-
Notifications
You must be signed in to change notification settings - Fork 109
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
Keypress event (conditional) trigger #81
Conversation
@@ -694,6 +698,7 @@ class JQConsole | |||
# (e.g. ">>> "), and the editable text to the left and right of the cursor. | |||
@$prompt_label = $(EMPTY_SPAN).appendTo @$prompt_current | |||
@$prompt_left = $(EMPTY_SPAN).appendTo @$prompt_current | |||
@$prompt_left.attr 'class', CLASS_USER_TEXT |
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.
what is this for?
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 for identifying the part of the prompt that is changed by the user. This was useful for implementing highlighting (with highlight.js) but maybe there are other way that I am not considering (not js expert here 😄)
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.
Oh we use GetPromptText
great!
Looks good. Can you add an example usage? Would be great to add the documentation too. |
Where do you want me to add the usage? In the |
Read me and an example usage would be great! On Saturday, November 7, 2015, Andrea Richiardi notifications@github.com
|
2c9adfa
to
b0e4b81
Compare
Ok done, have a look in |
b0e4b81
to
4a80c8e
Compare
That's very cool. Thank you. Will do a release soon after I fix #80 |
Keypress event (conditional) trigger
👍 thanks, as before I would like to push a release in |
I'd like to simplify this a little bit. Instead of having two different handlers, let's make it a single step. The user gets to execute the handler before the internal handler with no auxiliary events needed. So the example would be.
|
I'll send a PR and let me know what you think |
Ok, I put two because one gives the "pace" of the triggering (I don't won't to trigger every keypress for instance), the other handles. |
Based on @arichiardi's work in #81. This introduces a way to set custom key handlers: * key press handler: concerned with text input * control key handler: concerned with other key handler The handlers can return false to prevent jqconsole from handling the event.
see #82 gives us the full potential for auto-complete and other user-defined behavior |
This is an implementation of the key press trigger.
It is conditional because if you push a function(current_text, new_char) with
SetKeyPressPredicate
and your function returns false (default), no event is triggered. This is done cause you might want to add logic, say, if the last word of thecurrent text + new_char
is a keyword then trigger, you can achieve it here.It works quite nicely here 👍
Please let me know if I have been too prolific with the function names 😄