[Class] eAutocomplete - Custom word completion for (Rich)Edit controls

Post your working scripts, libraries and tools
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

[Class] eAutocomplete - Custom word completion for (Rich)Edit controls

13 May 2018, 13:49

eAutocomplete

The class provides a programmable interface allowing to easily integrate a custom word autocomplete function in a given script or project. Any Edit/RICHEDIT50W control should be able to be wrapped into an eAutocomplete object. Practically, it enables users to quickly find, get info tips and select from a dynamic pre-populated list of data (e.g. complete strings, replacement strings) as he types, leveraging typing, definition lookups, searching, translation, filtering etc.


Image - Image




Sample example


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


An html file, bundled in the release provides an overview of the programmable interface.





Thanks to:

- AlphaBravo, jeeswg and just me.
- brutus_skywalker for his valuable suggestions on how to make more ergonomic and user-friendly the common features provided by the script via the use of keyboard shortcuts.
- G33kDude (GeekDude) and ManiacDC whose respective works - respectively CQT.AutoComplete.ahk and TypingAid - served as models for this one.

Future ideas include:
- Possibility of docking the listbox.
- Possibility of deleting suggestions from the listbox.
- Possibility of setting the delay between when a keystroke occurs and when a search is performed.
- Add an OnSuggestionsAvailable callback.
- Add support for languages displayed in right-to-left (RTL) mode.
- Display suggestions by frequency and/or recentness.
- Add support for all user interface elements whose Value property is provided by the IAccessible interface.
with the latter two requiring perhaps a more fundamental overhaul of the class.
Last edited by A_AhkUser on 05 Aug 2018, 18:32, edited 13 times in total.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Custom word completion for edit controls

14 May 2018, 07:18

https://autohotkey.com/board/topic/96129-ahk-l-custom-autocompletion-for-edit-control-with-drop-down-list might harbor solutions to your issues. Wierd,its the second time this week I've linked that post.
Outsourcing Clicks & Presses Since 2004.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: Custom word completion for edit controls

14 May 2018, 13:30

HI brutus_skywalker,


Perhaps, but unfortunately it is lost in the midst of a whole series of NumGet, NumPut, ObjRelease... and structures are not my cup of tea :headwall: :(

brutus_skywalker wrote:Wierd,its the second time this week I've linked that post.

Nothing weird here and, in fact, I already knew this outstanding code and you are not the only one to link it: https://autohotkey.com/boards/viewtopic ... #p194586...

However, it seems it has a intrinsic limitation; it seems it doesn't allow to expand substrings anywhere inside the input; it relies on the IAutoComplete interface which does not appear to provide this feature: none of the available options is likely to enable this behaviour - but I may be mistaken. Anyway thanks for wisely providing this link, pertinent here. I added, in that respect, two properties to the class, available in the script of nepter, onSelect and useTab.
. onSelect associates a function object with the drop-down list; I updated the example with a custom callback: when an item is selected (Enter when drop-down list is visible), it launches a search engine on the model of the ACO_SEARCH option.
. if useTab evaluates to true, users can use the TAB key to select an item from the drop-down list (similar to ACO_USETAB).

Btw, I fixed the regex: as for now, a match occurs even if only one item matchs in the word list.

Location: Antarctica

AutoHotkey seems to have conquered all seven continents :wtf: :clap: :lol: - thinking about it, this is not so surprising... :lol:
Last edited by A_AhkUser on 20 May 2018, 23:55, edited 1 time in total.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: Custom word completion for edit controls

17 May 2018, 10:17

There's no need anymore to make the GUI delimiter fit the one which seperates each item in the autocomplete list.
I updated the documentation and the first post to make the class as user-friendly as possible and also sparingly commented the source.
fenchai
Posts: 186
Joined: 28 Mar 2016, 07:57

Re: Custom word completion for edit controls

17 May 2018, 14:35

brutus_skywalker wrote:https://autohotkey.com/board/topic/96129-ahk-l-custom-autocompletion-for-edit-control-with-drop-down-list might harbor solutions to your issues. Wierd,its the second time this week I've linked that post.


I would kill to get something like this BUT also for searching letters or numbers that does not necessarily begin with it.

Like 17801-21050

typing 210... shows 17801-21050 as a suggestion. It makes life waay easier this way instead of typing 17801.. (which there are like probably thousands of them)

I already have a code that can do this BUT it gets laggy when showing more than 10 suggestions and does not show in a compact way like this code does
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: Custom word completion for edit controls

17 May 2018, 16:39

Hola fenchai,

fenchai wrote:I would kill to get something like this BUT also for searching letters or numbers that does not necessarily begin with it. [...] Like 17801-21050 [...] typing 210... shows 17801-21050 as a suggestion.


Regarding eAutocomplete, it supports wilcard searches (the dot-star pattern .*) - only starting from the second character, though. The reason behind that is, that the class first preprocessed the input string/file's content, creating a autocomplete dictionary - so that the search can be more efficient by reducing the length of the input string whose content is searched by both the RegExMatch and RegExReplace functions.


| EDIT | Removed deprecated code snippet.
Last edited by A_AhkUser on 06 Jun 2018, 22:29, edited 1 time in total.
fenchai
Posts: 186
Joined: 28 Mar 2016, 07:57

Re: Custom word completion for edit controls

17 May 2018, 20:58

Bonjour A_AhkUser,

Long time no see :) just realized you made this post, I'm glad.

