on master help sign in
Fix completion panicking if text changed before insert completed.
0f66244Blaž Hrastnik
helix-term/src/commands.rs+4−3
@@ -1290,7 +1290,7 @@ pub fn completion(cx: &mut Context) {
1290
1290
1291 // TODO: if no completion, show some message or something
1291 // TODO: if no completion, show some message or something
1292 if !res.is_empty() {
1292 if !res.is_empty() {
1293− let snapshot = doc.state.clone();
1293+ // let snapshot = doc.state.clone();
1294 let mut menu = ui::Menu::new(
1294 let mut menu = ui::Menu::new(
1295 res,
1295 res,
1296 |item| {
1296 |item| {
@@ -1304,13 +1304,13 @@ pub fn completion(cx: &mut Context) {
1304 PromptEvent::Abort => {
1304 PromptEvent::Abort => {
1305 // revert state
1305 // revert state
1306 let doc = &mut editor.view_mut().doc;
1306 let doc = &mut editor.view_mut().doc;
1307− doc.state = snapshot.clone();
1307+ // doc.state = snapshot.clone();
1308 }
1308 }
1309 PromptEvent::Validate => {
1309 PromptEvent::Validate => {
1310 let doc = &mut editor.view_mut().doc;
1310 let doc = &mut editor.view_mut().doc;
1311
1311
1312 // revert state to what it was before the last update
1312 // revert state to what it was before the last update
1313− doc.state = snapshot.clone();
1313+ // doc.state = snapshot.clone();
1314
1314
1315 // extract as fn(doc, item):
1315 // extract as fn(doc, item):
1316
1316
@@ -1350,6 +1350,7 @@ pub fn completion(cx: &mut Context) {
1350 }
1350 }
1351 }
1351 }
1352
1352
1353+ // TODO: <-- if state has changed by further input, transaction will panic on len
1353 let transaction =
1354 let transaction =
1354 util::generate_transaction_from_edits(&doc.state, vec![edit]);
1355 util::generate_transaction_from_edits(&doc.state, vec![edit]);
1355 doc.apply(&transaction);
1356 doc.apply(&transaction);