From 8c072de2afd93aad9923966edc58ec0736deffb2 Mon Sep 17 00:00:00 2001 From: Grim Maple Date: Tue, 26 Apr 2022 19:29:15 +0300 Subject: [PATCH] Fix autocompletion crash; autocompletion cancel --- src/dlangide/ui/dsourceedit.d | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/dlangide/ui/dsourceedit.d b/src/dlangide/ui/dsourceedit.d index 134ebb4..17f8837 100644 --- a/src/dlangide/ui/dsourceedit.d +++ b/src/dlangide/ui/dsourceedit.d @@ -724,7 +724,9 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener { private bool isAutoCompleteKey(ref KeyEvent event) { if((event.keyCode >= KeyCode.KEY_0 && event.keyCode <= KeyCode.KEY_Z) || - event.keyCode == KeyCode.KEY_PERIOD) + event.keyCode == KeyCode.KEY_PERIOD || + event.keyCode == KeyCode.BACK || + event.text == "_") return true; return false; } @@ -735,7 +737,7 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener { override bool onKeyEvent(KeyEvent event) { if (event.action == KeyAction.KeyDown) _lastKeyDownCode = event.keyCode; - if(_settings.autoAutoComplete && !_completionPopup) { + if(_settings.autoAutoComplete && isAutoCompleteKey(event) && !_completionPopup) { window.dispatchAction(ACTION_GET_COMPLETIONS, this); } else if (event.action == KeyAction.Text && event.noModifiers && event.text==".") { @@ -817,19 +819,12 @@ class CompletionPopupMenu : PopupMenu { /// handle keys override bool onKeyEvent(KeyEvent event) { if (event.action == KeyAction.Text) { - _prefix ~= event.text; - MenuItem newItems = updateItems(); - if (newItems.subitemCount == 0) { - // no matches anymore - _editor.onKeyEvent(event); - _editor.closeCompletionPopup(this); - return true; - } else { - _editor.onKeyEvent(event); - menuItems = newItems; - selectItem(0); - return true; - } + _editor.onKeyEvent(event); + _editor.closeCompletionPopup(this); + return true; + } else if (event.keyCode == KeyCode.ESCAPE) { + _editor.closeCompletionPopup(this); + return true; } else if (event.action == KeyAction.KeyDown && event.keyCode == KeyCode.BACK && event.noModifiers) { if (_prefix.length > _initialPrefix.length) { _prefix.length = _prefix.length - 1; @@ -842,8 +837,8 @@ class CompletionPopupMenu : PopupMenu { _editor.closeCompletionPopup(this); } return true; - } else if (event.action == KeyAction.KeyDown && event.keyCode == KeyCode.RETURN) { - } else if (event.action == KeyAction.KeyDown && event.keyCode == KeyCode.SPACE) { + } else if ((event.action == KeyAction.KeyDown && event.keyCode == KeyCode.RETURN) || + (event.action == KeyAction.KeyDown && event.keyCode == KeyCode.SPACE)) { } return super.onKeyEvent(event); }