I like your method. It is very straightforward. I will surely implement it to my code. For some reason, my Uncle refuses to use click on another editbox to autocomplete or even just using arrow keys to move around. I am sure he will like your code. He likes to type the entire code :D I am too lazy for that. But he will like this.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: Custom word completion for edit controls

18 May 2018, 23:41

@fenchai
In other words, you want it to rather pre-select/auto-append the first matching item among available suggestions?
However, note that the autoappend feature is hardly compatible with wilcard searches (especially when the regex symbol appears at the left of the caret position): lets' say you enter *wk... it automatically appends awkward while you intended in fact to enter lowkey... if you press e you will end up with awkwe... :headwall: wich is, admittedly... awkward :crazy: :lol: For sure this can be avoid by storing the value of the last input not to be automatically appended in order to restore it later (in case you press a letter, enter a space character or press the backspace key) - but without the co-presence of both the regular expression and the suggestion, autocompletion will become less intuitive, I guess. Whatever it could be, thanks much for the suggestion: I added a autoAppend option.


. Added an autoAppend option. If it evaluates to true - and presuming that the last word partially entered is not a regular expression - the first item in the drop-down list is pre-select/auto-append without the need to press any of the arrow keys. The option defaults to false.
. Fixed incorrect ranges of selected additional characters (those highlighted and showing in a preview the complete word) with respect to the letters that have been actually entered.

Other minor changes:
. The drop-down list is now docked: it follows the main window in case this latter is resized/moved while it is still displayed (instead of being simply hidden).
. A upper threshold of 132 items to load in the drop-down list has been set for efficiency reason. 132 can still potentially be efficent since the menu navigation is circular: the last item can still be reached by simply pressing Up.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Custom word completion for edit controls

19 May 2018, 09:10

If i may make a suggestion, having to use up/down to select an item kinda gets old after a while, i think 'Tab' should select the top most item, it's just better that way & it doesn't slow you down. For those 'few' times one may want to actually tab, it's just as easy to press escape then tab as it now already works.

It's shaping up real sweet dude,the wildcard autoAppend is a feature that i never knew i needed,but clearly i freaking do...love it.
Outsourcing Clicks & Presses Since 2004.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: Custom word completion for edit controls

19 May 2018, 18:17

Hi brutus_skywalker,

I'm glad you like it. Concerning the commands, I guess you're right; as of now, one can - alternatively - use Tab/Shift+Tab to select from the list of available suggestions and, as for the Right arrow key, it is intended to send the selected item (as well as the Enter to also move to the next line at the same time, if need be). The ESC key, on the other hand, will henceforth clear the selection in addition to close the drop-down list.

