-
Notifications
You must be signed in to change notification settings - Fork 19
Add instant and prefix-based completion (#36) #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I realize the way I implemented it is a bit too greedy. When a name is complete (eg Note for performance: the original feature I saw enters a special mode when typing a backslash; the characters that follow are underlined and the substitution is only active during that time. If you click away then it stops and the backslash will no longer be substituted without an explicit command. This might be a better approach for the greedy completer. |
Coming back to this now, I finally managed to make it behave as I want it to. It's starting to be quite a big change though. Since I made replacement logic more complex, I factored out In the end I think the most natural setting is to have Just to be clear, instant conversion kicks in when:
The whole point is to get as close as possible to some "LaTeX effect" where there is zero control keystroke. If I close my eyes and type The prefix idea is so that I can close my eyes, type This isn't finished (still need to tackle the sorting thing), but any feedback on the current code is welcome. |
For the performance problem, I wanted to use an ordered map so we could have a single data structure to replace the dictionary, but I couldn't easily find one in the standard library (?!). I elected to keep both the dictionary and the sorted version, which I wrapped along with the inverse in a utility class. I'm open to suggestions on how to handle this. I don't have any more planned changes on this branch for now, so another review would be welcome. I noticed an exception on "Convert Back", but it seems to occur on the current master as well, so I guess that's orthogonal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for comments in code; I need a bit more time to review unicodecomplete.py
All valid points, thanks! I'll remember to squash everything when we're done. |
return True | ||
|
||
# In instant mode, accept symbols when followed by an invalid character. | ||
# For instance, when typing "x" in "\alphax", recognize that "\alpha" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks a bit hacky, but maybe it's ok.
If we type 'x' after '\alpha' - it will convert '\alpha'
Will it convert if we paste 'x' after '\alpha' with Ctrl+V? Looks like it will
But it won't - if we paste 'xyz' after '\alpha', because prefix will be '\alphaxy' (without last 'z')
It is expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the intended behavior, though we could discuss how satisfying it is. Ideally you'd want to behave as if all characters were typed in sequence, but testing that doesn't seem too straightforward and I'm afraid of (1) performance issues, as pasting tens of thousands of characters is quite common, and (2) unduly substituting stuff that should've been left verbatim when pasting chunks of code. I think it's fair to have a typing-oriented input mode rather than a text-oriented input mode for instant mode since it is interactive by design.
Thanks for the review. Let me know when I can squash the branch. Also, I'm thinking the feature would be rather obscure without some proper documentation. Would a section in the README file be fine with you? |
Looks good to me to squash
It'll be nice to have readme section about new feature |
Oops, not sure how and when this flew off my radar. Sorry! I added the README section and squashed the branch (no other changes today). I've been using this mode for a while now, had to disable some of the conversions (such as |
Thanks, merged! |
This PR implements a rough version of the features proposed in the linked issue.
symbol_by_unique_prefix()
function inmathsymbols.py
. The function only searches for 2 matching prefixes, and is used both incan_replace()
and the replacement function.on_modified()
and that doesn't allow me to disable conversion during undos; the commented view-listener version would just run instantly after undoing a conversion and redo it again.Not sure if this is fine to merge yet (I'm a bit worried about the text change listener), but at least it's out there. 😄