[Script] AutocompleteEditorText - using text from editor/active-window/last-window

Post your working scripts, libraries and tools
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

[Script] AutocompleteEditorText - using text from editor/active-window/last-window

13 May 2018, 04:16

You know how notepad++ can autocomplete text using other text in the window, this script does exactly the same thing,except across multiple editors or even unsupported windows such as a browser using text from last supported window, NOTE: for the later to work autocompleteAllWindows must be set to true,which is the default.

Configuration Options:
    Trigger Length
    One Press Auto-completion (Toggle) *default:TRUE Enter autocompletes+newline, Tab autocompletes+space
    Process Exclusion
    Window Title Exclusion
    All/Compatible-Only Window Auto-completion (Toggle)
    Case Correction (Toggle)
    Case Ranking of Suggestions (Toggle)
    Remove Punctuation from matches (Toggle) *default: FALSE


Interaction is via Up/Down/Enter/Tab, the later two behaving differently based on configuration,see above.


Merci A_AhkUser for insight,suggestive corrections and great library which motivated me to rewrite my tooltip version, now at the bottom of post.

Let me know about any bugs. :D


Legacy toolTip version in my OP can be found at the bottom.

EDIT: Saturday, May 26, 2018 16:42
    Full Rewrite.

EDIT: Tuesday, May 29, 2018
Added:
    Support for unknown keyboard layouts. Working On It(Experimental).

    A number of configuration options, see above.

    More endkeys; Left,Right,LButton,RButton

    A lot of little things under the hood....

Fixed:
    Use ByRef where necessary for performance. Thx @A_AhkUser for pointing it out.

EDIT: Wednesday, May 30, 2018
Fixed: Issues with #If not properly working, it was a conflict with another script on my end.

EDIT: Thursday, May 31, 2018
Fixed: ListBox error message.
Fixed: ListBox flickering on window change.

EDIT: Saturday, June 02, 2018
Just added version information, and optimised some of the logic.


Edit: Monday, June 04, 2018
v1.1
Added: sanityCheck to ensure script behaviour is as predictable as possible.
Fixed: ListBox being generated beyond the edges of the screen when typing at the edges of the display.
Fixed: Endkey backspace hotkey thread no longer interrupted, ensures backspace works as expected.
Fixed: Listbox hotkey threads no longer interrupted, ensures Tab/Enter work as expected.
Added: A few more endkeys to cover more use cases,such as Numpad Arrows.



Code: [Select all] [Expand] [Download] (AutocompleteEditorText -ListBox-.ahk)GeSHi © Codebox Plus






Below are the components that comprise the above script, i'm posting them such that others may have an easier start in similar scripts or just code to cannibalise if you so wish...cheers.
Spoiler





Legacy Tooltip version, in my OP is also down here for any one who might want it,as it's less intrusive being a tooltip and all. I Run both personally, i run the tooltip version on all my Virtual Machines,as it works across the board with no hiccups.

Based on variations on THIS post of rajat's Intellisense script modifications.

; DOUBLE Press 1 to 0 keys to autocomplete the word upon suggestion
; (0 will match suggestion 10)


Code: [Select all] [Expand] [Download] (AutocompleteEditorText -ToolTip-.ahk)GeSHi © Codebox Plus

Last edited by brutus_skywalker on 13 Jun 2018, 09:29, edited 20 times in total.
Outsourcing Clicks & Presses Since 2004.
LarryC
Posts: 22
Joined: 30 Sep 2013, 12:14

Re: AutocompleteEditorText - using text in editor

13 May 2018, 13:13

I read this twice but still cannot find how to insert an offered word other than a statement saying to press the corresponding number key. Didn't work, but does work if double pressed the corresponding number.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: AutocompleteEditorText - using text in editor

13 May 2018, 23:40

LarryC wrote:I read this twice but still cannot find how to insert an offered word other than a statement saying to press the corresponding number key. Didn't work, but does work if double pressed the corresponding number.


YUP. That was bad instruction on my part. Fixed it. Double Press Number Keys.
Outsourcing Clicks & Presses Since 2004.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: AutocompleteEditorText - using text in editor

21 May 2018, 13:56

brutus_skywalker wrote:^If AnyOne can make a listview alternative to this method of selection,by all means...HELP :headwall: ...


A owned GUI endowed with the WS_EX_CLICKTHROUGH (or WS_EX_NOACTIVATE) extended style, and shown using the NA option is functionally equivalent in many respects to a tooltip:

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

brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: AutocompleteEditorText - using text in editor

22 May 2018, 05:03

@A_AhkUser


Thanks much,a hell of a nudge in the right direction,appreciate it. Just the example I needed to wrap my head round it. ;)
Outsourcing Clicks & Presses Since 2004.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: AutocompleteEditorText - using text in editor

22 May 2018, 18:06

@A_AhkUser


So i more or less get list boxes now,i never got them because i never really tried,it seems...