As for the wilcard autoAppend option, and for the reasons given above (it often makes things less intuitive: WYSIWYG but not 'WYSIWYE', 'what you see is what you've entered') it is disabled when the script detects a wilcard so I guess by wilcard autoAppend you meant wilcard autosuggest ;) :?:

On a side note, I implemented an attach option. It is available at this time only in the attach branch. It endows with word completion feature an existing - multiline - edit control (classNN EditX). All options including the onEvent one remain available, and the behaviour is alike in all respects to the class form the master branch.
Attachments
eAutocomplete-attach.PNG
eAutocomplete-attach.PNG (7.3 KiB) Viewed 1029 times
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Custom word completion for edit controls

20 May 2018, 00:21

A_AhkUser wrote:As for the wilcard autoAppend option, and for the reasons given above (it often makes things less intuitive: WYSIWYG but not 'WYSIWYE', 'what you see is what you've entered') it is disabled when the script detects a wilcard so I guess by wilcard autoAppend you meant wilcard autosuggest ;) :?:


Yea,i was just trying to use your words from the post above,lest i be confusing.
And when i tested it with something like, 'd*op' it does autosuggest and autocomplete 'develop'.

And regarding 'Tab' selection, i kinda meant the 'Colloquial Tab-Completion', if your using QWERTY like me, the arrow keys are impractical when typing unless for the occasional convoluted word that you have to select via arrow. So my suggestion was 'Tab' autocompletes top most suggestion,similar to how any IDE,sublime,scite,notepad++ or 'Typing-Aid' do it, because now it's Tab/Shift+Tab>RightArrow>Space, 3Key presses. I Suggest 'Tab' not only autocomplete but also add a space so it's one key deal.

Sorry if pestered on this,i'm one of those neurotics when it comes to my keyboard... :facepalm:

The penguins say, à la prochaine fois, their french is no better than their ability to fly tho :lolno: .
Outsourcing Clicks & Presses Since 2004.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: Custom word completion for edit controls

20 May 2018, 18:40

@brutus_skywalker
Haha I see - sorry for the confusion. :crazy:
To be honest, personally, I'm not really wanting to use it a lot so I apologize for my lack of common sense when it comes to make it the more ergonomic as possible. In that respect, your suggestions are not only welcolme but also valuable: 'Outsourcing Clicks & Presses Since 2004.' - I couldn't ask for much :D

The tab key
Tab selects - if need be - the top most suggestion. If need be - is that, if the autoAppend option is enabled, the top most suggestion is automatically selected.
Otherwise, the tab key sends (i.e. actually autocompletes adding a space character) the selected item. Enter does the same work except that it also makes the selection move to the next line at the same time.
In other words, if you're lucky, it's a one Tab (or Enter) deal, and two with regular expressions.
Naturally, both the Up and Down arrows keys are still available for convoluted words, that you have to select via arrow.

In the same vein, the regex symbol is henceforth customizable via the regExSymbol option - so that you can choose the one better suited to 'outsource press' ;)

The script is now compatible with single-line edit controls (edit controls that lack the ES_MULTILINE style). Moreover, the attach method is fully available.
In other words, the script is now compatible with virtually all - ahk hard-coded or not - edit controls of the class NN Edit (in fact, it was as simple as define a toogle in the function handling the edit control's events...).

On a side note, the script should rather now use the create base method (which interfaces the __New one) instead of the new keyword to create a instance of eAutocomplete and should rather ensure to dispose the instance using the dispose method, at the latest at the time the script exits (in order to removes the event hook function created by the internal call of SetWinEventHook). The repository includes amended examples.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Custom word completion for edit controls

21 May 2018, 00:18

Merci Monsieur. :salute:
Outsourcing Clicks & Presses Since 2004.
iPhilip
Posts: 287
Joined: 02 Oct 2013, 12:21

Re: Custom word completion for edit controls

21 May 2018, 18:52

Hi A_AhkUser,

Thank you for this interesting script. I want you to be aware that the englishWordList.txt file is missing from the archive master.

Cheers!
P.S.: I see that it automatically downloads when running example.ahk, which I didn't notice until after I ran example_attach.ahk.
P.P.S.: I see that example_attach.ahk requires the user to select the word list file. You might want to add that to your instructions in the OP.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: Custom word completion for edit controls

23 May 2018, 20:38

Hi iPhilip,

You're right... it is not so obvious :facepalm: I'm sorry. I amended the OP and added a basic TrayTip in the auto-execute part of the script to invite the user to first select a word list. Thanks much for the suggestion, much appreciated.

Best regards.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: [Class] eAutocomplete - Custom word completion for edit controls

26 May 2018, 01:48

- Performance has been dramatically improved: the class doesn't relies anymore on ControlSetText; word completion in the midst of a huge string is henceforth nearly instantaneous and therefore more reliable. As a nice side-effect, this also prevents the edit control from automatically scrolling up upon autocompletion if the first visible line is not the very first one.
- The dispose method destroys the instance's menu. It is also automatically called the moment the host GUI/window is destroyed.
- Item in the word completion source shoud not have to be words anymore - that is, they can contain in-between space characters. However, since the script has no way to know when it should see either a word or a group of word as an hapax legomenon, only words are appended, if need be, to a given source.
- Create and attach methods have been harmonised; while the first one requires a window's hWnd the second requires henceforth only an edit's hwnd (thanks to jeeswg for sharing its knowledge).
- A class validator has been implemented to prevent the attach method from attaching a control other than an edit control.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: [Class] eAutocomplete - Custom word completion for edit controls

28 May 2018, 01:49

eAutocomplete v1.0.10
Download link

    . Fixed unwanted scroll up upon a backspace key press if the first visible line of the edit control is not the very first one.
    . The drop-down list is henceforth shown/hidden when the host edit control's gots/losts the focus, respectively. It is also a fortiori hidden when the host GUI is closed.
    . Fixed incorrect suggestions when using a space or a tab (why not) as field separator.
    . The script now remove any trailing ?!,;.:(){}[]'""<> before actually appending an hapax legomenon (first onset of a word) to the current 'word' list.

Unlike previous erratic commits to the master branch, this release will remain as it is and can be consider as a standard version. The readme documents this version.
On a side note, one can now found verbose commentary alongside the source.
Let me know about any bugs or suggestions you may have. ;)
Helgef
Posts: 3094
Joined: 17 Jul 2016, 01:02
Contact:

Re: [Class] eAutocomplete - Custom word completion for edit controls

03 Jun 2018, 13:11

Smooth and fast, excellent job :thumbup: :dance:.

Thanks for sharing, cheers.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: [Class] eAutocomplete - Custom word completion for edit controls

06 Jun 2018, 23:45

eAutocomplete v1.0.21


    [v1.0.20+]
    . Each instance comes with a new read-only property: focused, which speaks for itself.
    . The class was further reworked to properly handle instances sharing the same process and/or the same parent (less for real use cases than as a guarantee of the integrity of each instance).
    . If the source's list is a file, its content is overwritten by the updated list only at the time the setSource or the dispose method is called, which is way more efficient. Calling dispose now also ensures that new occurrences are added to the source's list.
    [v1.0.21+]
    . Added the content read-only property (the edit control's contents). Its value should be in any case the same as the one retrieved by ControlGetText. It has been made available since it is already used and available at any time, internally.
    . Added learnAt option. It specify how many times a word should be typed before being actually stored by the script.
    . The appendHapax toggle option is henceforth meaningful as integer and specify the minimum number of characters the first onset of a word must contain to be appended to the current source's list.
    . Improved handling of rapid key sequences, including when a given input can match a dozen thousand items.

Helgef wrote:Smooth and fast, excellent job :thumbup: :dance:.
Thanks for sharing, cheers.


Thanks to you, Helgef, your feedback is, as always, much appreciated ;)
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: [Class] eAutocomplete - Custom word completion for edit controls

25 Jun 2018, 02:02

v1.1.00

Full rewrite (first attempt to write the class as an object-oriented class).
Please check out the readme for an overview of the new interface.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot] and 16 guests