commands: Implement count for a few more commands.

pull/8/head
Blaž Hrastnik 4 years ago
parent 5fa1ba6b1c
commit 01907b3497

@ -12,16 +12,16 @@
- [x] % for whole doc selection - [x] % for whole doc selection
- [x] vertical splits - [x] vertical splits
- [x] input counts (30j) - [x] input counts (30j)
- [ ] input counts for b, w, e - [x] input counts for b, w, e
- [ ] respect view fullscreen flag - [ ] respect view fullscreen flag
- [x] retain horiz when moving vertically - [x] retain horiz when moving vertically
- [w] retain horiz when moving via ctrl-u/d
- [x] deindent - [x] deindent
- [ ] ensure_cursor_in_view always before rendering? or always in app after event process? - [ ] ensure_cursor_in_view always before rendering? or always in app after event process?
- [x] update lsp on redo/undo - [x] update lsp on redo/undo
- [ ] Implement marks (superset of Selection/Range) - [ ] Implement marks (superset of Selection/Range)
- [ ] ctrl-v/ctrl-x on file picker - [ ] ctrl-v/ctrl-x on file picker
- [ ] linewise selection work - [ ] linewise selection work
- [ ] goto definition
- [ ] nixos packaging - [ ] nixos packaging
- [ ] CI binary builds - [ ] CI binary builds
@ -33,6 +33,13 @@
- [ ] buffers should sit on editor.buffers, view simply refs them - [ ] buffers should sit on editor.buffers, view simply refs them
- [ ] lsp: signature help
- [ ] lsp: hover
- [ ] lsp: document symbols (nested/vec)
- [ ] lsp: code actions
- [ ] lsp: formatting
- [ ] lsp: goto
2 2
- [ ] tab completion for paths on the prompt - [ ] tab completion for paths on the prompt
- [ ] extend selection (treesitter select parent node) (replaces viw, vi(, va( etc ) - [ ] extend selection (treesitter select parent node) (replaces viw, vi(, va( etc )
@ -41,7 +48,7 @@
- [ ] completion signature popups/docs - [ ] completion signature popups/docs
- [ ] multiple views into the same file - [ ] multiple views into the same file
- [ ] selection align - [ ] selection align
- [ ] store some state: file positions, prompt history - [ ] store some state between restarts: file positions, prompt history
3 3
- [ ] diagnostics popups - [ ] diagnostics popups

@ -120,8 +120,9 @@ impl State {
} }
} }
pub fn move_next_word_start(slice: RopeSlice, mut pos: usize) -> usize { pub fn move_next_word_start(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
// TODO: confirm it's fine without using graphemes, I think it should be // TODO: confirm it's fine without using graphemes, I think it should be
for _ in 0..count {
let ch = slice.char(pos); let ch = slice.char(pos);
let next = slice.char(pos.saturating_add(1)); let next = slice.char(pos.saturating_add(1));
if categorize(ch) != categorize(next) { if categorize(ch) != categorize(next) {
@ -139,12 +140,14 @@ impl State {
// TODO: don't include newline? // TODO: don't include newline?
skip_over_next(slice, &mut pos, |ch| ch.is_ascii_whitespace()); skip_over_next(slice, &mut pos, |ch| ch.is_ascii_whitespace());
}
pos pos
} }
pub fn move_prev_word_start(slice: RopeSlice, mut pos: usize) -> usize { pub fn move_prev_word_start(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
// TODO: confirm it's fine without using graphemes, I think it should be // TODO: confirm it's fine without using graphemes, I think it should be
for _ in 0..count {
let ch = slice.char(pos); let ch = slice.char(pos);
let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start
@ -165,11 +168,14 @@ impl State {
} else if ch.is_ascii_punctuation() { } else if ch.is_ascii_punctuation() {
skip_over_prev(slice, &mut pos, |ch| ch.is_ascii_punctuation()); skip_over_prev(slice, &mut pos, |ch| ch.is_ascii_punctuation());
} }
pos = pos.saturating_add(1)
}
pos.saturating_add(1) pos
} }
pub fn move_next_word_end(slice: RopeSlice, mut pos: usize, _count: usize) -> usize { pub fn move_next_word_end(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
for _ in 0..count {
// TODO: confirm it's fine without using graphemes, I think it should be // TODO: confirm it's fine without using graphemes, I think it should be
let ch = slice.char(pos); let ch = slice.char(pos);
let next = slice.char(pos.saturating_add(1)); let next = slice.char(pos.saturating_add(1));
@ -188,8 +194,10 @@ impl State {
} else if ch.is_ascii_punctuation() { } else if ch.is_ascii_punctuation() {
skip_over_next(slice, &mut pos, |ch| ch.is_ascii_punctuation()); skip_over_next(slice, &mut pos, |ch| ch.is_ascii_punctuation());
} }
pos = pos.saturating_sub(1)
}
pos.saturating_sub(1) pos
} }
pub fn move_selection( pub fn move_selection(

@ -128,8 +128,7 @@ pub fn move_line_start(cx: &mut Context) {
pub fn move_next_word_start(cx: &mut Context) { pub fn move_next_word_start(cx: &mut Context) {
let count = cx.count; let count = cx.count;
let doc = cx.doc(); let doc = cx.doc();
// TODO: count let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count);
let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor());
doc.set_selection(Selection::point(pos)); doc.set_selection(Selection::point(pos));
} }
@ -137,7 +136,7 @@ pub fn move_next_word_start(cx: &mut Context) {
pub fn move_prev_word_start(cx: &mut Context) { pub fn move_prev_word_start(cx: &mut Context) {
let count = cx.count; let count = cx.count;
let doc = cx.doc(); let doc = cx.doc();
let pos = State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor()); let pos = State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor(), count);
doc.set_selection(Selection::point(pos)); doc.set_selection(Selection::point(pos));
} }
@ -169,11 +168,12 @@ pub fn move_file_end(cx: &mut Context) {
pub fn extend_next_word_start(cx: &mut Context) { pub fn extend_next_word_start(cx: &mut Context) {
let count = cx.count; let count = cx.count;
let doc = cx.doc(); let doc = cx.doc();
let mut selection = doc.selection().transform(|mut range| { let selection = doc.selection().transform(|mut range| {
let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor()); let pos =
State::move_next_word_start(doc.text().slice(..), doc.selection().cursor(), count);
range.head = pos; range.head = pos;
range range
}); // TODO: count });
doc.set_selection(selection); doc.set_selection(selection);
} }
@ -181,22 +181,23 @@ pub fn extend_next_word_start(cx: &mut Context) {
pub fn extend_prev_word_start(cx: &mut Context) { pub fn extend_prev_word_start(cx: &mut Context) {
let count = cx.count; let count = cx.count;
let doc = cx.doc(); let doc = cx.doc();
let mut selection = doc.selection().transform(|mut range| { let selection = doc.selection().transform(|mut range| {
let pos = State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor()); let pos =
State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor(), count);
range.head = pos; range.head = pos;
range range
}); // TODO: count });
doc.set_selection(selection); doc.set_selection(selection);
} }
pub fn extend_next_word_end(cx: &mut Context) { pub fn extend_next_word_end(cx: &mut Context) {
let count = cx.count; let count = cx.count;
let doc = cx.doc(); let doc = cx.doc();
let mut selection = doc.selection().transform(|mut range| { let selection = doc.selection().transform(|mut range| {
let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count); let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count);
range.head = pos; range.head = pos;
range range
}); // TODO: count });
doc.set_selection(selection); doc.set_selection(selection);
} }
@ -417,13 +418,13 @@ pub fn search_selection(cx: &mut Context) {
// //
pub fn select_line(cx: &mut Context) { pub fn select_line(cx: &mut Context) {
// TODO: count let count = cx.count;
let doc = cx.doc(); let doc = cx.doc();
let pos = doc.selection().primary(); let pos = doc.selection().primary();
let text = doc.text(); let text = doc.text();
let line = text.char_to_line(pos.head); let line = text.char_to_line(pos.head);
let start = text.line_to_char(line); let start = text.line_to_char(line);
let end = text.line_to_char(line + 1).saturating_sub(1); let end = text.line_to_char(line + count).saturating_sub(1);
doc.set_selection(Selection::single(start, end)); doc.set_selection(Selection::single(start, end));
} }

@ -12,7 +12,7 @@ pub struct Editor {
pub tree: Tree, pub tree: Tree,
// pub documents: Vec<Document>, // pub documents: Vec<Document>,
pub count: Option<usize>, pub count: Option<usize>,
pub theme: Theme, // TODO: share one instance pub theme: Theme,
pub language_servers: helix_lsp::Registry, pub language_servers: helix_lsp::Registry,
} }

Loading…
Cancel
Save