on master help sign in
Implement view transpose (#2461)

Change the layout of existing split view from horizontal to vertical and vica-versa. It only effects the focused view and its siblings, i.e. not recursive. Command is mapped to 't' or 'C-t' under the Window menus.

commit8958bf0a926a6e6afc63f0c59f3fa6761f5da709 authorRoland Kovacs <zen3ger@tutanota.com> dateFri 20 May 2022, 03:25 (4 years ago) parent62fd1f6
4 files changed+23
helix-term/src/commands.rs+5 helix-term/src/keymap/default.rs+2 helix-view/src/editor.rs+4 helix-view/src/tree.rs+12
helix-term/src/commands.rs+5
@@ -360,6 +360,7 @@ impl MappableCommand {
360360 jump_view_left, "Jump to the split to the left",
361361 jump_view_up, "Jump to the split above",
362362 jump_view_down, "Jump to the split below",
363+ transpose_view, "Transpose splits",
363364 rotate_view, "Goto next window",
364365 hsplit, "Horizontal bottom split",
365366 hsplit_new, "Horizontal bottom split scratch buffer",
@@ -3863,6 +3864,10 @@ fn jump_view_down(cx: &mut Context) {
38633864 cx.editor.focus_down()
38643865}
38653866
3867+fn transpose_view(cx: &mut Context) {
3868+ cx.editor.transpose_view()
3869+}
3870+
38663871// split helper, clear it later
38673872fn split(cx: &mut Context, action: Action) {
38683873 let (view, doc) = current!(cx.editor);
helix-term/src/keymap/default.rs+2
@@ -171,6 +171,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
171171 "C-w" | "w" => rotate_view,
172172 "C-s" | "s" => hsplit,
173173 "C-v" | "v" => vsplit,
174+ "C-t" | "t" => transpose_view,
174175 "f" => goto_file_hsplit,
175176 "F" => goto_file_vsplit,
176177 "C-q" | "q" => wclose,
@@ -226,6 +227,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
226227 "C-w" | "w" => rotate_view,
227228 "C-s" | "s" => hsplit,
228229 "C-v" | "v" => vsplit,
230+ "C-t" | "t" => transpose_view,
229231 "f" => goto_file_hsplit,
230232 "F" => goto_file_vsplit,
231233 "C-q" | "q" => wclose,
helix-view/src/editor.rs+4
@@ -885,6 +885,10 @@ impl Editor {
885885 self.tree.focus_direction(tree::Direction::Down);
886886 }
887887
888+ pub fn transpose_view(&mut self) {
889+ self.tree.transpose();
890+ }
891+
888892 pub fn should_close(&self) -> bool {
889893 self.tree.is_empty()
890894 }
helix-view/src/tree.rs+12
@@ -526,6 +526,18 @@ impl Tree {
526526 }
527527 }
528528
529+ pub fn transpose(&mut self) {
530+ let focus = self.focus;
531+ let parent = self.nodes[focus].parent;
532+ if let Content::Container(container) = &mut self.nodes[parent].content {
533+ container.layout = match container.layout {
534+ Layout::Vertical => Layout::Horizontal,
535+ Layout::Horizontal => Layout::Vertical,
536+ };
537+ self.recalculate();
538+ }
539+ }
540+
529541 pub fn area(&self) -> Rect {
530542 self.area
531543 }