summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components/prompt-input/editor-dom.test.ts
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-12 19:58:43 -0600
committerAdam <[email protected]>2026-02-12 19:58:57 -0600
commit7f95cc64c57b439f58833d0300a1da93b3b893df (patch)
treed9a75b27dac2f1fcf5865bb3c98fbee28f489eb5 /packages/app/src/components/prompt-input/editor-dom.test.ts
parentb525c03d205e37ad7527e6bd1749b324395dd6b7 (diff)
downloadopencode-7f95cc64c57b439f58833d0300a1da93b3b893df.tar.gz
opencode-7f95cc64c57b439f58833d0300a1da93b3b893df.zip
fix(app): prompt input quirks
Diffstat (limited to 'packages/app/src/components/prompt-input/editor-dom.test.ts')
-rw-r--r--packages/app/src/components/prompt-input/editor-dom.test.ts36
1 files changed, 31 insertions, 5 deletions
diff --git a/packages/app/src/components/prompt-input/editor-dom.test.ts b/packages/app/src/components/prompt-input/editor-dom.test.ts
index fce8b4b95..15e759f44 100644
--- a/packages/app/src/components/prompt-input/editor-dom.test.ts
+++ b/packages/app/src/components/prompt-input/editor-dom.test.ts
@@ -2,17 +2,26 @@ import { describe, expect, test } from "bun:test"
import { createTextFragment, getCursorPosition, getNodeLength, getTextLength, setCursorPosition } from "./editor-dom"
describe("prompt-input editor dom", () => {
- test("createTextFragment preserves newlines with br and zero-width placeholders", () => {
+ test("createTextFragment preserves newlines with consecutive br nodes", () => {
const fragment = createTextFragment("foo\n\nbar")
const container = document.createElement("div")
container.appendChild(fragment)
- expect(container.childNodes.length).toBe(5)
+ expect(container.childNodes.length).toBe(4)
+ expect(container.childNodes[0]?.textContent).toBe("foo")
+ expect((container.childNodes[1] as HTMLElement).tagName).toBe("BR")
+ expect((container.childNodes[2] as HTMLElement).tagName).toBe("BR")
+ expect(container.childNodes[3]?.textContent).toBe("bar")
+ })
+
+ test("createTextFragment keeps trailing newline as terminal break", () => {
+ const fragment = createTextFragment("foo\n")
+ const container = document.createElement("div")
+ container.appendChild(fragment)
+
+ expect(container.childNodes.length).toBe(2)
expect(container.childNodes[0]?.textContent).toBe("foo")
expect((container.childNodes[1] as HTMLElement).tagName).toBe("BR")
- expect(container.childNodes[2]?.textContent).toBe("\u200B")
- expect((container.childNodes[3] as HTMLElement).tagName).toBe("BR")
- expect(container.childNodes[4]?.textContent).toBe("bar")
})
test("length helpers treat breaks as one char and ignore zero-width chars", () => {
@@ -48,4 +57,21 @@ describe("prompt-input editor dom", () => {
container.remove()
})
+
+ test("setCursorPosition and getCursorPosition round-trip across blank lines", () => {
+ const container = document.createElement("div")
+ container.appendChild(document.createTextNode("a"))
+ container.appendChild(document.createElement("br"))
+ container.appendChild(document.createElement("br"))
+ container.appendChild(document.createTextNode("b"))
+ document.body.appendChild(container)
+
+ setCursorPosition(container, 2)
+ expect(getCursorPosition(container)).toBe(2)
+
+ setCursorPosition(container, 3)
+ expect(getCursorPosition(container)).toBe(3)
+
+ container.remove()
+ })
})