Improve on the fix for deleting from the end of the buffer.

This commit is contained in:
Jakub Bartodziej 2021-06-03 09:44:16 -04:00 committed by Blaž Hrastnik
parent 6cbc0aea92
commit 3c5dfb0633
2 changed files with 5 additions and 9 deletions

View file

@ -745,10 +745,6 @@ pub fn extend_line(cx: &mut Context) {
// heuristic: append changes to history after each command, unless we're in insert mode // heuristic: append changes to history after each command, unless we're in insert mode
fn _delete_selection(doc: &mut Document, view_id: ViewId) { fn _delete_selection(doc: &mut Document, view_id: ViewId) {
if doc.empty() {
return;
}
// first yank the selection // first yank the selection
let values: Vec<String> = doc let values: Vec<String> = doc
.selection(view_id) .selection(view_id)
@ -763,7 +759,11 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) {
// then delete // then delete
let transaction = let transaction =
Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| { Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| {
(range.from(), range.to() + 1, None) use std::cmp::{max, min};
let max_to = max(0, doc.text().len_chars() - 1);
let to = min(max_to, range.to() + 1);
log::info!("{} {} {}", max_to, to, doc.text().len_chars());
(range.from(), to, None)
}); });
doc.apply(&transaction, view_id); doc.apply(&transaction, view_id);
} }

View file

@ -494,10 +494,6 @@ impl Document {
pub fn versioned_identifier(&self) -> lsp::VersionedTextDocumentIdentifier { pub fn versioned_identifier(&self) -> lsp::VersionedTextDocumentIdentifier {
lsp::VersionedTextDocumentIdentifier::new(self.url().unwrap(), self.version) lsp::VersionedTextDocumentIdentifier::new(self.url().unwrap(), self.version)
} }
pub fn empty(&self) -> bool {
self.text == "\n"
}
} }
#[cfg(test)] #[cfg(test)]