on master help sign in
Editor: remove duplication for view focus/swap commands
commit7b8e4ac95a83513b315af29591ae957ae861605c authorBlaž Hrastnik <blaz@mxxn.io> dateTue 23 Aug 2022, 11:44 (4 years ago) parentdd2b9e5
2 files changed+13−36
helix-term/src/commands.rs+9−8 helix-view/src/editor.rs+4−28
helix-term/src/commands.rs+9−8
@@ -33,6 +33,7 @@ use helix_view::{
3333 info::Info,
3434 input::KeyEvent,
3535 keyboard::KeyCode,
36+ tree,
3637 view::View,
3738 Document, DocumentId, Editor, ViewId,
3839};
@@ -4080,35 +4081,35 @@ fn rotate_view(cx: &mut Context) {
40804081}
40814082
40824083fn jump_view_right(cx: &mut Context) {
4083− cx.editor.focus_right()
4084+ cx.editor.focus_direction(tree::Direction::Right)
40844085}
40854086
40864087fn jump_view_left(cx: &mut Context) {
4087− cx.editor.focus_left()
4088+ cx.editor.focus_direction(tree::Direction::Left)
40884089}
40894090
40904091fn jump_view_up(cx: &mut Context) {
4091− cx.editor.focus_up()
4092+ cx.editor.focus_direction(tree::Direction::Up)
40924093}
40934094
40944095fn jump_view_down(cx: &mut Context) {
4095− cx.editor.focus_down()
4096+ cx.editor.focus_direction(tree::Direction::Down)
40964097}
40974098
40984099fn swap_view_right(cx: &mut Context) {
4099− cx.editor.swap_right()
4100+ cx.editor.swap_split_in_direction(tree::Direction::Right)
41004101}
41014102
41024103fn swap_view_left(cx: &mut Context) {
4103− cx.editor.swap_left()
4104+ cx.editor.swap_split_in_direction(tree::Direction::Left)
41044105}
41054106
41064107fn swap_view_up(cx: &mut Context) {
4107− cx.editor.swap_up()
4108+ cx.editor.swap_split_in_direction(tree::Direction::Up)
41084109}
41094110
41104111fn swap_view_down(cx: &mut Context) {
4111− cx.editor.swap_down()
4112+ cx.editor.swap_split_in_direction(tree::Direction::Down)
41124113}
41134114
41144115fn transpose_view(cx: &mut Context) {
helix-view/src/editor.rs+4−28
@@ -1095,36 +1095,12 @@ impl Editor {
10951095 self.tree.focus_next();
10961096 }
10971097
1098− pub fn focus_right(&mut self) {
1099− self.tree.focus_direction(tree::Direction::Right);
1098+ pub fn focus_direction(&mut self, direction: tree::Direction) {
1099+ self.tree.focus_direction(direction);
11001100 }
11011101
1102− pub fn focus_left(&mut self) {
1103− self.tree.focus_direction(tree::Direction::Left);
1104− }
1105−
1106− pub fn focus_up(&mut self) {
1107− self.tree.focus_direction(tree::Direction::Up);
1108− }
1109−
1110− pub fn focus_down(&mut self) {
1111− self.tree.focus_direction(tree::Direction::Down);
1112− }
1113−
1114− pub fn swap_right(&mut self) {
1115− self.tree.swap_split_in_direction(tree::Direction::Right);
1116− }
1117−
1118− pub fn swap_left(&mut self) {
1119− self.tree.swap_split_in_direction(tree::Direction::Left);
1120− }
1121−
1122− pub fn swap_up(&mut self) {
1123− self.tree.swap_split_in_direction(tree::Direction::Up);
1124− }
1125−
1126− pub fn swap_down(&mut self) {
1127− self.tree.swap_split_in_direction(tree::Direction::Down);
1102+ pub fn swap_split_in_direction(&mut self, direction: tree::Direction) {
1103+ self.tree.swap_split_in_direction(direction);
11281104 }
11291105
11301106 pub fn transpose_view(&mut self) {