on master help sign in
Editor: remove duplication for view focus/swap commands
7b8e4acBlaž Hrastnik
helix-term/src/commands.rs+9−8
@@ -33,6 +33,7 @@ use helix_view::{
33 info::Info,
33 info::Info,
34 input::KeyEvent,
34 input::KeyEvent,
35 keyboard::KeyCode,
35 keyboard::KeyCode,
36+ tree,
36 view::View,
37 view::View,
37 Document, DocumentId, Editor, ViewId,
38 Document, DocumentId, Editor, ViewId,
38};
39};
@@ -4080,35 +4081,35 @@ fn rotate_view(cx: &mut Context) {
4080}
4081}
4081
4082
4082fn jump_view_right(cx: &mut Context) {
4083fn jump_view_right(cx: &mut Context) {
4083− cx.editor.focus_right()
4084+ cx.editor.focus_direction(tree::Direction::Right)
4084}
4085}
4085
4086
4086fn jump_view_left(cx: &mut Context) {
4087fn jump_view_left(cx: &mut Context) {
4087− cx.editor.focus_left()
4088+ cx.editor.focus_direction(tree::Direction::Left)
4088}
4089}
4089
4090
4090fn jump_view_up(cx: &mut Context) {
4091fn jump_view_up(cx: &mut Context) {
4091− cx.editor.focus_up()
4092+ cx.editor.focus_direction(tree::Direction::Up)
4092}
4093}
4093
4094
4094fn jump_view_down(cx: &mut Context) {
4095fn jump_view_down(cx: &mut Context) {
4095− cx.editor.focus_down()
4096+ cx.editor.focus_direction(tree::Direction::Down)
4096}
4097}
4097
4098
4098fn swap_view_right(cx: &mut Context) {
4099fn swap_view_right(cx: &mut Context) {
4099− cx.editor.swap_right()
4100+ cx.editor.swap_split_in_direction(tree::Direction::Right)
4100}
4101}
4101
4102
4102fn swap_view_left(cx: &mut Context) {
4103fn swap_view_left(cx: &mut Context) {
4103− cx.editor.swap_left()
4104+ cx.editor.swap_split_in_direction(tree::Direction::Left)
4104}
4105}
4105
4106
4106fn swap_view_up(cx: &mut Context) {
4107fn swap_view_up(cx: &mut Context) {
4107− cx.editor.swap_up()
4108+ cx.editor.swap_split_in_direction(tree::Direction::Up)
4108}
4109}
4109
4110
4110fn swap_view_down(cx: &mut Context) {
4111fn swap_view_down(cx: &mut Context) {
4111− cx.editor.swap_down()
4112+ cx.editor.swap_split_in_direction(tree::Direction::Down)
4112}
4113}
4113
4114
4114fn transpose_view(cx: &mut Context) {
4115fn transpose_view(cx: &mut Context) {
helix-view/src/editor.rs+4−28
@@ -1095,36 +1095,12 @@ impl Editor {
1095 self.tree.focus_next();
1095 self.tree.focus_next();
1096 }
1096 }
1097
1097
1098− pub fn focus_right(&mut self) {
1098+ pub fn focus_direction(&mut self, direction: tree::Direction) {
1099− self.tree.focus_direction(tree::Direction::Right);
1099+ self.tree.focus_direction(direction);
1100 }
1100 }
1101
1101
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);
1102+ pub fn swap_split_in_direction(&mut self, direction: tree::Direction) {
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);
1103+ self.tree.swap_split_in_direction(direction);
1128 }
1104 }
1129
1105
1130 pub fn transpose_view(&mut self) {
1106 pub fn transpose_view(&mut self) {