bugfix(replace): fix issue with regexes targeting empty lines replacing with nothing (#347)
This commit is contained in:
parent
a578d8bf98
commit
7fa83125ab
1 changed files with 14 additions and 1 deletions
15
src/tab.rs
15
src/tab.rs
|
|
@ -286,13 +286,26 @@ impl EditorTab {
|
||||||
end.index = index + len;
|
end.index = index + len;
|
||||||
|
|
||||||
editor.start_change();
|
editor.start_change();
|
||||||
|
// if index = 0 and len = 0, we are targeting and deleting an empty line
|
||||||
|
// we'll move either cursor or end to delete the newline
|
||||||
|
if index == 0 && len == 0 {
|
||||||
|
if cursor.line > 0 {
|
||||||
|
// move the cursor up one line
|
||||||
|
cursor.line -= 1;
|
||||||
|
cursor.index =
|
||||||
|
editor.with_buffer(|buffer| buffer.lines[cursor.line].text().len());
|
||||||
|
} else if cursor.line + 1 < editor.with_buffer(|buffer| buffer.lines.len()) {
|
||||||
|
// move the end down one line
|
||||||
|
end.line += 1;
|
||||||
|
end.index = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
editor.delete_range(cursor, end);
|
editor.delete_range(cursor, end);
|
||||||
cursor = editor.insert_at(cursor, replace, None);
|
cursor = editor.insert_at(cursor, replace, None);
|
||||||
editor.set_cursor(cursor);
|
editor.set_cursor(cursor);
|
||||||
// Need to disable selection to prevent the new cursor showing selection to old location
|
// Need to disable selection to prevent the new cursor showing selection to old location
|
||||||
editor.set_selection(Selection::None);
|
editor.set_selection(Selection::None);
|
||||||
editor.finish_change();
|
editor.finish_change();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue