on master help sign in
Improve on the fix for deleting from the end of the buffer.
commit3c5dfb0633e5e5b64c78cb1c2e96291ef23e08d0 authorJakub Bartodziej <jqb@google.com> dateThu 3 Jun 2021, 09:44 (5 years ago) parent6cbc0ae
2 files changed+5−9
helix-term/src/commands.rs+5−5 helix-view/src/document.rs−4
helix-term/src/commands.rs+5−5
@@ -745,10 +745,6 @@ pub fn extend_line(cx: &mut Context) {
745745// heuristic: append changes to history after each command, unless we're in insert mode
746746
747747fn _delete_selection(doc: &mut Document, view_id: ViewId) {
748− if doc.empty() {
749− return;
750− }
751−
752748 // first yank the selection
753749 let values: Vec<String> = doc
754750 .selection(view_id)
@@ -763,7 +759,11 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) {
763759 // then delete
764760 let transaction =
765761 Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| {
766− (range.from(), range.to() + 1, None)
762+ use std::cmp::{max, min};
763+ let max_to = max(0, doc.text().len_chars() - 1);
764+ let to = min(max_to, range.to() + 1);
765+ log::info!("{} {} {}", max_to, to, doc.text().len_chars());
766+ (range.from(), to, None)
767767 });
768768 doc.apply(&transaction, view_id);
769769}
helix-view/src/document.rs−4
@@ -494,10 +494,6 @@ impl Document {
494494 pub fn versioned_identifier(&self) -> lsp::VersionedTextDocumentIdentifier {
495495 lsp::VersionedTextDocumentIdentifier::new(self.url().unwrap(), self.version)
496496 }
497−
498− pub fn empty(&self) -> bool {
499− self.text == "\n"
500− }
501497}
502498
503499#[cfg(test)]