Skip to content

Commit 8af33a4

Browse files
lizclipseiniw
authored andcommitted
Added zoom mode & max width
1 parent c2e23d9 commit 8af33a4

File tree

11 files changed

+77
-10
lines changed

11 files changed

+77
-10
lines changed

book/src/editor.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ The `[editor.statusline]` key takes the following sub-keys:
116116

117117
| Key | Description | Default |
118118
| --- | --- | --- |
119-
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` |
119+
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "zoom", "file-modification-indicator"]` |
120120
| `center` | A list of elements aligned to the middle of the statusline | `[]` |
121121
| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` |
122122
| `separator` | The character used to separate elements in the statusline | `"│"` |
@@ -153,6 +153,7 @@ The following statusline elements can be configured:
153153
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |
154154
| `version-control` | The current branch name or detached commit hash of the opened workspace |
155155
| `register` | The current selected register |
156+
| `zoom` | The current window zoom/zen state |
156157

157158
### `[editor.lsp]` Section
158159

book/src/generated/static-cmd.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
| `vsplit_new` | Vertical right split scratch buffer | normal: `` <C-w>nv ``, `` <space>wnv ``, `` <C-w>n<C-v> ``, `` <space>wn<C-v> ``, select: `` <C-w>nv ``, `` <space>wnv ``, `` <C-w>n<C-v> ``, `` <space>wn<C-v> `` |
251251
| `wclose` | Close window | normal: `` <C-w>q ``, `` <space>wq ``, `` <C-w><C-q> ``, `` <space>w<C-q> ``, select: `` <C-w>q ``, `` <space>wq ``, `` <C-w><C-q> ``, `` <space>w<C-q> `` |
252252
| `wonly` | Close windows except current | normal: `` <C-w>o ``, `` <space>wo ``, `` <C-w><C-o> ``, `` <space>w<C-o> ``, select: `` <C-w>o ``, `` <space>wo ``, `` <C-w><C-o> ``, `` <space>w<C-o> `` |
253+
| `toggle_zoom` | Toggle zoom for current window | normal: `` <C-w>z ``, `` <space>wz ``, select: `` <C-w>z ``, `` <space>wz `` |
253254
| `select_register` | Select register | normal: `` " ``, select: `` " `` |
254255
| `insert_register` | Insert register | insert: `` <C-r> `` |
255256
| `copy_between_registers` | Copy between two registers | |

book/src/generated/typable-cmd.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@
9292
| `:read`, `:r` | Load a file into buffer |
9393
| `:echo` | Prints the given arguments to the statusline. |
9494
| `:noop` | Does nothing. |
95+
| `:set-max-width` | Set the maximum width of the editor, or swap between 2 widths. If set to 0 it will take up the entire width. |

book/src/keymap.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ This layer is similar to Vim keybindings as Kakoune does not support windows.
279279
| `J` | Swap window downwards | `swap_view_down` |
280280
| `K` | Swap window upwards | `swap_view_up` |
281281
| `L` | Swap window to the right | `swap_view_right` |
282+
| `z` | Toggle zoom for the focused view | `toggle_zoom` |
282283

283284
#### Space mode
284285

book/src/remapping.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ k = "scroll_down"
6868
m = ":run-shell-command make"
6969
c = ":run-shell-command cargo build"
7070
t = ":run-shell-command cargo test"
71+
72+
# Creates a basic 'zen-mode' similar to VSCode's
73+
z = ["toggle_zoom", ":set-max-width 120 0", ":set gutters.layout []"]
7174
```
7275

7376
## Special keys and modifiers

helix-term/src/commands.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ impl MappableCommand {
554554
vsplit_new, "Vertical right split scratch buffer",
555555
wclose, "Close window",
556556
wonly, "Close windows except current",
557+
toggle_zoom, "Toggle zoom for current window",
557558
select_register, "Select register",
558559
insert_register, "Insert register",
559560
copy_between_registers, "Copy between two registers",
@@ -5792,6 +5793,11 @@ fn wonly(cx: &mut Context) {
57925793
}
57935794
}
57945795

