Autocompletion

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9645
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Autocompletion

Post by dunbarx » Tue Aug 31, 2021 12:01 am

All of a sudden, I realize that losing the space within multi-word items is a dead end.

Not sure now how to autoComplete, after entering a short string of chars, to distinguish between, say, "LiveCode Builder" and "LIveCode Script".

There is no way to "know", as the user is typing, at least in the early part, which one is intended. A kludge {pseudo)

Code: Select all

on textChanged
 find all instances currently in the source text
 if more than one match is found change the number of chars required from 3 to the longest first word of the found instances + 2
continue to run "normally" with the new longer value until a unique string in the source is identified
return that one
This is doable, and straightforward. But is it worth it?

Craig

golife
Posts: 103
Joined: Fri Apr 02, 2010 12:10 pm

Re: Autocompletion

Post by golife » Tue Aug 31, 2021 4:22 pm

@dunbarx
-- Reference: autoComplete.livecode.zip

Nice stack. But as you know: try to use backspace. It will not allow you to delete unless selecting and deleting since it will autocomplete all the time.

My idea here would be to present more than one choice.
How to select the chosen one?
Maybe using arrow keys and hitting Enter? Clicking with the mouse..?

A newly entered term share the same first 4-n characters and then be different, even be completely new. You are also giving an idea how to construct the logic which I adjust a bit:

When the user types, only this one phrase is taken into account.
All other phrases entered must have been converted to "tag objects" and are not touched any longer.
(I group each phrase and let it appear as a "tag" object.)

I think, without such a list from which to chose it is impossible to solve autocomplete in a user-friendly way.

The list to chose from shall be "at the fingertips", and it must be very easy to select from it.

Code: Select all

on keydown k -- not "closeField"
// Pseudo code
  find all instances currently in the word/phrase typed > 3 chars
  -- no already defined phrases are in the source text, only the one the user types
    Filter the tag list with for one to n phrases that match the typed string
    Present the filter result in a list field near the selection. 
    The filter list is non obstructive and moves with the cursor (look for edge cases to the right, left, top, bottom)
    At any time the user can make a choice using ENTER or continue typing...
    If a choice is made the tag is identified and completed and taken away from the source text.
    If no choice is made, a new tag is created with ENTER
   If no choice is made then the typed string will be deleted on closefield
end if
Cheers, Roland

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9645
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Autocompletion

Post by dunbarx » Tue Aug 31, 2021 6:32 pm

But as you know: try to use backspace. It will not allow you to delete unless selecting and deleting since it will autocomplete all the time.
OK, true, but just add this:

Code: Select all

on backSpacekey
   delete the last char of me
end backSpacekey
If you want a pop-up list of options to select, and I think that slows the user down to a greater extent than doing nothing, you can find all instances of a string of chars by any of several methods. For example, you can use the itemOffset function, which has the ability to skip a specified number of items as counted from the beginning. So you can find all items that start with the last chars of the typed string. Then just pop that list into any gadget you like.

Craig

golife
Posts: 103
Joined: Fri Apr 02, 2010 12:10 pm

Re: Autocompletion

Post by golife » Wed Sep 01, 2021 9:24 am

Dear Craig

Thank you. Yes.

Anyway, neither methods are ideal.

If the typed string is autocompleted automatically, we have a problem. In MS Word for example, this can be done, but you must override it using backspace and it will not autocomplete again next time when typing. Not a perfect solution.

Autocomplete would have to be non-destructive and interfering at a minimum. Maybe it is possible to autocomplete but leave the cursor where it is and when the user continues typing then autocomplete adjusts with a new autocompletes. When the user is satisfied the user must either use Enter or close the field in clicking elsewhere.

In code editors I have mostly seen selection lists popping up from where to chose, or continue typing.

Well, this needs some experimentation... I will devote more time to it.

Thanks, Roland

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Autocompletion

Post by richmond62 » Wed Sep 01, 2021 10:44 am

I would try to offer something towards this, but as I have been short-changed by LiveCode I won't.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9645
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Autocompletion

Post by dunbarx » Wed Sep 01, 2021 2:21 pm

Hi.
override it using backspace and it will not autocomplete again next time when typing
My little gadget now supports the backspace key, as I mentioned, with a new "backSpaceKey" handler. If you delete some chars and then continue typing, autoComplete continues to work normally from that point. Did you not try this?

Anyway, the updated stack is attached.
autoComplete.livecode.zip
(1.41 KiB) Downloaded 99 times
As for presenting a list of possible options, this too is simple and straightforward. If you want to go down that path let me know. But I would not do that, presenting such choices only in other user activities, not from the middle of typing into a text field. I do remember seeing that sort of thing, though, and for me, it is just a fun coding exercise.

Craig
Last edited by dunbarx on Thu Sep 02, 2021 5:15 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9645
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Autocompletion

Post by dunbarx » Wed Sep 01, 2021 2:24 pm

@ Richmond.
I would try to offer something towards this, but as I have been short-changed by LiveCode I won't.
Really? Just because something miraculous that was once free no longer is? :roll:

Craig

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Autocompletion

Post by stam » Wed Sep 01, 2021 9:47 pm

dunbarx wrote:
Wed Sep 01, 2021 2:24 pm
Really? Just because something miraculous that was once free no longer is? :roll:
It’s not about the fact that the company have made this a paid - only product after milking opensource backers for as much as it would go.

It’s about how this was done.

Why wasn’t there an advance announcement so that people like @Richmond could manage their businesses that were based on the promise of ongoing support for openSource?

The website and software redesign clearly are extensive and haven’t happened overnight - likely these took months. Yet it was all kept under a tight veil of secrecy. Was there really a serious reason for this?

We can all appreciate the financial realities that face the company must be facing, and understand they have a duty to ensure they don’t go under which means paid only software.

But equally no other community has given back so much financial support in form of donations and even now still doing their marketing for them.

Just one current example: even though the company in its various guises has been cross platform for many years, their excellent marketing team still hadn’t added this to a list of cross platform IDEs on Wikipedia, relying on a user to think of this and do it. (viewtopic.php?f=5&t=36256)

This is the insanity of the situation encapsulated right there. Instead of being mega pro-active in advertising this “miraculous” platform, increasing awareness and trying to bring in more users with deals etc, what they’ve done is basically decided to cannibalise their existing market, yet again asking their loyal users to dish out more $$$ instead of actually making any serious attempt to increase their userbase. When it comes to new users, there seems to be an attitude of “built it and they will come” which just won’t cut it.

Will trying to squeeze loyal users for more cash be enough to keep them afloat?
I truly hope so, because we all love the platforms and would hate to see it go.

To be on the safe side I’m brushing up on Flutter.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”