mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-18 21:17:08 +04:00
Add home-end keymaps, (as kakoune/vim do) (#83)
* add home-end keymaps * implement extend methods for extend_line_start, extend_line_end * add home-end mappings to keymaps.md * add ^-$ extend mappings for extend mode * pass cargo linter
This commit is contained in:
parent
72eaaaac99
commit
a1f4b8f92b
@ -17,6 +17,8 @@ ### Movement
|
||||
| f | find next char |
|
||||
| T | find 'till previous char |
|
||||
| F | find previous char |
|
||||
| Home | move to the start of the line |
|
||||
| End | move to the end of the line |
|
||||
| m | Jump to matching bracket |
|
||||
| PageUp | Move page up |
|
||||
| PageDown | Move page down |
|
||||
|
@ -573,6 +573,37 @@ pub fn extend_line_down(cx: &mut Context) {
|
||||
doc.set_selection(view.id, selection);
|
||||
}
|
||||
|
||||
pub fn extend_line_end(cx: &mut Context) {
|
||||
let (view, doc) = cx.current();
|
||||
|
||||
let selection = doc.selection(view.id).transform(|range| {
|
||||
let text = doc.text();
|
||||
let line = text.char_to_line(range.head);
|
||||
|
||||
// Line end is pos at the start of next line - 1
|
||||
// subtract another 1 because the line ends with \n
|
||||
let pos = text.line_to_char(line + 1).saturating_sub(2);
|
||||
Range::new(range.anchor, pos)
|
||||
});
|
||||
|
||||
doc.set_selection(view.id, selection);
|
||||
}
|
||||
|
||||
pub fn extend_line_start(cx: &mut Context) {
|
||||
let (view, doc) = cx.current();
|
||||
|
||||
let selection = doc.selection(view.id).transform(|range| {
|
||||
let text = doc.text();
|
||||
let line = text.char_to_line(range.head);
|
||||
|
||||
// adjust to start of the line
|
||||
let pos = text.line_to_char(line);
|
||||
Range::new(range.anchor, pos)
|
||||
});
|
||||
|
||||
doc.set_selection(view.id, selection);
|
||||
}
|
||||
|
||||
pub fn select_all(cx: &mut Context) {
|
||||
let (view, doc) = cx.current();
|
||||
|
||||
|
@ -61,8 +61,8 @@
|
||||
// in kakoune these are alt-h alt-l / gh gl
|
||||
// select from curs to begin end / move curs to begin end
|
||||
// 0 = start of line
|
||||
// ^ = start of line (first non blank char)
|
||||
// $ = end of line
|
||||
// ^ = start of line(first non blank char) || Home = start of line(first non blank char)
|
||||
// $ = end of line || End = end of line
|
||||
//
|
||||
// z = save selections
|
||||
// Z = restore selections
|
||||
@ -153,6 +153,16 @@ pub fn default() -> Keymaps {
|
||||
//
|
||||
key!('r') => commands::replace,
|
||||
|
||||
KeyEvent {
|
||||
code: KeyCode::Home,
|
||||
modifiers: KeyModifiers::NONE
|
||||
} => commands::move_line_start,
|
||||
|
||||
KeyEvent {
|
||||
code: KeyCode::End,
|
||||
modifiers: KeyModifiers::NONE
|
||||
} => commands::move_line_end,
|
||||
|
||||
key!('w') => commands::move_next_word_start,
|
||||
key!('b') => commands::move_prev_word_start,
|
||||
key!('e') => commands::move_next_word_end,
|
||||
@ -306,13 +316,21 @@ pub fn default() -> Keymaps {
|
||||
|
||||
key!('t') => commands::extend_till_char,
|
||||
key!('f') => commands::extend_next_char,
|
||||
|
||||
key!('T') => commands::extend_till_prev_char,
|
||||
key!('F') => commands::extend_prev_char,
|
||||
|
||||
KeyEvent {
|
||||
code: KeyCode::Home,
|
||||
modifiers: KeyModifiers::NONE
|
||||
} => commands::extend_line_start,
|
||||
KeyEvent {
|
||||
code: KeyCode::End,
|
||||
modifiers: KeyModifiers::NONE
|
||||
} => commands::extend_line_end,
|
||||
KeyEvent {
|
||||
code: KeyCode::Esc,
|
||||
modifiers: KeyModifiers::NONE
|
||||
} => commands::exit_select_mode as Command,
|
||||
} => commands::exit_select_mode,
|
||||
)
|
||||
.into_iter(),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user