diff options
author | Jiří Techet <techet@gmail.com> | 2024-03-08 07:56:22 +1100 |
---|---|---|
committer | Jiří Techet <techet@gmail.com> | 2024-03-08 07:56:22 +1100 |
commit | 548093449967bb84aaf112df736428681657c528 (patch) | |
tree | 2b0fa62496674d8d1f777679628a56e8fcbca0c0 | |
parent | 792b3fde18766b74c56472a26fa82107b650d3e4 (diff) | |
download | scintilla-mirror-548093449967bb84aaf112df736428681657c528.tar.gz |
Bug [#2403]. Add SC_AUTOCOMPLETE_SELECT_FIRST_ITEM.
This option always selects the first item in the autocompletion list.
-rw-r--r-- | doc/ScintillaDoc.html | 12 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 13 | ||||
-rw-r--r-- | include/Scintilla.h | 1 | ||||
-rw-r--r-- | include/Scintilla.iface | 2 | ||||
-rw-r--r-- | include/ScintillaTypes.h | 1 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 2 | ||||
-rw-r--r-- | test/simpleTests.py | 22 |
7 files changed, 53 insertions, 0 deletions
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.</td> </tr> + <tr> + <td align="left"><code>SC_AUTOCOMPLETE_SELECT_FIRST_ITEM</code></td> + + <td align="center">2</td> + + <td>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.</td> + </tr> + </tbody> </table> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 49d939332..eed1fc4ba 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -584,6 +584,19 @@ </table> <h2>Releases</h2> <h3> + <a href="https://www.scintilla.org/scintilla543.zip">Release 5.4.3</a> + </h3> + <ul> + <li> + Released 5 March 2024. + </li> + <li> + Add SC_AUTOCOMPLETE_SELECT_FIRST_ITEM option to + always selects the first item in the autocompletion list. + <a href="https://sourceforge.net/p/scintilla/bugs/2403/">Bug #2403</a>. + </li> + </ul> + <h3> <a href="https://www.scintilla.org/scintilla542.zip">Release 5.4.2</a> </h3> <ul> 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/ |