mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-04 23:40:48 +00:00
fix(app): stop terminal autofocus on shortcuts (#18931)
This commit is contained in:
parent
d3debc191f
commit
fde201c286
3 changed files with 36 additions and 2 deletions
|
|
@ -41,7 +41,13 @@ import { useSync } from "@/context/sync"
|
||||||
import { useTerminal } from "@/context/terminal"
|
import { useTerminal } from "@/context/terminal"
|
||||||
import { type FollowupDraft, sendFollowupDraft } from "@/components/prompt-input/submit"
|
import { type FollowupDraft, sendFollowupDraft } from "@/components/prompt-input/submit"
|
||||||
import { createSessionComposerState, SessionComposerRegion } from "@/pages/session/composer"
|
import { createSessionComposerState, SessionComposerRegion } from "@/pages/session/composer"
|
||||||
import { createOpenReviewFile, createSessionTabs, createSizing, focusTerminalById } from "@/pages/session/helpers"
|
import {
|
||||||
|
createOpenReviewFile,
|
||||||
|
createSessionTabs,
|
||||||
|
createSizing,
|
||||||
|
focusTerminalById,
|
||||||
|
shouldFocusTerminalOnKeyDown,
|
||||||
|
} from "@/pages/session/helpers"
|
||||||
import { MessageTimeline } from "@/pages/session/message-timeline"
|
import { MessageTimeline } from "@/pages/session/message-timeline"
|
||||||
import { type DiffStyle, SessionReviewTab, type SessionReviewTabProps } from "@/pages/session/review-tab"
|
import { type DiffStyle, SessionReviewTab, type SessionReviewTabProps } from "@/pages/session/review-tab"
|
||||||
import { useSessionLayout } from "@/pages/session/session-layout"
|
import { useSessionLayout } from "@/pages/session/session-layout"
|
||||||
|
|
@ -850,7 +856,7 @@ export default function Page() {
|
||||||
// Prefer the open terminal over the composer when it can take focus
|
// Prefer the open terminal over the composer when it can take focus
|
||||||
if (view().terminal.opened()) {
|
if (view().terminal.opened()) {
|
||||||
const id = terminal.active()
|
const id = terminal.active()
|
||||||
if (id && focusTerminalById(id)) return
|
if (id && shouldFocusTerminalOnKeyDown(event) && focusTerminalById(id)) return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only treat explicit scroll keys as potential "user scroll" gestures.
|
// Only treat explicit scroll keys as potential "user scroll" gestures.
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
createSessionTabs,
|
createSessionTabs,
|
||||||
focusTerminalById,
|
focusTerminalById,
|
||||||
getTabReorderIndex,
|
getTabReorderIndex,
|
||||||
|
shouldFocusTerminalOnKeyDown,
|
||||||
} from "./helpers"
|
} from "./helpers"
|
||||||
|
|
||||||
describe("createOpenReviewFile", () => {
|
describe("createOpenReviewFile", () => {
|
||||||
|
|
@ -86,6 +87,26 @@ describe("focusTerminalById", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("shouldFocusTerminalOnKeyDown", () => {
|
||||||
|
test("skips pure modifier keys", () => {
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Meta", metaKey: true }))).toBe(false)
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Control", ctrlKey: true }))).toBe(false)
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Alt", altKey: true }))).toBe(false)
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Shift", shiftKey: true }))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("skips shortcut key combos", () => {
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "c", metaKey: true }))).toBe(false)
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "c", ctrlKey: true }))).toBe(false)
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "ArrowLeft", altKey: true }))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("keeps plain typing focused on terminal", () => {
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "a" }))).toBe(true)
|
||||||
|
expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "A", shiftKey: true }))).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("getTabReorderIndex", () => {
|
describe("getTabReorderIndex", () => {
|
||||||
test("returns target index for valid drag reorder", () => {
|
test("returns target index for valid drag reorder", () => {
|
||||||
expect(getTabReorderIndex(["a", "b", "c"], "a", "c")).toBe(2)
|
expect(getTabReorderIndex(["a", "b", "c"], "a", "c")).toBe(2)
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,13 @@ export const focusTerminalById = (id: string) => {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const skip = new Set(["Alt", "Control", "Meta", "Shift"])
|
||||||
|
|
||||||
|
export const shouldFocusTerminalOnKeyDown = (event: Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey" | "altKey">) => {
|
||||||
|
if (skip.has(event.key)) return false
|
||||||
|
return !(event.ctrlKey || event.metaKey || event.altKey)
|
||||||
|
}
|
||||||
|
|
||||||
export const createOpenReviewFile = (input: {
|
export const createOpenReviewFile = (input: {
|
||||||
showAllFiles: () => void
|
showAllFiles: () => void
|
||||||
tabForPath: (path: string) => string
|
tabForPath: (path: string) => string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue