PythonEditor icon indicating copy to clipboard operation
PythonEditor copied to clipboard

Code hinter causes incorrect entry

Open PropGit opened this issue 6 years ago • 6 comments

This case found when typing in a variables.py example.

Up to here, all entries and behavior is fine (note cursor position and code hint): image

And here, one ")" character later, still fine (though I don't see how try/except is a good suggestion) image

But then upon hitting enter key, that "a)" is replaced with the hinted block - not at all what user expects at that moment. image

PropGit avatar Apr 18 '19 23:04 PropGit

Of course, typing other characters, like a space, gets rid of the code hint and then enter key is fine, but that's not a natural action at the end of a line.

PropGit avatar Apr 18 '19 23:04 PropGit

Here's another example,

When typing in this code:

from microbit import *

k = 5

def add_k(value): value = value + k return value

display.scroll(add_k(3))

What naturally happens is this code is entered (accidental hinted replacements in bold):

from microbit import *

k = pin5.read_digital

def add_k(value): value = value + add_k return value

display.scroll(add_k(3))

The user can avoid the hinted replacements by clicking the mouse somewhere (even on the same spot), pressing ESC, pressing spacebar, or typing some other printable character, but ENTER (the natural key to press at the end of a line) automatically selects the currently highlighted item in the code hint list.

Can it be made to only select the highlighted code hint item if the user 1) clicks on an item with the mouse, 2) actually moves the highlight with the up/down arrow keys then presses enter, or 3) presses tab? The last one is still a bit of a nuisance if someone intended to tab out from the end of the code to a spot where they want to add a right-justified comment, but hopefully they are looking at the screen at that point and see what actually happens and will learn from it. As common users (students) are typing in code, the are often looking away from the screen at the code they are dutifully typing in, causes some of these auto-replacements to happen unknowingly.

It's also be wonderful if an ESC key press immediately after an auto-replacement undoes the auto-replacement as the current requirement is Ctrl+Z or manual retype.

PropGit avatar Apr 19 '19 12:04 PropGit

We've reworked the autocompletion in the v2.0.0-beta.1 version of the editor: https://python.microbit.org/v/beta

You can enable/disable autocomplete on pressing the enter key, and it no longer suggest the snippets (as they have descriptions that use a lot of common words, these suggestions were out-of-place).

Could you give this a go and let us know what you think?

microbit-carlos avatar Jul 23 '19 16:07 microbit-carlos

Thanks @microbit-carlos

Certainly the first post's issue has been solved by this. Thanks!

The third post's issues still occur. For example, defining any symbol to be equal to a value of anywhere from 0 through 20 (except for 17 & 18) brings up the suggestion list with the first item selected. Pressing Enter selects that choice, but that's not what was intended by the user.

k = 10ENTER becomes k = pin10.read_analog

You can enable/disable autocomplete on pressing the enter key

I'm not sure what you mean by that. It seems the enter key always enables (chooses) the selected option when I try it.

Possible Solution

I've noticed that the first item in the suggested list is selected by default whenever there is any kind of match at all.

Perhaps an approach similar to Google Chrome is acceptable? When typing in the URL field, the autosuggestion list includes what was just typed as the first item (which is automatically selected/highlighted) so that an enter key press selects that (often what the user intended upon pressing enter) or a cursor down/up or mouseover allows selection of other matching items that differ further from exactly what was typed.

Here I typed in "problem solving" in Chrome's URL field and the first item in the drop-down list is highlighted and is exactly what I've typed, each character of the way through the typing.

image

An alternative would be for the selection list to appear as it does now, but with no items selected by default, and requiring the user to cursor down/up or mouse click to select what they want. It'd still be the same user inputs (enter keeps what they just typed, cursor down + enter or mouse-click selects a suggestion and replaces their typed in word with it) but it'd take one less line on-screen. This seems nicer to me, but may be more difficult to implement; 1) maybe the control you're using can't have 0 items selected, and 2) once something is highlighted, to unhighlight again may be impossible unless the control allows cursor-up beyond the top item in the list.

PropGit avatar Jul 23 '19 18:07 PropGit

You can enable/disable autocomplete on pressing the enter key

I'm not sure what you mean by that. It seems the enter key always enables (chooses) the selected option when I try it.

The "On Enter" option enables or disables this behaviour:

image

Right now is enabled by default, but based on your feedback and the good examples you've provided, we will changed that to be disabled by default (but still available as a setting in the beta editor).

To change the way the autocomplete matching is computed would requite modifying core parts of the ACE editor, and right now we are using the default autocomplete implementation and changing available settings. So for the time being we are probably not going to be able to edit that feature much, but I am hoping that triggering only with the tab key will improve this issue.

microbit-carlos avatar Sep 06 '19 17:09 microbit-carlos

That sounds good... only with Tab key by default... that should get rid of all the cases I pointed out. Thank you!

PropGit avatar Sep 06 '19 18:09 PropGit