From 548093449967bb84aaf112df736428681657c528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Fri, 8 Mar 2024 07:56:22 +1100 Subject: Bug [#2403]. Add SC_AUTOCOMPLETE_SELECT_FIRST_ITEM. This option always selects the first item in the autocompletion list. --- doc/ScintillaDoc.html | 12 ++++++++++++ doc/ScintillaHistory.html | 13 +++++++++++++ include/Scintilla.h | 1 + include/Scintilla.iface | 2 ++ include/ScintillaTypes.h | 1 + src/ScintillaBase.cxx | 2 ++ test/simpleTests.py | 22 ++++++++++++++++++++++ 7 files changed, 53 insertions(+) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index b65a9c8ef..9f8f6d937 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -6420,6 +6420,18 @@ struct Sci_TextToFindFull { This also avoids a header rectangle above the list. + + SC_AUTOCOMPLETE_SELECT_FIRST_ITEM + + 2 + + Always select the first item from the autocompletion list regardless of the value + entered in the editor. Useful when the autocompletion logic of the application + sorts autocompletion entries so that the best match is always at the top of the + list. Without this option, Scintilla selects the item from the autocompletion + list matching the value entered in the editor. + + diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 49d939332..eed1fc4ba 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -583,6 +583,19 @@

Releases

+

+ Release 5.4.3 +

+

Release 5.4.2

diff --git a/include/Scintilla.h b/include/Scintilla.h index 4ea264d8e..9b53ae174 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -445,6 +445,7 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SCI_AUTOCGETAUTOHIDE 2119 #define SC_AUTOCOMPLETE_NORMAL 0 #define SC_AUTOCOMPLETE_FIXED_SIZE 1 +#define SC_AUTOCOMPLETE_SELECT_FIRST_ITEM 2 #define SCI_AUTOCSETOPTIONS 2638 #define SCI_AUTOCGETOPTIONS 2639 #define SCI_AUTOCSETDROPRESTOFWORD 2270 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 9f5b5a054..3f88653ce 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1100,6 +1100,8 @@ enu AutoCompleteOption=SC_AUTOCOMPLETE_ val SC_AUTOCOMPLETE_NORMAL=0 # Win32 specific: val SC_AUTOCOMPLETE_FIXED_SIZE=1 +# Always select the first item in the autocompletion list: +val SC_AUTOCOMPLETE_SELECT_FIRST_ITEM=2 # Set autocompletion options. set void AutoCSetOptions=2638(AutoCompleteOption options,) diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index 4692e9916..128b73002 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -249,6 +249,7 @@ enum class IndicFlag { enum class AutoCompleteOption { Normal = 0, FixedSize = 1, + SelectFirstItem = 2, }; enum class IndentView { diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index a629cdd33..c66a689b7 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -353,6 +353,8 @@ void ScintillaBase::AutoCompleteMove(int delta) { } void ScintillaBase::AutoCompleteMoveToCurrentWord() { + if (FlagSet(ac.options, AutoCompleteOption::SelectFirstItem)) + return; std::string wordCurrent = RangeText(ac.posStart - ac.startLen, sel.MainCaret()); ac.Select(wordCurrent.c_str()); } diff --git a/test/simpleTests.py b/test/simpleTests.py index 72007f86a..900f97faf 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -3129,6 +3129,28 @@ class TestAutoComplete(unittest.TestCase): self.assertEqual(self.ed.AutoCActive(), 0) + def testAutoSelectFirstItem(self): + self.assertEqual(self.ed.AutoCActive(), 0) + + self.ed.AutoCSetOrder(self.ed.SC_ORDER_CUSTOM) + + # without SC_AUTOCOMPLETE_SELECT_FIRST_ITEM option + self.ed.SetSel(3, 3) + self.ed.AutoCShow(3, b"aaa1 bbb1 xxx1") + # automatically selects the item with the entered prefix xxx + self.ed.AutoCComplete() + self.assertEqual(self.ed.Contents(), b"xxx1\n") + + # with SC_AUTOCOMPLETE_SELECT_FIRST_ITEM option + self.ed.AutoCSetOptions(2, 0) + self.ed.SetSel(3, 3) + self.ed.AutoCShow(3, b"aaa1 bbb1 xxx1") + # selects the first item regardless of the entered prefix and replaces the entered xxx + self.ed.AutoCComplete() + self.assertEqual(self.ed.Contents(), b"aaa11\n") + + self.assertEqual(self.ed.AutoCActive(), 0) + def testAutoCustomSort(self): # Checks bug #2294 where SC_ORDER_CUSTOM with an empty list asserts # https://sourceforge.net/p/scintilla/bugs/2294/ -- cgit v1.2.3