Skip to content

Commit c868ce8

Browse files
implemetned hasText state with update handler to check if editor has content more robustly
1 parent f55a7f1 commit c868ce8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Diff for: gui/src/components/mainInput/InputToolbar.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ function InputToolbar(props: InputToolbarProps) {
225225
}}
226226
disabled={isEnterDisabled}
227227
>
228-
<div data-tooltip-id="submit-tooltip">
228+
<span data-tooltip-id="submit-tooltip">
229229
<PaperAirplaneIcon
230230
className={`h-4 w-4 ${
231231
props.hasText
232232
? "text-[var(--vscode-editorForeground)]"
233233
: "text-[var(--vscode-descriptionForeground)]"
234234
} transition duration-150 ease-in-out`}
235235
/>
236-
</div>
236+
</span>
237237
<ToolTip id="submit-tooltip" place="top-middle">
238238
Send (Enter)
239239
</ToolTip>

Diff for: gui/src/components/mainInput/TipTapEditor.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,21 @@ function TipTapEditor(props: TipTapEditorProps) {
551551
editable: !isStreaming || props.isMainInput,
552552
});
553553

554+
const [hasText, setHasText] = useState(false);
555+
useEffect(() => {
556+
if (!editor) return;
557+
// Check if the editor has text
558+
const updateEditorHandler = () => {
559+
const text = editor.getText().trim();
560+
setHasText(text.length > 0);
561+
};
562+
editor.on("update", updateEditorHandler);
563+
updateEditorHandler();
564+
return () => {
565+
editor.off("update", updateEditorHandler);
566+
};
567+
}, [editor]);
568+
554569
const [shouldHideToolbar, setShouldHideToolbar] = useState(false);
555570
const debouncedShouldHideToolbar = debounce((value) => {
556571
setShouldHideToolbar(value);
@@ -1015,7 +1030,7 @@ function TipTapEditor(props: TipTapEditorProps) {
10151030
});
10161031
}}
10171032
disabled={isStreaming}
1018-
hasText={editor ? editor.getText().trim().length > 0 : false}
1033+
hasText={hasText}
10191034
/>
10201035
</div>
10211036

0 commit comments

Comments
 (0)