Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { cancelToolCall } from "../../../../redux/slices/sessionSlice";
import { callToolById } from "../../../../redux/thunks/callToolById";
import { cancelStream } from "../../../../redux/thunks/cancelStream";
import { logToolUsage } from "../../../../redux/util";
import { isJetBrains } from "../../../../util";
import { isJetBrains, isTextInputTarget } from "../../../../util";
import { useMainEditor } from "../../TipTapEditor";
import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar";
import { EditOutcomeToolbar } from "./EditOutcomeToolbar";
Expand Down Expand Up @@ -117,7 +117,7 @@ export function LumpToolbar() {

// Also stop regular streaming if it's happening
if (isStreaming) {
dispatch(cancelStream());
void dispatch(cancelStream());
}
};

Expand All @@ -127,6 +127,9 @@ export function LumpToolbar() {
}

const handleToolCallKeyboardShortcuts = (event: KeyboardEvent) => {
if (isTextInputTarget(event.target)) {
return;
}
if (isExecuteToolCallShortcut(event) && firstPendingToolCall) {
event.preventDefault();
event.stopPropagation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,6 @@ export function createEditorConfig(options: {

return true;
},
"Mod-Backspace": () => {
// If you press cmd+backspace wanting to cancel,
// but are inside of a text box, it shouldn't
// delete the text
if (isStreamingRef.current) {
return true;
}
return false;
},
"Shift-Enter": () =>
this.editor.commands.first(({ commands }) => [
() => commands.newlineInCode(),
Expand Down
9 changes: 8 additions & 1 deletion gui/src/pages/gui/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import {
import { streamEditThunk } from "../../redux/thunks/edit";
import { loadLastSession } from "../../redux/thunks/session";
import { streamResponseThunk } from "../../redux/thunks/streamResponse";
import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util";
import {
isJetBrains,
isMetaEquivalentKeyPressed,
isTextInputTarget,
} from "../../util";
import { ToolCallDiv } from "./ToolCallDiv";

import { useStore } from "react-redux";
Expand Down Expand Up @@ -136,6 +140,9 @@ export function Chat() {
useEffect(() => {
// Cmd + Backspace to delete current step
const listener = (e: KeyboardEvent) => {
if (!isStreaming || isTextInputTarget(e.target)) {
return;
}
if (
e.key === "Backspace" &&
(jetbrains ? e.altKey : isMetaEquivalentKeyPressed(e)) &&
Expand Down
11 changes: 11 additions & 0 deletions gui/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ export function isMetaEquivalentKeyPressed({
return metaKey;
}
}
export function isTextInputTarget(target: EventTarget | null): boolean {
if (!(target instanceof Element)) {
return false;
}

return Boolean(
target.closest(
'input, textarea, [contenteditable="true"], [contenteditable="plaintext-only"]',
),
);
}

export function getMetaKeyLabel(): string {
return getPlatform() === "mac" ? "⌘" : "Ctrl";
Expand Down
23 changes: 23 additions & 0 deletions gui/src/util/isTextInputTarget.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import { isTextInputTarget } from ".";

describe("isTextInputTarget", () => {
it("matches native text-editing elements", () => {
expect(isTextInputTarget(document.createElement("input"))).toBe(true);
expect(isTextInputTarget(document.createElement("textarea"))).toBe(true);
});

it("matches descendants of contenteditable editors", () => {
const editor = document.createElement("div");
editor.setAttribute("contenteditable", "true");
const child = document.createElement("span");
editor.appendChild(child);

expect(isTextInputTarget(child)).toBe(true);
});

it("ignores non-editable targets", () => {
expect(isTextInputTarget(document.createElement("button"))).toBe(false);
expect(isTextInputTarget(null)).toBe(false);
});
});
Loading