on master help sign in
Implement view transpose (#2461)
8958bf0Roland Kovacs
helix-term/src/commands.rs+5
@@ -360,6 +360,7 @@ impl MappableCommand {
360 jump_view_left, "Jump to the split to the left",
360 jump_view_left, "Jump to the split to the left",
361 jump_view_up, "Jump to the split above",
361 jump_view_up, "Jump to the split above",
362 jump_view_down, "Jump to the split below",
362 jump_view_down, "Jump to the split below",
363+ transpose_view, "Transpose splits",
363 rotate_view, "Goto next window",
364 rotate_view, "Goto next window",
364 hsplit, "Horizontal bottom split",
365 hsplit, "Horizontal bottom split",
365 hsplit_new, "Horizontal bottom split scratch buffer",
366 hsplit_new, "Horizontal bottom split scratch buffer",
@@ -3863,6 +3864,10 @@ fn jump_view_down(cx: &mut Context) {
3863 cx.editor.focus_down()
3864 cx.editor.focus_down()
3864}
3865}
3865
3866
3867+fn transpose_view(cx: &mut Context) {
3868+ cx.editor.transpose_view()
3869+}
3870+
3866// split helper, clear it later
3871// split helper, clear it later
3867fn split(cx: &mut Context, action: Action) {
3872fn split(cx: &mut Context, action: Action) {
3868 let (view, doc) = current!(cx.editor);
3873 let (view, doc) = current!(cx.editor);
helix-term/src/keymap/default.rs+2
@@ -171,6 +171,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
171 "C-w" | "w" => rotate_view,
171 "C-w" | "w" => rotate_view,
172 "C-s" | "s" => hsplit,
172 "C-s" | "s" => hsplit,
173 "C-v" | "v" => vsplit,
173 "C-v" | "v" => vsplit,
174+ "C-t" | "t" => transpose_view,
174 "f" => goto_file_hsplit,
175 "f" => goto_file_hsplit,
175 "F" => goto_file_vsplit,
176 "F" => goto_file_vsplit,
176 "C-q" | "q" => wclose,
177 "C-q" | "q" => wclose,
@@ -226,6 +227,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
226 "C-w" | "w" => rotate_view,
227 "C-w" | "w" => rotate_view,
227 "C-s" | "s" => hsplit,
228 "C-s" | "s" => hsplit,
228 "C-v" | "v" => vsplit,
229 "C-v" | "v" => vsplit,
230+ "C-t" | "t" => transpose_view,
229 "f" => goto_file_hsplit,
231 "f" => goto_file_hsplit,
230 "F" => goto_file_vsplit,
232 "F" => goto_file_vsplit,
231 "C-q" | "q" => wclose,
233 "C-q" | "q" => wclose,
helix-view/src/editor.rs+4
@@ -885,6 +885,10 @@ impl Editor {
885 self.tree.focus_direction(tree::Direction::Down);
885 self.tree.focus_direction(tree::Direction::Down);
886 }
886 }
887
887
888+ pub fn transpose_view(&mut self) {
889+ self.tree.transpose();
890+ }
891+
888 pub fn should_close(&self) -> bool {
892 pub fn should_close(&self) -> bool {
889 self.tree.is_empty()
893 self.tree.is_empty()
890 }
894 }
helix-view/src/tree.rs+12
@@ -526,6 +526,18 @@ impl Tree {
526 }
526 }
527 }
527 }
528
528
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+
529 pub fn area(&self) -> Rect {
541 pub fn area(&self) -> Rect {
530 self.area
542 self.area
531 }
543 }