However i don't care to reinvent the wheel, so i used your library and the attach example as a starting point for a new version below, and it does not seem to want to work with anything but an edit1 control and downright goes crazy with scintilla controls, care to enlighten me as to what i'm doing wrong. Works brilliantly with edit1 controls though.

Code: [Select all] [Expand] [Download] (AutocompleteEditorText (eAutocomplete).ahk)GeSHi © Codebox Plus

Last edited by brutus_skywalker on 25 May 2018, 03:12, edited 1 time in total.
Outsourcing Clicks & Presses Since 2004.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: AutocompleteEditorText - using text in editor

23 May 2018, 21:03

brutus_skywalker wrote:However i don't care to reinvent the wheel, so i used your library and the attach example as a starting point for a new version below, and it does not seem to want to work with anything but an edit1 control and downright goes crazy with scintilla controls, care to enlighten me as to what i'm doing wrong. Works brilliantly with edit1 controls though.


I'm glad you give a chance to the library... but is intended to work only with edit control... - hence the 'e' in eAutocomplete. The class internally relies, among other things, on messages (to set/retrieve the selection in the control, for example) which are specific to edit/richedit controls; hence it goes crazy with - the very specific - scintilla control (btw your code has the virtue to implicitly points out that the class probably needs a control class validator before even a 'control class dispatcher' like the one in your winChanged subroutine). Practically, it means the class will work on paper with both edit and combobox controls, since these latter have an embedded (child) edit control - on paper: I didn't test with combobox controls (btw, in this case it might be more relevant, depending on goals, to use cbAutocomplete by Pulover). Simply, I had not originally take into consideration other kind of control and the script reflects it by its limitations.
That's also the reason why I posted with true peace of mind the eAutocomplete class a few hours after your autocomplete script: to some extent, they share the same goals but yours has the undeniable and specific advantage to work with other kind of controls.

However, I really like how you make the best of the class by attaching dynamically compatible controls and, more specifically, the idea to dynamically set the source depending on the active window. This could actually be tremendously useful when using multiple keyboard layouts and/or various registers of language depending on the active application/web page. This is very interesting. In any event, it makes me want to have a support for other kind of controls. It might be at least possible to add - even in the form of a new library - a full support for richedit control (e.g. word) and textarea html element (in an embedded browser). I shall take it into consideration.

On a side note, note that:

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

A := eAutocomplete.attach(WinExist(), eHwnd)

does not implictly remove the event hook function nor dispose the previous instance since each instance set circular references; alternatively, you might consider to dispose the previous instance before anew calling the attach method in order to update the host edit control.

Thanks for sharing this implementation, really, much appreciated.

P.S.: To which application(s) TConTEXTSynEdit1 belongs?
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: AutocompleteEditorText - using text in editor

25 May 2018, 00:34

A_AhkUser wrote:... but is intended to work only with edit control... - hence the 'e' in eAutocomplete.


Yeah, i thought as much, and i eventually tried cbAutocomplete by pullover, but it was a bit drab and unflattering for an autocomplete interface, so i'm writing a 'Pseudo-Micro-Framework' with verbose commentary for listboxes intended for text selection and as a starting point for anyone else dabling with list boxes,which i am also going to use for a listbox suggestion variant to 'AutoCompleteEditorText'.

A_AhkUser wrote:..btw your code has the virtue to implicitly points out that the class probably needs a control class validator before even a 'control class dispatcher' like the one in your winChanged subroutine. Practically, it means the class will work on paper with both edit and combobox controls, since these latter have an embedded (child) edit control - on paper:...


Hmm...

A_AhkUser wrote:It might be at least possible to add - even in the form of a new library - a full support for richedit control (e.g. word) and textarea html element (in an embedded browser). I shall take it into consideration.


I hope you do consider it, your library trully is awesome. Maybe even someone else will expand on it,that tends to be the trend in this forum, a very welcome trend...

A_AhkUser wrote:...you might consider to dispose the previous instance before anew calling the attach method in order to update the host edit control.


Aha, i knew i saw a dispose call, on the exit subroutine on your example, i failed to incorporate it, for some reason!

A_AhkUser wrote:P.S.: To which application(s) TConTEXTSynEdit1 belongs?


An obscure editor called ConTEXT, http://www.contexteditor.org/index.php


Thanks A_AhkUser, your insight is most welcome.
Outsourcing Clicks & Presses Since 2004.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: [Script] AutocompleteEditorText - using text from editor/active window [LISTBOX Rewrite]

26 May 2018, 09:03

Updated OP, with listbox variant of my OP. A lot better dare i say....
Outsourcing Clicks & Presses Since 2004.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: [Script] AutocompleteEditorText - using text from editor/active window [LISTBOX Rewrite]

27 May 2018, 23:02

brutus_skywalker wrote:Updated OP, with listbox variant of my OP. A lot better dare i say....

Nice work :bravo:
Works well here (tested on both Notepad and Notepad++ - still have to test it on... ConTEXT though :D ). Erratically, I have some parenthesis or dots in some suggestions (e.g. 'name:').
One question:
  • Is there any reason why you make it (re)create/destroy the GUI instead of simply show/hide it (CreateListBox vs UpdateListBox) ?
