on master help sign in
minor changes
9cac44cBlaž Hrastnik
helix-core/src/selection.rs+6−2
@@ -278,7 +278,7 @@ pub fn select_on_matches(
278 text: &RopeSlice,
278 text: &RopeSlice,
279 selections: &Selection,
279 selections: &Selection,
280 regex: &crate::regex::Regex,
280 regex: &crate::regex::Regex,
281−) -> Selection {
281+) -> Option<Selection> {
282 let mut result = SmallVec::with_capacity(selections.ranges().len());
282 let mut result = SmallVec::with_capacity(selections.ranges().len());
283
283
284 for sel in selections.ranges() {
284 for sel in selections.ranges() {
@@ -300,7 +300,11 @@ pub fn select_on_matches(
300 }
300 }
301
301
302 // TODO: figure out a new primary index
302 // TODO: figure out a new primary index
303+ if !result.is_empty() {
303− Selection::new(result, 0)
304+ return Some(Selection::new(result, 0));
305+ }
306+
307+ None
304}
308}
305
309
306// TODO: support to split on capture #N instead of whole match
310// TODO: support to split on capture #N instead of whole match
helix-core/src/transaction.rs+1−4
@@ -314,10 +314,7 @@ impl ChangeSet {
314 /// `true` when the set is empty.
314 /// `true` when the set is empty.
315 #[inline]
315 #[inline]
316 pub fn is_empty(&self) -> bool {
316 pub fn is_empty(&self) -> bool {
317− match self.changes.as_slice() {
317+ matches!(self.changes.as_slice(), [] | [Operation::Retain(_)])
318− [] | [Operation::Retain(_)] => true,
319− _ => false,
320− }
321 }
318 }
322
319
323 /// Map a position through the changes.
320 /// 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 {
193 let line = doc.text().char_to_line(cursor);
193 let line = doc.text().char_to_line(cursor);
194 let document_end = view.first_line + view.area.height.saturating_sub(1) as usize;
194 let document_end = view.first_line + view.area.height.saturating_sub(1) as usize;
195
195
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) {
197 return false;
197 return false;
198 }
198 }
199 true
199 true
@@ -304,7 +304,9 @@ pub fn select_all(cx: &mut Context) {
304pub fn select_regex(cx: &mut Context) {
304pub fn select_regex(cx: &mut Context) {
305 let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
305 let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
306 let text = &doc.text().slice(..);
306 let text = &doc.text().slice(..);
307+ // TODO: if select on matches returns empty range, we need to abort
308+ let selection =
307− let selection = selection::select_on_matches(text, doc.selection(), &regex);
309+ selection::select_on_matches(text, doc.selection(), &regex).expect("no matches");
308 doc.set_selection(selection);
310 doc.set_selection(selection);
309 });
311 });
310 cx.callback = Some(Box::new(
312 cx.callback = Some(Box::new(
helix-term/src/ui/editor.rs+3−3
@@ -77,7 +77,7 @@ impl EditorView {
77 let range = {
77 let range = {
78 // calculate viewport byte ranges
78 // calculate viewport byte ranges
79 let start = text.line_to_byte(view.first_line);
79 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
81
81
82 start..end
82 start..end
83 };
83 };
@@ -381,8 +381,8 @@ impl Component for EditorView {
381 }
381 }
382 }
382 }
383 mode => {
383 mode => {
384− match keys.as_slice() {
384+ match *keys.as_slice() {
385− &[KeyEvent {
385+ [KeyEvent {
386 code: KeyCode::Char(i @ '0'..='9'),
386 code: KeyCode::Char(i @ '0'..='9'),
387 modifiers: KeyModifiers::NONE,
387 modifiers: KeyModifiers::NONE,
388 }] => {
388 }] => {