on master help sign in
add_newline unimpaired mapping (#653)

* added some keymaps * remove * remove wrong mappings * remove * wrong import * use enum * correct line ending * added to book * column

commit825bceeab68276cdf120bda5d172b854867d8585 authoroberblastmeister <61095988+oberblastmeister@users.noreply.github.com> dateWed 1 Sep 2021, 11:55 (5 years ago) parentae3f936
3 files changed+50−11
book/src/keymap.md+12−11 helix-term/src/commands.rs+36 helix-term/src/keymap.rs+2
book/src/keymap.md+12−11
@@ -110,17 +110,18 @@ in reverse, or searching via smartcase.
110110| `N` | Add next search match to selection | `extend_search_next` |
111111| `*` | Use current selection as the search pattern | `search_selection` |
112112
113−### Diagnostics
114−
115−> NOTE: `[` and `]` will likely contain more pair mappings in the style of
116−> [vim-unimpaired](https://github.com/tpope/vim-unimpaired)
117−
118−| Key | Description | Command |
119−| ----- | ----------- | ------- |
120−| `[d` | Go to previous diagnostic | `goto_prev_diag` |
121−| `]d` | Go to next diagnostic | `goto_next_diag` |
122−| `[D` | Go to first diagnostic in document | `goto_first_diag` |
123−| `]D` | Go to last diagnostic in document | `goto_last_diag` |
113+### Unimpaired
114+
115+Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaired)
116+
117+| Key | Description | Command |
118+| ----- | ----------- | ------- |
119+| `[d` | Go to previous diagnostic | `goto_prev_diag` |
120+| `]d` | Go to next diagnostic | `goto_next_diag` |
121+| `[D` | Go to first diagnostic in document | `goto_first_diag` |
122+| `]D` | Go to last diagnostic in document | `goto_last_diag` |
123+| `[space` | Add newline above | `add_newline_above` |
124+| `]space` | Add newline below | `add_newline_below` |
124125
125126### Shell
126127
helix-term/src/commands.rs+36
@@ -227,6 +227,8 @@ impl Command {
227227 select_mode, "Enter selection extend mode",
228228 exit_select_mode, "Exit selection mode",
229229 goto_definition, "Goto definition",
230+ add_newline_above, "Add newline above",
231+ add_newline_below, "Add newline below",
230232 goto_type_definition, "Goto type definition",
231233 goto_implementation, "Goto implementation",
232234 goto_file_start, "Goto file start/line",
@@ -4473,3 +4475,37 @@ fn suspend(_cx: &mut Context) {
44734475 #[cfg(not(windows))]
44744476 signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap();
44754477}
4478+
4479+fn add_newline_above(cx: &mut Context) {
4480+ add_newline_impl(cx, Open::Above);
4481+}
4482+
4483+fn add_newline_below(cx: &mut Context) {
4484+ add_newline_impl(cx, Open::Below)
4485+}
4486+
4487+fn add_newline_impl(cx: &mut Context, open: Open) {
4488+ let count = cx.count();
4489+ let (view, doc) = current!(cx.editor);
4490+ let selection = doc.selection(view.id);
4491+ let text = doc.text();
4492+ let slice = text.slice(..);
4493+
4494+ let changes = selection.into_iter().map(|range| {
4495+ let (start, end) = range.line_range(slice);
4496+ let line = match open {
4497+ Open::Above => start,
4498+ Open::Below => end + 1,
4499+ };
4500+ let pos = text.line_to_char(line);
4501+ (
4502+ pos,
4503+ pos,
4504+ Some(doc.line_ending.as_str().repeat(count).into()),
4505+ )
4506+ });
4507+
4508+ let transaction = Transaction::change(text, changes);
4509+ doc.apply(&transaction, view.id);
4510+ doc.append_changes_to_history(view.id);
4511+}
helix-term/src/keymap.rs+2
@@ -412,10 +412,12 @@ impl Default for Keymaps {
412412 "[" => { "Left bracket"
413413 "d" => goto_prev_diag,
414414 "D" => goto_first_diag,
415+ "space" => add_newline_above,
415416 },
416417 "]" => { "Right bracket"
417418 "d" => goto_next_diag,
418419 "D" => goto_last_diag,
420+ "space" => add_newline_below,
419421 },
420422
421423 "/" => search,