-
Notifications
You must be signed in to change notification settings - Fork 537
Fixes 0814 3 #1348
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
Fixes 0814 3 #1348
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -203,6 +203,32 @@ export function ChatInput( | |||||
| } | ||||||
| }, [chatInputRef]); | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| const editor = editorRef.current?.editor; | ||||||
| if (editor) { | ||||||
| // override TipTap's Enter behavior completely | ||||||
| editor.setOptions({ | ||||||
| editorProps: { | ||||||
| ...editor.options.editorProps, | ||||||
| handleKeyDown: (view, event) => { | ||||||
| if (event.key === "Enter" && !event.shiftKey) { | ||||||
| const isEmpty = view.state.doc.textContent.trim() === ""; | ||||||
| if (isEmpty) { | ||||||
| return true; | ||||||
| } | ||||||
| if (inputValue.trim()) { | ||||||
| event.preventDefault(); | ||||||
| handleSubmit(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stop propagation in the TipTap handleKeyDown handler before submitting to avoid duplicate Enter handling with the DOM keydown listener (which also triggers submit) Prompt for AI agents
Suggested change
|
||||||
| return true; | ||||||
| } | ||||||
| } | ||||||
| return false; | ||||||
| }, | ||||||
| }, | ||||||
| }); | ||||||
| } | ||||||
| }, [editorRef.current?.editor, inputValue, handleSubmit]); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid re-applying editor.setOptions on every keystroke; remove inputValue from the effect dependencies or use a ref to access the latest value inside the handler Prompt for AI agents |
||||||
|
|
||||||
|
Comment on lines
+206
to
+231
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enter is handled twice (ProseMirror handler + DOM listener) — risk of double submission You now override TipTap’s handleKeyDown and still attach a DOM keydown listener below. Both intercept Enter and call handleSubmit, causing duplicate sends. Also, the PM handler doesn’t stop propagation; and the effect resets editor options on every keystroke via inputValue dependency.
Apply this diff to the PM handler to stop propagation: if (isEmpty) {
- return true;
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
}
if (inputValue.trim()) {
event.preventDefault();
+ event.stopPropagation();
handleSubmit();
return true;
}And update the DOM keydown handler to skip when already handled (see the next comment’s diff). Optional (outside the selected lines): use a ref to avoid re-calling setOptions on every inputValue change. // outside: before effects
const inputValueRef = useRef(inputValue);
useEffect(() => { inputValueRef.current = inputValue; }, [inputValue]);
// inside PM handler, replace inputValue.trim() with:
if (inputValueRef.current.trim()) { ... }
// and make the setOptions effect depend only on editorRef.current?.editor🤖 Prompt for AI Agents |
||||||
| useEffect(() => { | ||||||
| const editor = editorRef.current?.editor; | ||||||
| if (editor) { | ||||||
|
|
@@ -264,7 +290,7 @@ export function ChatInput( | |||||
| .chat-editor .tiptap-normal { | ||||||
| padding: 12px 40px 12px 12px !important; | ||||||
| min-height: 50px !important; | ||||||
| max-height: 80px!important; | ||||||
| max-height: 90px !important; | ||||||
| font-size: 14px !important; | ||||||
| line-height: 1.5 !important; | ||||||
| } | ||||||
|
|
||||||
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.
Directly overriding a third-party library's core behavior (
TipTapeditor'shandleKeyDownviaeditorProps) can lead to brittle and unmaintainable code. This approach tightly couples the component toTipTap's internal implementation details, making future upgrades and bug fixes challenging. It circumventsTipTap's intended extension mechanisms and can introduce unexpected side effects or breakages when the library updates. A more robust solution would be to use TipTap's official extension API or event listeners, if available, for custom key handling.Prompt for AI agents