on master help sign in
Improve on the fix for deleting from the end of the buffer.
3c5dfb0Jakub Bartodziej
helix-term/src/commands.rs+5−5
@@ -745,10 +745,6 @@ pub fn extend_line(cx: &mut Context) {
745// heuristic: append changes to history after each command, unless we're in insert mode
745// heuristic: append changes to history after each command, unless we're in insert mode
746
746
747fn _delete_selection(doc: &mut Document, view_id: ViewId) {
747fn _delete_selection(doc: &mut Document, view_id: ViewId) {
748− if doc.empty() {
749− return;
750− }
751−
752 // first yank the selection
748 // first yank the selection
753 let values: Vec<String> = doc
749 let values: Vec<String> = doc
754 .selection(view_id)
750 .selection(view_id)
@@ -763,7 +759,11 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) {
763 // then delete
759 // then delete
764 let transaction =
760 let transaction =
765 Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| {
761 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)
767 });
767 });
768 doc.apply(&transaction, view_id);
768 doc.apply(&transaction, view_id);
769}
769}
helix-view/src/document.rs−4
@@ -494,10 +494,6 @@ impl Document {
494 pub fn versioned_identifier(&self) -> lsp::VersionedTextDocumentIdentifier {
494 pub fn versioned_identifier(&self) -> lsp::VersionedTextDocumentIdentifier {
495 lsp::VersionedTextDocumentIdentifier::new(self.url().unwrap(), self.version)
495 lsp::VersionedTextDocumentIdentifier::new(self.url().unwrap(), self.version)
496 }
496 }
497−
498− pub fn empty(&self) -> bool {
499− self.text == "\n"
500− }
501}
497}
502
498
503#[cfg(test)]
499#[cfg(test)]