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
1,145 changes: 579 additions & 566 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "opencode-vim",
"version": "0.0.29",
"version": "0.0.30",
"license": "MIT",
"type": "module",
"repository": {
Expand All @@ -26,13 +26,15 @@
"diff": "^9.0.0"
},
"peerDependencies": {
"@opencode/plugin": "2.1.4",
"@opentui/core": ">=0.6.8",
"@opentui/solid": ">=0.6.8",
"@opencode/plugin": "2.3.2",
"@opentui/core": ">=0.8.4",
"@opentui/solid": ">=0.8.4",
"solid-js": ">=1.9.0"
},
"devDependencies": {
"@opencode/theme": "2.1.4",
"@opencode/theme": "2.3.2",
"@opentui/core": "0.8.4",
"@opentui/solid": "0.8.4",
"@types/bun": "^1.3.14",
"@types/node": "^24.0.0",
"prettier": "3.9.9",
Expand Down
11 changes: 3 additions & 8 deletions src/transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function createTranscriptSelection(
from: string | undefined
offset: number
latest?: boolean
loading?: { key: string; frame: number; up: boolean; height: number }
loading?: { key: string; frame: number }
}
| undefined

Expand Down Expand Up @@ -57,16 +57,11 @@ export function createTranscriptSelection(
}
const target = navigation.latest ? ranges.length - 1 : from + navigation.offset
const loading = navigation.loading
// OpenCode compensates for prepended rows after two animation frames.
// Give OpenCode two frames to finish a load before asking for the next one.
if (loading && context.renderer.frameId < loading.frame) {
context.renderer.requestRender()
return
}
if (view && loading?.up && view.scroll.scrollHeight > loading.height) {
const maximum = Math.max(0, view.scroll.scrollHeight - view.scroll.viewport.height)
const compensated = Math.max(0, Math.min(maximum, view.scroll.scrollHeight - loading.height - 1))
if (view.scroll.scrollTop < compensated) return
}
if (view && target >= 0 && target < ranges.length && (!navigation.latest || view.hasLatest)) {
navigation = undefined
choose(ranges[target], view)
Expand All @@ -76,7 +71,7 @@ export function createTranscriptSelection(
const messages = context.data.session.message.list(sessionID)
const key = `${messages[0]?.id}:${messages.length}:${ranges[0]?.id}:${ranges.at(-1)?.id}:${view?.scroll.scrollHeight}`
if (loading?.key === key) return
navigation.loading = { key, frame: context.renderer.frameId + 2, up, height: view?.scroll.scrollHeight ?? 0 }
navigation.loading = { key, frame: context.renderer.frameId + 2 }
view?.scroll.scrollTo(up ? 0 : view.scroll.scrollHeight)
context.keymap.dispatch(up ? "session.line.up" : "session.line.down")
context.renderer.requestRender()
Expand Down
13 changes: 4 additions & 9 deletions src/vim/vimee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,16 +1073,11 @@ function clampNormalCursor(input: EditorInput, map: PromptMap) {
function dispatchCommand(command: string, ctx: EditorContext) {
const input = ctx.input()
if (command === "prompt.history.previous" && input) input.cursorOffset = 0
if (command === "prompt.history.next" && input) input.cursorOffset = input.plainText.length
// The host only moves through history when the cursor is at the end of the
// text, measured in display width.
if (command === "prompt.history.next" && input) input.cursorOffset = displayWidth(input.plainText, ctx.widthMethod)

const result = ctx.dispatchCommand(command)

// The host currently checks history-next using character length, then leaves
// the cursor in that unit. Restore the display-width offset after dispatch.
if (command !== "prompt.history.next" || !result.ok) return result
const nextInput = ctx.input()
if (nextInput) nextInput.cursorOffset = displayWidth(nextInput.plainText, ctx.widthMethod)
return result
return ctx.dispatchCommand(command)
}

function defaultHistoryCommand(
Expand Down
12 changes: 8 additions & 4 deletions test/e2e/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,20 @@ const scenarios: Array<{
run: fileChanges,
setup: { messages: fileChangeMessages, cli: { session: { grouping: "none" } } },
},
{ name: "patch-running", run: pendingPatch, setup: { messages: pendingChangeMessages } },
{
name: "patch-running",
run: pendingPatch,
setup: { messages: pendingChangeMessages, cli: { session: { verbosity: "medium" } } },
},
{
name: "permission-tools",
run: permissionTools(true),
setup: { messages: permissionMessages, cli: { session: { grouping: "auto" } } },
setup: { messages: permissionMessages, cli: { session: { verbosity: "medium", grouping: "auto" } } },
},
{
name: "permission-tools-ungrouped",
run: permissionTools(false),
setup: { messages: permissionMessages, cli: { session: { grouping: "none" } } },
setup: { messages: permissionMessages, cli: { session: { verbosity: "medium", grouping: "none" } } },
},
{ name: "diff-reader", run: diffReader(), setup: { messages: fileChangeMessages } },
{
Expand Down Expand Up @@ -354,7 +358,7 @@ for (const animations of [true, false]) {
setup: {
messages,
probe: name === "partial",
cli: { animations, session: { grouping: "none", thinking: "show" } },
cli: { animations, session: { verbosity: "medium", grouping: "none", thinking: "show" } },
},
})
}
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/scenarios/dialog-focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ export async function dialogFocus(fixture: Fixture) {
(text) => text.includes("Commands") && text.includes("Switch session") && text.includes("NORMAL"),
)
await type("j".repeat(30))
await screen("dialog-scrolled-down", (text) => text.includes("Commands") && !text.includes("Switch session"))
// "Switch session" is listed again further down, so watch the first group's heading instead.
await screen("dialog-scrolled-down", (text) => text.includes("Commands") && !text.includes("Suggested"))
await type("k".repeat(30))
await screen("dialog-scrolled-up", (text) => text.includes("Commands") && text.includes("Switch session"))
await screen("dialog-scrolled-up", (text) => text.includes("Commands") && text.includes("Suggested"))
await type("iOpen settings")
await screen("dialog-submit-filter", (text) => text.includes("Open settings") && !text.includes("Switch session"))
await keys("Escape")
Expand Down
18 changes: 10 additions & 8 deletions test/e2e/scenarios/native-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,24 @@ export async function nativeHistory({ terminal, probe, request, sessionID, strea
await terminal.screen(`${kind}-undone`, async () => (await probe()).editor?.text === "")
await terminal.keys("C-r")
await terminal.screen(`${kind}-redone`, async () => (await probe()).editor?.text === original)
// OpenCode's own redo brings back an attachment's label but not the attachment
// itself, so only pasted text is sent and checked.
if (kind !== "paste") {
await terminal.type("u")
await terminal.screen(`${kind}-cleared`, async () => (await probe()).editor?.text === "")
continue
}
await terminal.keys("Enter")
await terminal.screen(`${kind}-submitted`, (text) => text.split("native history response").length === index + 2)
await terminal.screen("paste-submitted", (text) => text.includes("native history response"))
stream.write("", true)
await terminal.screen(`${kind}-completed`, async () => {
await terminal.screen("paste-completed", async () => {
const exported = await request(`/api/experimental/session/${sessionID}/export`)
const assistant = exported.data.messages.filter((message: any) => message.type === "assistant").at(-1)
return !!assistant?.time.completed
})
const exported = await request(`/api/experimental/session/${sessionID}/export`)
const user = exported.data.messages.filter((message: any) => message.type === "user").at(-1)
if (kind === "paste") assert.equal(user.text.trim(), pasted, "Redo must restore the original pasted contents")
else {
assert.equal(user.files.length, 1, "Redo must restore the attachment, not just its label")
if (kind === "image") assert.equal(user.files[0].data, image)
else assert.equal(user.files[0].name, "native-history.txt")
}
assert.equal(user.text.trim(), pasted, "Redo must restore the original pasted contents")
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/e2e/support/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ export async function runWithFixture(options: Options, run: (fixture: Fixture) =
OPENCODE_CONFIG_DIR: path.join(directory, "config"),
OPENCODE_CONFIG_CONTENT: JSON.stringify(stream?.config ?? {}),
OPENCODE_DISABLE_PROJECT_CONFIG: "true",
OPENCODE_DISABLE_FILEWATCHER: "true",
// The TUI needs its watcher to reload cli.json when a scenario unloads Vim.
...(home === "server" ? { OPENCODE_DISABLE_FILEWATCHER: "true" } : {}),
OPENCODE_DISABLE_MODELS_FETCH: "true",
OPENCODE_DISABLE_AUTOUPDATE: "true",
OPENCODE_PASSWORD: password,
Expand Down
46 changes: 26 additions & 20 deletions test/integration/highlighting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ import { highlightCode } from "../../src/readers/syntax"

test("multiline reader colors match native code rendering with the real TypeScript parser", async () => {
const screen = await createTestRenderer({ width: 70, height: 32 })
const syntax = SyntaxStyle.fromStyles({
default: { fg: "#eeeeee" },
keyword: { fg: "#ff0000" },
string: { fg: "#00ff00" },
comment: { fg: "#888888" },
number: { fg: "#00ffff" },
variable: { fg: "#ffff00" },
operator: { fg: "#ff00ff" },
punctuation: { fg: "#ffffff" },
})
const syntax = SyntaxStyle.fromStyles(
{
default: { fg: "#eeeeee" },
keyword: { fg: "#ff0000" },
string: { fg: "#00ff00" },
comment: { fg: "#888888" },
number: { fg: "#00ffff" },
variable: { fg: "#ffff00" },
operator: { fg: "#ff00ff" },
punctuation: { fg: "#ffffff" },
},
screen.renderer.nativeScene,
)
const text = [
"",
'const greeting = "你好 👩‍💻";',
Expand Down Expand Up @@ -80,16 +83,19 @@ test("multiline reader colors match native code rendering with the real TypeScri

test("diff code colors and change backgrounds match native unified diff rendering", async () => {
const screen = await createTestRenderer({ width: 70, height: 36 })
const syntax = SyntaxStyle.fromStyles({
default: { fg: "#eeeeee" },
keyword: { fg: "#ff0000" },
string: { fg: "#00ff00" },
comment: { fg: "#888888" },
number: { fg: "#00ffff" },
variable: { fg: "#ffff00" },
operator: { fg: "#ff00ff" },
punctuation: { fg: "#ffffff" },
})
const syntax = SyntaxStyle.fromStyles(
{
default: { fg: "#eeeeee" },
keyword: { fg: "#ff0000" },
string: { fg: "#00ff00" },
comment: { fg: "#888888" },
number: { fg: "#00ffff" },
variable: { fg: "#ffff00" },
operator: { fg: "#ff00ff" },
punctuation: { fg: "#ffffff" },
},
screen.renderer.nativeScene,
)
const patch =
[
"--- example.ts",
Expand Down
6 changes: 4 additions & 2 deletions test/unit/map.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
import { EditBuffer } from "@opentui/core"
import { EditBuffer, ResourceContext } from "@opentui/core"
import { createGraphemeCodec } from "../../src/vim/graphemes"
import {
charToDisplay,
Expand All @@ -17,7 +17,8 @@ describe("vim display offsets", () => {
test.each(["unicode", "wcwidth", "unicode-wide"] as const)("matches OpenTUI's %s offsets", (method) => {
const lines = ["你好 👩‍💻", "👨‍👩‍👧‍👦", "e\u0301\tend", "x·Ω", "last"]
const text = lines.join("\n")
const buffer = EditBuffer.create(method)
const owner = new ResourceContext({ objectCapacity: 16, renderCellsMax: 1024 })
const buffer = EditBuffer.create(method, owner)
try {
buffer.setText(text)
const map = createPromptMap(text, undefined, method)
Expand All @@ -31,6 +32,7 @@ describe("vim display offsets", () => {
}
} finally {
buffer.destroy()
owner.destroy()
}
})
test("maps ASCII and CJK offsets", () => {
Expand Down
Loading