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.
pull/2445/head
Roland Kovacs 3 years ago committed by GitHub
parent 62fd1f6999
commit 8958bf0a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -360,6 +360,7 @@ impl MappableCommand {
jump_view_left, "Jump to the split to the left", jump_view_left, "Jump to the split to the left",
jump_view_up, "Jump to the split above", jump_view_up, "Jump to the split above",
jump_view_down, "Jump to the split below", jump_view_down, "Jump to the split below",
transpose_view, "Transpose splits",
rotate_view, "Goto next window", rotate_view, "Goto next window",
hsplit, "Horizontal bottom split", hsplit, "Horizontal bottom split",
hsplit_new, "Horizontal bottom split scratch buffer", hsplit_new, "Horizontal bottom split scratch buffer",
@ -3863,6 +3864,10 @@ fn jump_view_down(cx: &mut Context) {
cx.editor.focus_down() cx.editor.focus_down()
} }
fn transpose_view(cx: &mut Context) {
cx.editor.transpose_view()
}
// split helper, clear it later // split helper, clear it later
fn split(cx: &mut Context, action: Action) { fn split(cx: &mut Context, action: Action) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);

@ -171,6 +171,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-w" | "w" => rotate_view, "C-w" | "w" => rotate_view,
"C-s" | "s" => hsplit, "C-s" | "s" => hsplit,
"C-v" | "v" => vsplit, "C-v" | "v" => vsplit,
"C-t" | "t" => transpose_view,
"f" => goto_file_hsplit, "f" => goto_file_hsplit,
"F" => goto_file_vsplit, "F" => goto_file_vsplit,
"C-q" | "q" => wclose, "C-q" | "q" => wclose,
@ -226,6 +227,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-w" | "w" => rotate_view, "C-w" | "w" => rotate_view,
"C-s" | "s" => hsplit, "C-s" | "s" => hsplit,
"C-v" | "v" => vsplit, "C-v" | "v" => vsplit,
"C-t" | "t" => transpose_view,
"f" => goto_file_hsplit, "f" => goto_file_hsplit,
"F" => goto_file_vsplit, "F" => goto_file_vsplit,
"C-q" | "q" => wclose, "C-q" | "q" => wclose,

@ -885,6 +885,10 @@ impl Editor {
self.tree.focus_direction(tree::Direction::Down); self.tree.focus_direction(tree::Direction::Down);
} }
pub fn transpose_view(&mut self) {
self.tree.transpose();
}
pub fn should_close(&self) -> bool { pub fn should_close(&self) -> bool {
self.tree.is_empty() self.tree.is_empty()
} }

@ -526,6 +526,18 @@ impl Tree {
} }
} }
pub fn transpose(&mut self) {
let focus = self.focus;
let parent = self.nodes[focus].parent;
if let Content::Container(container) = &mut self.nodes[parent].content {
container.layout = match container.layout {
Layout::Vertical => Layout::Horizontal,
Layout::Horizontal => Layout::Vertical,
};
self.recalculate();
}
}
pub fn area(&self) -> Rect { pub fn area(&self) -> Rect {
self.area self.area
} }

Loading…
Cancel
Save