Fix completion panicking if text changed before insert completed.

imgbot
Blaž Hrastnik 3 years ago
parent 8eaf9a432d
commit 0f6624491b

@ -1290,7 +1290,7 @@ pub fn completion(cx: &mut Context) {
// TODO: if no completion, show some message or something // TODO: if no completion, show some message or something
if !res.is_empty() { if !res.is_empty() {
let snapshot = doc.state.clone(); // let snapshot = doc.state.clone();
let mut menu = ui::Menu::new( let mut menu = ui::Menu::new(
res, res,
|item| { |item| {
@ -1304,13 +1304,13 @@ pub fn completion(cx: &mut Context) {
PromptEvent::Abort => { PromptEvent::Abort => {
// revert state // revert state
let doc = &mut editor.view_mut().doc; let doc = &mut editor.view_mut().doc;
doc.state = snapshot.clone(); // doc.state = snapshot.clone();
} }
PromptEvent::Validate => { PromptEvent::Validate => {
let doc = &mut editor.view_mut().doc; let doc = &mut editor.view_mut().doc;
// revert state to what it was before the last update // revert state to what it was before the last update
doc.state = snapshot.clone(); // doc.state = snapshot.clone();
// extract as fn(doc, item): // extract as fn(doc, item):
@ -1350,6 +1350,7 @@ pub fn completion(cx: &mut Context) {
} }
} }
// TODO: <-- if state has changed by further input, transaction will panic on len
let transaction = let transaction =
util::generate_transaction_from_edits(&doc.state, vec![edit]); util::generate_transaction_from_edits(&doc.state, vec![edit]);
doc.apply(&transaction); doc.apply(&transaction);

Loading…
Cancel
Save