on master help sign in
minor changes
commit9cac44c7c0f5696c8749fd8fdd32b8174723ab5d authorBlaž Hrastnik <blaz@mxxn.io> dateWed 17 Feb 2021, 14:41 (6 years ago) parent8e1a59c
4 files changed+14−11
helix-core/src/selection.rs+6−2 helix-core/src/transaction.rs+1−4 helix-term/src/commands.rs+4−2 helix-term/src/ui/editor.rs+3−3
helix-core/src/selection.rs+6−2
@@ -278,7 +278,7 @@ pub fn select_on_matches(
278278 text: &RopeSlice,
279279 selections: &Selection,
280280 regex: &crate::regex::Regex,
281−) -> Selection {
281+) -> Option<Selection> {
282282 let mut result = SmallVec::with_capacity(selections.ranges().len());
283283
284284 for sel in selections.ranges() {
@@ -300,7 +300,11 @@ pub fn select_on_matches(
300300 }
301301
302302 // TODO: figure out a new primary index
303− Selection::new(result, 0)
303+ if !result.is_empty() {
304+ return Some(Selection::new(result, 0));
305+ }
306+
307+ None
304308}
305309
306310// TODO: support to split on capture #N instead of whole match
helix-core/src/transaction.rs+1−4
@@ -314,10 +314,7 @@ impl ChangeSet {
314314 /// `true` when the set is empty.
315315 #[inline]
316316 pub fn is_empty(&self) -> bool {
317− match self.changes.as_slice() {
318− [] | [Operation::Retain(_)] => true,
319− _ => false,
320− }
317+ matches!(self.changes.as_slice(), [] | [Operation::Retain(_)])
321318 }
322319
323320 /// Map a position through the changes.
helix-term/src/commands.rs+4−2
@@ -193,7 +193,7 @@ pub fn check_cursor_in_view(view: &View) -> bool {
193193 let line = doc.text().char_to_line(cursor);
194194 let document_end = view.first_line + view.area.height.saturating_sub(1) as usize;
195195
196− if (line > document_end.saturating_sub(PADDING)) | (line < view.first_line + PADDING) {
196+ if (line > document_end.saturating_sub(PADDING)) || (line < view.first_line + PADDING) {
197197 return false;
198198 }
199199 true
@@ -304,7 +304,9 @@ pub fn select_all(cx: &mut Context) {
304304pub fn select_regex(cx: &mut Context) {
305305 let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
306306 let text = &doc.text().slice(..);
307− let selection = selection::select_on_matches(text, doc.selection(), &regex);
307+ // TODO: if select on matches returns empty range, we need to abort
308+ let selection =
309+ selection::select_on_matches(text, doc.selection(), &regex).expect("no matches");
308310 doc.set_selection(selection);
309311 });
310312 cx.callback = Some(Box::new(
helix-term/src/ui/editor.rs+3−3
@@ -77,7 +77,7 @@ impl EditorView {
7777 let range = {
7878 // calculate viewport byte ranges
7979 let start = text.line_to_byte(view.first_line);
80− let end = text.line_to_byte(last_line) + text.line(last_line).len_bytes();
80+ let end = text.line_to_byte(last_line + 1); // TODO: double check
8181
8282 start..end
8383 };
@@ -381,8 +381,8 @@ impl Component for EditorView {
381381 }
382382 }
383383 mode => {
384− match keys.as_slice() {
385− &[KeyEvent {
384+ match *keys.as_slice() {
385+ [KeyEvent {
386386 code: KeyCode::Char(i @ '0'..='9'),
387387 modifiers: KeyModifiers::NONE,
388388 }] => {