Skip to content

Don't show autocomplete after backspacing over whitespace#937

Merged
dzhou121 merged 5 commits intolapce:masterfrom
zarathir:autocomplete-after-backspace
Aug 9, 2022
Merged

Don't show autocomplete after backspacing over whitespace#937
dzhou121 merged 5 commits intolapce:masterfrom
zarathir:autocomplete-after-backspace

Conversation

@zarathir
Copy link
Copy Markdown
Contributor

@zarathir zarathir commented Aug 6, 2022

Fixes #743
Added EditCommand::DeleteBackward and EditCommand::DeleteForward to the match statement that checks for whitespace commands. On receiving one of these commands the deleted string gets checked if it's all whitespace.

Added EditCommand::Undo and EditCommand::Redo to the check, because i think it's not necessary to show autocompletion after an undo or redo.

Maybe it would make sense to extract this into a function?

@MinusGix MinusGix added the A-editor Area: editor, modal editing label Aug 6, 2022
@zarathir zarathir marked this pull request as ready for review August 7, 2022 12:27
};

if start > &0 && end > &0 && end > start {
let slice = &doc[*start..*end];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the slice_to_cow on the rope to make it more efficient without converting the rope to a string.

https://github.com/lapce/lapce/blob/master/lapce-core/src/buffer.rs#L931

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you pass the Rope to show_completion(...)? Because slice_to_cow takes a Range as argument it would end up something like this:

fn show_completion(cmd: &EditCommand, doc: &Rope, deltas: &[(RopeDelta, InvalLines)]) -> bool {
    [...]
    if start > &0 && end > start {
        !doc.slice_to_cow(*start..*end)
            .chars()
            .all(|c| c.is_whitespace() || c.is_ascii_whitespace())
    } else {
        true
}

I'll have to try if this works and update with results 😄

@dzhou121 dzhou121 merged commit 7cb3b13 into lapce:master Aug 9, 2022
@zarathir zarathir deleted the autocomplete-after-backspace branch August 23, 2022 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-editor Area: editor, modal editing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't show autocomplete after backspacing over whitespace

3 participants