@@ -247,6 +247,7 @@ impl MappableCommand {
247247 extend_line, "Select current line, if already selected, extend to next line" ,
248248 extend_line_above, "Select current line, if already selected, extend to previous line" ,
249249 extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)" ,
250+ shrink_to_line_bounds, "Shrink selection to line bounds (line-wise selection)" ,
250251 delete_selection, "Delete selection" ,
251252 delete_selection_noyank, "Delete selection, without yanking" ,
252253 change_selection, "Change selection (delete and enter insert mode)" ,
@@ -360,6 +361,11 @@ impl MappableCommand {
360361 jump_view_left, "Jump to the split to the left" ,
361362 jump_view_up, "Jump to the split above" ,
362363 jump_view_down, "Jump to the split below" ,
364+ swap_view_right, "Swap with the split to the right" ,
365+ swap_view_left, "Swap with the split to the left" ,
366+ swap_view_up, "Swap with the split above" ,
367+ swap_view_down, "Swap with the split below" ,
368+ transpose_view, "Transpose splits" ,
363369 rotate_view, "Goto next window" ,
364370 hsplit, "Horizontal bottom split" ,
365371 hsplit_new, "Horizontal bottom split scratch buffer" ,
@@ -1224,11 +1230,11 @@ fn replace(cx: &mut Context) {
12241230 // need to wait for next key
12251231 cx. on_next_key ( move |cx, event| {
12261232 let ( view, doc) = current ! ( cx. editor) ;
1227- let ch = match event {
1233+ let ch: Option < & str > = match event {
12281234 KeyEvent {
12291235 code : KeyCode :: Char ( ch) ,
12301236 ..
1231- } => Some ( & ch. encode_utf8 ( & mut buf[ ..] ) [ .. ] ) ,
1237+ } => Some ( ch. encode_utf8 ( & mut buf[ ..] ) ) ,
12321238 KeyEvent {
12331239 code : KeyCode :: Enter ,
12341240 ..
@@ -1937,6 +1943,47 @@ fn extend_to_line_bounds(cx: &mut Context) {
19371943 ) ;
19381944}
19391945
1946+ fn shrink_to_line_bounds ( cx : & mut Context ) {
1947+ let ( view, doc) = current ! ( cx. editor) ;
1948+
1949+ doc. set_selection (
1950+ view. id ,
1951+ doc. selection ( view. id ) . clone ( ) . transform ( |range| {
1952+ let text = doc. text ( ) ;
1953+
1954+ let ( start_line, end_line) = range. line_range ( text. slice ( ..) ) ;
1955+
1956+ // Do nothing if the selection is within one line to prevent
1957+ // conditional logic for the behavior of this command
1958+ if start_line == end_line {
1959+ return range;
1960+ }
1961+
1962+ let mut start = text. line_to_char ( start_line) ;
1963+
1964+ // line_to_char gives us the start position of the line, so
1965+ // we need to get the start position of the next line. In
1966+ // the editor, this will correspond to the cursor being on
1967+ // the EOL whitespace charactor, which is what we want.
1968+ let mut end = text. line_to_char ( ( end_line + 1 ) . min ( text. len_lines ( ) ) ) ;
1969+
1970+ if start != range. from ( ) {
1971+ start = text. line_to_char ( ( start_line + 1 ) . min ( text. len_lines ( ) ) ) ;
1972+ }
1973+
1974+ if end != range. to ( ) {
1975+ end = text. line_to_char ( end_line) ;
1976+ }
1977+
1978+ if range. anchor <= range. head {
1979+ Range :: new ( start, end)
1980+ } else {
1981+ Range :: new ( end, start)
1982+ }
1983+ } ) ,
1984+ ) ;
1985+ }
1986+
19401987enum Operation {
19411988 Delete ,
19421989 Change ,
@@ -3860,6 +3907,26 @@ fn jump_view_down(cx: &mut Context) {
38603907 cx. editor . focus_down ( )
38613908}
38623909
3910+ fn swap_view_right ( cx : & mut Context ) {
3911+ cx. editor . swap_right ( )
3912+ }
3913+
3914+ fn swap_view_left ( cx : & mut Context ) {
3915+ cx. editor . swap_left ( )
3916+ }
3917+
3918+ fn swap_view_up ( cx : & mut Context ) {
3919+ cx. editor . swap_up ( )
3920+ }
3921+
3922+ fn swap_view_down ( cx : & mut Context ) {
3923+ cx. editor . swap_down ( )
3924+ }
3925+
3926+ fn transpose_view ( cx : & mut Context ) {
3927+ cx. editor . transpose_view ( )
3928+ }
3929+
38633930// split helper, clear it later
38643931fn split ( cx : & mut Context , action : Action ) {
38653932 let ( view, doc) = current ! ( cx. editor) ;
0 commit comments