-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Allow toggling CTRL+Enter vs Enter to send ChatAreaInput #6592
Conversation
Thanks! That looks right to me; I'd recommend creating a new env for Panel dev. Also, clearing browser console. https://panel.holoviz.org/developer_guide/index.html#installing-the-project Lastly, I'm hesitant on a three word keyword, maybe |
panel/models/chatarea_input.ts
Outdated
@@ -45,7 +52,8 @@ export class ChatAreaInputView extends PnTextAreaInputView { | |||
export namespace ChatAreaInput { | |||
export type Attrs = p.AttrsOf<Props> | |||
export type Props = PnTextAreaInput.Props & { | |||
disabled_enter: p.Property<boolean> | |||
disabled_enter: p.Property<boolean>, | |||
shift_enter_sends: p.Property<boolean>, |
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.
This needs to be updated to enter_sends too
panel/models/chatarea_input.ts
Outdated
@@ -65,6 +73,7 @@ export class ChatAreaInput extends PnTextAreaInput { | |||
this.define<ChatAreaInput.Props>(({Bool}) => { | |||
return { | |||
disabled_enter: [ Bool, false ], | |||
shift_enter_sends: [ Bool, false ], |
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.
This too.
changed the parameter name to enter_sends, and added the notebook - will need some changes eventually
|
@@ -60,7 +61,7 @@ | |||
"source": [ | |||
"#### Basics\n", | |||
"\n", | |||
"To submit a message, press the Enter key." | |||
"To submit a message, press the Enter key if **``shift_enter_sends``** is False, else press Shift-Enter." |
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.
"To submit a message, press the Enter key if **``shift_enter_sends``** is False, else press Shift-Enter." | |
"To submit a message, press the Enter key if **``enter_sends``** is True, else press Shift-Enter." |
panel/chat/input.py
Outdated
|
||
enter_sends = param.Boolean( | ||
default=True, | ||
doc="If False, the shift_enter key will send the message rather than the enter key.", |
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.
doc="If False, the shift_enter key will send the message rather than the enter key.", | |
doc="If True, pressing the Enter key will send the message; if False, Shift+Enter will send the message.", |
panel/chat/input.py
Outdated
@@ -44,7 +44,12 @@ class ChatAreaInput(_PnTextAreaInput): | |||
|
|||
disabled_enter = param.Boolean( | |||
default=False, | |||
doc="If True, the enter key will not submit the message (clear the value).", | |||
doc="If True, disables sending the message by pressing the enter or the shift_enter key (clear the value).", |
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.
doc="If True, disables sending the message by pressing the enter or the shift_enter key (clear the value).", | |
doc="If True, disables sending the message by pressing the Enter or Shift+Enter key (clear the value).", |
If something is not working properly, I'd also check: |
panel/models/chatarea_input.ts
Outdated
console.log( "DBG: keydown event", event.key ) | ||
if (event.key === "Enter" && ( (!event.shiftKey && this.model.enter_sends) | ||
|| ( event.shiftKey && !this.model.enter_sends)) | ||
) { | ||
console.log( ". enter_sends: ", event.shiftKey && !this.model.enter_sends ) |
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.
Maybe if you swap it?
console.log( "DBG: keydown event", event.key ) | |
if (event.key === "Enter" && ( (!event.shiftKey && this.model.enter_sends) | |
|| ( event.shiftKey && !this.model.enter_sends)) | |
) { | |
console.log( ". enter_sends: ", event.shiftKey && !this.model.enter_sends ) | |
if (event.key === "Enter" && ( | |
(event.shiftKey && !this.model.enter_sends) || | |
(!event.shiftKey && this.model.enter_sends) | |
)) { | |
if (!this.model.disabled_enter) { | |
console.log(". . FIRE: ", this.model.value_input) | |
this.model.trigger_event(new ChatMessageEvent(this.model.value_input)) | |
this.model.value_input = "" | |
} | |
event.preventDefault() | |
} | |
}) |
panel/models/chatarea_input.ts
Outdated
if (event.key === "Enter" && ( (!event.shiftKey && this.model.enter_sends) | ||
|| ( event.shiftKey && !this.model.enter_sends)) |
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.
As a suggestion, this xor can be written more concisely as:
if (event.key === "Enter" && ( (!event.shiftKey && this.model.enter_sends) | |
|| ( event.shiftKey && !this.model.enter_sends)) | |
if (event.key === "Enter" && event.shiftKey != this.model.enter_sends) |
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.
Hmm, nice! It will need a comment though: I had to really stare at it
to figure out what it does :-)
Shift-Enter appears bound to rerun the current cell in the notebook. I was able to make this work with Ctrl-Enter instead. |
Hmm let's keep shift enter with the hope that this is fixed: #6394 |
Shift vs Ctrl Enter: Right now, Ctrl does work, and would be consistent with the I would like to make one more edit to the Jupyter notebook though: |
Are you able to press shift+enter to start new lines? Also try working outside of the notebook (call .show() on the obj in the notebook) Try the suggestion from #6592 (comment) |
|
@ahuang11 anything I need to do here? |
Sorry, I'll get to this today! No need to keep updating the branch. |
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 really nice! Just wording clean up and I believe we can merge after if all tests passes!
I recommend using Add suggestion to batch functionality to commit if you agree with the changes.
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
(Encourage you to use the Add suggestion to batch or else it triggers many many commits) |
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
unfortunately add suggestions to batch was greyed out?! |
Usually have to do it in Files changed tab. I suppose I could've mentioned that. |
Great thank you for adding this! |
current state with console.log statements....