mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-02 10:46:46 +00:00
fix history
This commit is contained in:
@@ -47,6 +47,9 @@ type History = {
|
|||||||
type Area = {
|
type Area = {
|
||||||
isDestroyed: boolean
|
isDestroyed: boolean
|
||||||
virtualLineCount: number
|
virtualLineCount: number
|
||||||
|
visualCursor: {
|
||||||
|
visualRow: number
|
||||||
|
}
|
||||||
plainText: string
|
plainText: string
|
||||||
cursorOffset: number
|
cursorOffset: number
|
||||||
setText(text: string): void
|
setText(text: string): void
|
||||||
@@ -152,6 +155,8 @@ export function RunFooterView(props: RunFooterViewProps) {
|
|||||||
const leaders = createMemo(() => Keybind.parse(props.keybinds.leader))
|
const leaders = createMemo(() => Keybind.parse(props.keybinds.leader))
|
||||||
const cycles = createMemo(() => Keybind.parse(props.keybinds.variantCycle))
|
const cycles = createMemo(() => Keybind.parse(props.keybinds.variantCycle))
|
||||||
const interrupts = createMemo(() => Keybind.parse(props.keybinds.interrupt))
|
const interrupts = createMemo(() => Keybind.parse(props.keybinds.interrupt))
|
||||||
|
const historyPrevious = createMemo(() => Keybind.parse(props.keybinds.historyPrevious))
|
||||||
|
const historyNext = createMemo(() => Keybind.parse(props.keybinds.historyNext))
|
||||||
const variant = createMemo(() => printableBinding(props.keybinds.variantCycle, props.keybinds.leader))
|
const variant = createMemo(() => printableBinding(props.keybinds.variantCycle, props.keybinds.leader))
|
||||||
const interrupt = createMemo(() => printableBinding(props.keybinds.interrupt, props.keybinds.leader))
|
const interrupt = createMemo(() => printableBinding(props.keybinds.interrupt, props.keybinds.leader))
|
||||||
const bindings = createMemo(() => textareaBindings(props.keybinds))
|
const bindings = createMemo(() => textareaBindings(props.keybinds))
|
||||||
@@ -342,17 +347,30 @@ export function RunFooterView(props: RunFooterViewProps) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.ctrl || event.meta || event.shift || event.super || event.hyper) {
|
const key = toKeyInfo(event, false)
|
||||||
|
const previous = match(historyPrevious(), key)
|
||||||
|
const next = match(historyNext(), key)
|
||||||
|
|
||||||
|
if (!previous && !next) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.name === "up") {
|
if (!area || area.isDestroyed) {
|
||||||
move(-1, event)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.name === "down") {
|
const dir = previous ? -1 : 1
|
||||||
move(1, event)
|
if ((dir === -1 && area.cursorOffset === 0) || (dir === 1 && area.cursorOffset === area.plainText.length)) {
|
||||||
|
move(dir, event)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir === -1 && area.visualCursor.visualRow === 0) {
|
||||||
|
area.cursorOffset = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir === 1 && area.visualCursor.visualRow === area.virtualLineCount - 1) {
|
||||||
|
area.cursorOffset = area.plainText.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ const DEFAULT_KEYBINDS: FooterKeybinds = {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}
|
}
|
||||||
@@ -118,6 +120,8 @@ async function resolveFooterKeybinds(): Promise<FooterKeybinds> {
|
|||||||
const configuredLeader = config.keybinds?.leader?.trim() || DEFAULT_KEYBINDS.leader
|
const configuredLeader = config.keybinds?.leader?.trim() || DEFAULT_KEYBINDS.leader
|
||||||
const configuredVariantCycle = config.keybinds?.variant_cycle?.trim() || "ctrl+t"
|
const configuredVariantCycle = config.keybinds?.variant_cycle?.trim() || "ctrl+t"
|
||||||
const configuredInterrupt = config.keybinds?.session_interrupt?.trim() || DEFAULT_KEYBINDS.interrupt
|
const configuredInterrupt = config.keybinds?.session_interrupt?.trim() || DEFAULT_KEYBINDS.interrupt
|
||||||
|
const configuredHistoryPrevious = config.keybinds?.history_previous?.trim() || DEFAULT_KEYBINDS.historyPrevious
|
||||||
|
const configuredHistoryNext = config.keybinds?.history_next?.trim() || DEFAULT_KEYBINDS.historyNext
|
||||||
const configuredSubmit = config.keybinds?.input_submit?.trim() || DEFAULT_KEYBINDS.inputSubmit
|
const configuredSubmit = config.keybinds?.input_submit?.trim() || DEFAULT_KEYBINDS.inputSubmit
|
||||||
const configuredNewline = config.keybinds?.input_newline?.trim() || DEFAULT_KEYBINDS.inputNewline
|
const configuredNewline = config.keybinds?.input_newline?.trim() || DEFAULT_KEYBINDS.inputNewline
|
||||||
|
|
||||||
@@ -134,6 +138,8 @@ async function resolveFooterKeybinds(): Promise<FooterKeybinds> {
|
|||||||
leader: configuredLeader,
|
leader: configuredLeader,
|
||||||
variantCycle: variantBindings.join(","),
|
variantCycle: variantBindings.join(","),
|
||||||
interrupt: configuredInterrupt,
|
interrupt: configuredInterrupt,
|
||||||
|
historyPrevious: configuredHistoryPrevious,
|
||||||
|
historyNext: configuredHistoryNext,
|
||||||
inputSubmit: configuredSubmit,
|
inputSubmit: configuredSubmit,
|
||||||
inputNewline: configuredNewline,
|
inputNewline: configuredNewline,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ export type FooterKeybinds = {
|
|||||||
leader: string
|
leader: string
|
||||||
variantCycle: string
|
variantCycle: string
|
||||||
interrupt: string
|
interrupt: string
|
||||||
|
historyPrevious: string
|
||||||
|
historyNext: string
|
||||||
inputSubmit: string
|
inputSubmit: string
|
||||||
inputNewline: string
|
inputNewline: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ describe("run footer view", () => {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}}
|
}}
|
||||||
@@ -120,6 +122,8 @@ describe("run footer view", () => {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}}
|
}}
|
||||||
@@ -165,12 +169,14 @@ describe("run footer view", () => {
|
|||||||
expect(area.plainText).toBe("one")
|
expect(area.plainText).toBe("one")
|
||||||
expect(area.cursorOffset).toBe(0)
|
expect(area.cursorOffset).toBe(0)
|
||||||
|
|
||||||
area.cursorOffset = area.plainText.length
|
setup.mockInput.pressArrow("down")
|
||||||
|
expect(area.plainText).toBe("one")
|
||||||
|
expect(area.cursorOffset).toBe(area.plainText.length)
|
||||||
|
|
||||||
setup.mockInput.pressArrow("down")
|
setup.mockInput.pressArrow("down")
|
||||||
expect(area.plainText).toBe("two")
|
expect(area.plainText).toBe("two")
|
||||||
expect(area.cursorOffset).toBe(area.plainText.length)
|
expect(area.cursorOffset).toBe(area.plainText.length)
|
||||||
|
|
||||||
area.cursorOffset = area.plainText.length
|
|
||||||
setup.mockInput.pressArrow("down")
|
setup.mockInput.pressArrow("down")
|
||||||
expect(area.plainText).toBe("")
|
expect(area.plainText).toBe("")
|
||||||
expect(area.cursorOffset).toBe(0)
|
expect(area.cursorOffset).toBe(0)
|
||||||
@@ -239,6 +245,8 @@ describe("run footer view", () => {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}}
|
}}
|
||||||
@@ -290,6 +298,8 @@ describe("run footer view", () => {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}}
|
}}
|
||||||
@@ -344,6 +354,8 @@ describe("run footer view", () => {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}}
|
}}
|
||||||
@@ -388,6 +400,8 @@ describe("run footer view", () => {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}}
|
}}
|
||||||
@@ -430,6 +444,8 @@ describe("run footer view", () => {
|
|||||||
leader: "ctrl+x",
|
leader: "ctrl+x",
|
||||||
variantCycle: "ctrl+t,<leader>t",
|
variantCycle: "ctrl+t,<leader>t",
|
||||||
interrupt: "escape",
|
interrupt: "escape",
|
||||||
|
historyPrevious: "up",
|
||||||
|
historyNext: "down",
|
||||||
inputSubmit: "return",
|
inputSubmit: "return",
|
||||||
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
inputNewline: "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user