Disable deleting from an empty buffer which can cause a crash.

This commit is contained in:
Jakub Bartodziej 2021-06-03 08:51:13 -04:00 committed by Blaž Hrastnik
parent c1c3750d38
commit 6cbc0aea92
2 changed files with 8 additions and 0 deletions

View File

@ -745,6 +745,10 @@ 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)

View File

@ -494,6 +494,10 @@ 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)]