If I may, two remarks:
  • The use of ByRef parameters could be relevant for both the WordsStartWithString & AlphaSortList functions:
    Documentation - ByRef parameters wrote:When passing large strings to a function, ByRef enhances performance and conserves memory by avoiding the need to make a copy of the string. Similarly, using ByRef to send a long string back to the caller usually performs better than something like Return HugeString



  • AutocompleteEditorText -ListBox-.ahk wrote:Create transparent Hotkeys for all relevant keys

    I doubt that french people consider é to not being part of relevant keys :terms: :lol: If I type 'été' or 'événement' it fails to actually suggest the given words (but it works well with 'littéraire')... Maybe scancodes could be a workaround here - I saw Exaskryz used something like the following one day:

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

    Loop % 100 ; not sure which number to use here
    Hotkey % "~sc" . a_index, test, On
    return

    test:
    ToolTip % GetKeyName(LTrim(A_ThisHotkey, "~"))
    return

    !i::KeyHistory

    ... so that you hotkeys are less hard-coded and will work for languages like russian (just an idea).

Cheers
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: [Script] AutocompleteEditorText - using text from editor/active window [LISTBOX Rewrite]

29 May 2018, 13:47

A_AhkUser wrote: Erratically, I have some parenthesis or dots in some suggestions (e.g. 'name:').


That was intentional, a great many strings have useful punctuations(Periods,Function(),file names,.), but i added a config option to remove punctuations from results. Default is with punctuations though.

A_AhkUser wrote:....
Is there any reason why you make it (re)create/destroy the GUI instead of simply show/hide it (CreateListBox vs UpdateListBox) ?
...
The use of ByRef parameters could be relevant for both the WordsStartWithString & AlphaSortList functions:
...

I didn't factor in performance,hence forgot ByRef and destroy instead of hide was to do with having issues with the context sensitve hotkeys,which needed to be inactive when the GUI was not active,but i have opted for an alternate method of exposing a hidden gui to the CreateListBox function momentarily to update it,which seems to work just fine. I know i could just use a control variable as in #If WinExist(listBoxTitle) AND !listboxHidden, but for some reason it's not properly working.

Edit: Properly using #If now, issue was on my end.

Corrected Both,


A_AhkUser wrote:
I doubt that french people consider é to not being part of relevant keys :terms: :lol: If I type 'été' or 'événement' it fails to actually suggest the given words (but it works well with 'littéraire')... Maybe scancodes could be a workaround here....

... so that you hotkeys are less hard-coded and will work for languages like russian (just an idea).


Well i just added an additional input capture function,GetInputString, to supplement hotkeys, It' uses the ' Input command, and captures all keys that aren't hotkeys, it seems to work with characters like 'ö,ß,' when i switched to german keyboard and 'ù' when i was on french, though i couldn't test the not so french é which ended up being detected but also input alongside the number two... So test it if you could, and let me know if it works on a native keyboard... And the scan code method seems to be even worse off, example the scan code for z is SC02C, x is SC02D, so looping through numbers will only get you so many characters.

Here's a script to test if a key is detected at all, it uses the same input detection as in my update,so if works here it should work there.Cheers.

And Most definitely thanks for your feedback and input,as always. :wink:

Code: [Select all] [Expand] [Download] (file.ahk)GeSHi © Codebox Plus

Outsourcing Clicks & Presses Since 2004.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: [Script] AutocompleteEditorText - using text from editor/active-window/last-window

31 May 2018, 08:22

Updated to a Fully functional and configurable script, will fix all reported bugs and any i find while i use it, but no additional features planned from here on out,unless you suggest a really good one :think: ...,it's fairly ironed out,been doing that for the past 3days. [b] *Retained all commented-out debug code & verbose commentary for others to best understand the script. :beer:
Outsourcing Clicks & Presses Since 2004.
A_AhkUser
Posts: 840
Joined: 06 Mar 2017, 16:18
Location: France

Re: [Script] AutocompleteEditorText - using text from editor/active window [LISTBOX Rewrite]

03 Jun 2018, 19:26

brutus_skywalker wrote:So test it if you could, and let me know if it works on a native keyboard...


It does work ;) :bravo:

getDifferentialInput:
Spoiler
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: [Script] AutocompleteEditorText - using text from editor/active window [LISTBOX Rewrite]

04 Jun 2018, 10:56

A_AhkUser wrote:
brutus_skywalker wrote:So test it if you could, and let me know if it works on a native keyboard...


It does work ;) :bravo:

getDifferentialInput:
Spoiler



That does help, thanks. I dunno how,but i was deleting a very old post and somehow my last post got deleted instead. I had yet to repost, did it now though.

Helgef wrote:Great stuff, thanks for sharing .

Cheers.


Thanks, check out my last update, fixed a few major issues i missed before.
Outsourcing Clicks & Presses Since 2004.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 23 guests