5796+
fn toggle_zoom(cx: &mut Context) {
5797+
cx.editor.tree.zoom = !cx.editor.tree.zoom;
5798+
cx.editor.tree.recalculate();
5799+
}
5800+
57955801
fn select_register(cx: &mut Context) {
57965802
cx.editor.autoinfo = Some(Info::from_registers(
57975803
"Select register",

helix-term/src/keymap/default.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
215215
"C-s" | "s" => hsplit_new,
216216
"C-v" | "v" => vsplit_new,
217217
},
218+
"z" => toggle_zoom,
218219
},
219220

220221
// move under <space>c
@@ -282,6 +283,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
282283
"C-s" | "s" => hsplit_new,
283284
"C-v" | "v" => vsplit_new,
284285
},
286+
"z" => toggle_zoom,
285287
},
286288
"y" => yank_to_clipboard,
287289
"Y" => yank_main_selection_to_clipboard,

helix-term/src/ui/editor.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ impl EditorView {
208208
decorations,
209209
);
210210

211-
// if we're not at the edge of the screen, draw a right border
212-
if viewport.right() != view.area.right() {
211+
// if we're not at the edge of the screen or zoomed, draw a right border
212+
if viewport.right() != view.area.right() && !editor.tree.zoom {
213213
let x = area.right();
214214
let border_style = theme.get("ui.window");
215215
for y in area.top()..area.bottom() {
@@ -1145,8 +1145,13 @@ impl EditorView {
11451145
..
11461146
} = *event;
11471147

1148+
// In zoom, only the focused view is interactable.
1149+
let zoom = cxt.editor.tree.zoom;
11481150
let pos_and_view = |editor: &Editor, row, column, ignore_virtual_text| {
1149-
editor.tree.views().find_map(|(view, _focus)| {
1151+
editor.tree.views().find_map(|(view, focus)| {
1152+
if zoom && !focus {
1153+
return None;
1154+
}
11501155
view.pos_at_screen_coords(
11511156
&editor.documents[&view.doc],
11521157
row,
@@ -1158,7 +1163,10 @@ impl EditorView {
11581163
};
11591164

11601165
let gutter_coords_and_view = |editor: &Editor, row, column| {
1161-
editor.tree.views().find_map(|(view, _focus)| {
1166+
editor.tree.views().find_map(|(view, focus)| {
1167+
if zoom && !focus {
1168+
return None;
1169+
}
11621170
view.gutter_coords_at_screen_coords(row, column)
11631171
.map(|coords| (coords, view.id))
11641172
})
@@ -1560,8 +1568,12 @@ impl Component for EditorView {
15601568
}
15611569

15621570
for (view, is_focused) in cx.editor.tree.views() {
1563-
let doc = cx.editor.document(view.doc).unwrap();
1564-
self.render_view(cx.editor, doc, view, area, surface, is_focused);
1571+
// If in zoom, only the focused document is rendered, with the unfocused ones being
1572+
// positioned off-screen.
1573+
if !cx.editor.tree.zoom || is_focused {
1574+
let doc = cx.editor.document(view.doc).unwrap();
1575+
self.render_view(cx.editor, doc, view, area, surface, is_focused);
1576+
}
15651577
}
15661578

15671579
if config.auto_info {

helix-term/src/ui/statusline.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ where
157157
helix_view::editor::StatusLineElement::VersionControl => render_version_control,
158158
helix_view::editor::StatusLineElement::Register => render_register,
159159
helix_view::editor::StatusLineElement::CurrentWorkingDirectory => render_cwd,
160+
helix_view::editor::StatusLineElement::Zoom => render_zoom,
160161
}
161162
}
162163

@@ -602,3 +603,12 @@ where
602603
.to_string();
603604
write(context, cwd.into())
604605
}
606+
607+
fn render_zoom<'a, F>(context: &mut RenderContext<'a>, write: F)
608+
where
609+
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
610+
{
611+
if context.editor.tree.zoom {
612+
write(context, "[zoom]".into())
613+
}
614+
}

helix-view/src/editor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ impl Default for StatusLineConfig {
587587
],
588588
center: vec![],
589589
right: vec![
590+
E::Zoom,
590591
E::Diagnostics,
591592
E::Selections,
592593
E::Register,
@@ -690,6 +691,9 @@ pub enum StatusLineElement {
690691

691692
/// The base of current working directory
692693
CurrentWorkingDirectory,
694+
695+
/// Current zoom/zen state
696+
Zoom,
693697
}
694698

695699
// Cursor shape is read and used on every rendered frame and so needs

0 commit comments

Comments
 (0)