Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement view transpose #2461

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ impl MappableCommand {
jump_view_left, "Jump to the split to the left",
jump_view_up, "Jump to the split above",
jump_view_down, "Jump to the split below",
transpose_view, "Transpose splits",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great feature! Thank you for adding it

I must say when I read the words "transpose view" I assumed it would swap the contents of two windows, not swap from a horizontal split to a vertical split. However, reading the description "transpose splits" made it immediately clear.

rotate_view, "Goto next window",
hsplit, "Horizontal bottom split",
hsplit_new, "Horizontal bottom split scratch buffer",
Expand Down Expand Up @@ -3863,6 +3864,10 @@ fn jump_view_down(cx: &mut Context) {
cx.editor.focus_down()
}

fn transpose_view(cx: &mut Context) {
cx.editor.transpose_view()
}

// split helper, clear it later
fn split(cx: &mut Context, action: Action) {
let (view, doc) = current!(cx.editor);
Expand Down
2 changes: 2 additions & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-w" | "w" => rotate_view,
"C-s" | "s" => hsplit,
"C-v" | "v" => vsplit,
"C-t" | "t" => transpose_view,
"f" => goto_file_hsplit,
"F" => goto_file_vsplit,
"C-q" | "q" => wclose,
Expand Down Expand Up @@ -226,6 +227,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-w" | "w" => rotate_view,
"C-s" | "s" => hsplit,
"C-v" | "v" => vsplit,
"C-t" | "t" => transpose_view,
"f" => goto_file_hsplit,
"F" => goto_file_vsplit,
"C-q" | "q" => wclose,
Expand Down
4 changes: 4 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ impl Editor {
self.tree.focus_direction(tree::Direction::Down);
}

pub fn transpose_view(&mut self) {
self.tree.transpose();
}

pub fn should_close(&self) -> bool {
self.tree.is_empty()
}
Expand Down
12 changes: 12 additions & 0 deletions helix-view/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
self.area
}
Expand Down