diff options
author | Pascal Kuthe | 2023-03-02 20:56:55 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-03-09 04:01:02 +0000 |
commit | e8898fd9a8ac8120827fb2d6f4752b3cb2431a62 (patch) | |
tree | bc6abc2aa663c7c31fa006bf14d3a59cc9269191 /helix-term/src/commands.rs | |
parent | 2588fa3710921683c16a84ffd91103a0823a033b (diff) |
store multiple snapshots on the document at once
Fixing autocomplete required moving the document savepoint before the
asynchronous completion request. However, this in turn causes new bugs:
If the completion popup is open, the savepoint is restored when the
popup closes (or another entry is selected). However, at that point
a new completion request might already have been created which
would have replaced the new savepoint (therefore leading to incorrectly
applied complies).
This commit fixes that bug by allowing in arbitrary number of
savepoints to be tracked on the document. The savepoints are reference
counted and therefore remain valid as long as any reference to them
remains. Weak reference are stored on the document and any reference
that can not be upgraded anymore (hence no strong reference remain)
are automatically discarded.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index bc0e8ebe..01673c89 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4181,7 +4181,7 @@ pub fn completion(cx: &mut Context) { iter.reverse(); let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count(); let start_offset = cursor.saturating_sub(offset); - doc.savepoint(&view); + let savepoint = doc.savepoint(view); cx.callback( future, @@ -4209,6 +4209,7 @@ pub fn completion(cx: &mut Context) { let ui = compositor.find::<ui::EditorView>().unwrap(); ui.set_completion( editor, + savepoint, items, offset_encoding, start_offset, |