mirror of https://github.com/helix-editor/helix
minor changes
parent
8e1a59c140
commit
9cac44c7c0
|
@ -278,7 +278,7 @@ pub fn select_on_matches(
|
||||||
text: &RopeSlice,
|
text: &RopeSlice,
|
||||||
selections: &Selection,
|
selections: &Selection,
|
||||||
regex: &crate::regex::Regex,
|
regex: &crate::regex::Regex,
|
||||||
) -> Selection {
|
) -> Option<Selection> {
|
||||||
let mut result = SmallVec::with_capacity(selections.ranges().len());
|
let mut result = SmallVec::with_capacity(selections.ranges().len());
|
||||||
|
|
||||||
for sel in selections.ranges() {
|
for sel in selections.ranges() {
|
||||||
|
@ -300,7 +300,11 @@ pub fn select_on_matches(
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: figure out a new primary index
|
// TODO: figure out a new primary index
|
||||||
Selection::new(result, 0)
|
if !result.is_empty() {
|
||||||
|
return Some(Selection::new(result, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support to split on capture #N instead of whole match
|
// TODO: support to split on capture #N instead of whole match
|
||||||
|
|
|
@ -314,10 +314,7 @@ impl ChangeSet {
|
||||||
/// `true` when the set is empty.
|
/// `true` when the set is empty.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
match self.changes.as_slice() {
|
matches!(self.changes.as_slice(), [] | [Operation::Retain(_)])
|
||||||
[] | [Operation::Retain(_)] => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Map a position through the changes.
|
/// Map a position through the changes.
|
||||||
|
|
|
@ -193,7 +193,7 @@ pub fn check_cursor_in_view(view: &View) -> bool {
|
||||||
let line = doc.text().char_to_line(cursor);
|
let line = doc.text().char_to_line(cursor);
|
||||||
let document_end = view.first_line + view.area.height.saturating_sub(1) as usize;
|
let document_end = view.first_line + view.area.height.saturating_sub(1) as usize;
|
||||||
|
|
||||||
if (line > document_end.saturating_sub(PADDING)) | (line < view.first_line + PADDING) {
|
if (line > document_end.saturating_sub(PADDING)) || (line < view.first_line + PADDING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -304,7 +304,9 @@ pub fn select_all(cx: &mut Context) {
|
||||||
pub fn select_regex(cx: &mut Context) {
|
pub fn select_regex(cx: &mut Context) {
|
||||||
let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
|
let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
|
||||||
let text = &doc.text().slice(..);
|
let text = &doc.text().slice(..);
|
||||||
let selection = selection::select_on_matches(text, doc.selection(), ®ex);
|
// TODO: if select on matches returns empty range, we need to abort
|
||||||
|
let selection =
|
||||||
|
selection::select_on_matches(text, doc.selection(), ®ex).expect("no matches");
|
||||||
doc.set_selection(selection);
|
doc.set_selection(selection);
|
||||||
});
|
});
|
||||||
cx.callback = Some(Box::new(
|
cx.callback = Some(Box::new(
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl EditorView {
|
||||||
let range = {
|
let range = {
|
||||||
// calculate viewport byte ranges
|
// calculate viewport byte ranges
|
||||||
let start = text.line_to_byte(view.first_line);
|
let start = text.line_to_byte(view.first_line);
|
||||||
let end = text.line_to_byte(last_line) + text.line(last_line).len_bytes();
|
let end = text.line_to_byte(last_line + 1); // TODO: double check
|
||||||
|
|
||||||
start..end
|
start..end
|
||||||
};
|
};
|
||||||
|
@ -381,8 +381,8 @@ impl Component for EditorView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mode => {
|
mode => {
|
||||||
match keys.as_slice() {
|
match *keys.as_slice() {
|
||||||
&[KeyEvent {
|
[KeyEvent {
|
||||||
code: KeyCode::Char(i @ '0'..='9'),
|
code: KeyCode::Char(i @ '0'..='9'),
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
}] => {
|
}] => {
|
||||||
|
|
Loading…
Reference in New Issue