summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam <[email protected]>2025-12-05 12:05:30 -0600
committerAdam <[email protected]>2025-12-05 12:05:30 -0600
commit6e6bd1e1710be0d1daa481c0005ddd8e6cc093c4 (patch)
tree055442b283ed18c5e22c9248ea3aff1ea5786f8e
parent81ee2d2332ce71ba1232387be4ad26ee37bb7a3b (diff)
downloadopencode-6e6bd1e1710be0d1daa481c0005ddd8e6cc093c4.tar.gz
opencode-6e6bd1e1710be0d1daa481c0005ddd8e6cc093c4.zip
fix(desktop): terminal cursor position
-rw-r--r--packages/desktop/src/addons/serialize.ts33
-rw-r--r--packages/desktop/src/components/terminal.tsx7
2 files changed, 14 insertions, 26 deletions
diff --git a/packages/desktop/src/addons/serialize.ts b/packages/desktop/src/addons/serialize.ts
index 03899ff10..c9f848180 100644
--- a/packages/desktop/src/addons/serialize.ts
+++ b/packages/desktop/src/addons/serialize.ts
@@ -494,14 +494,9 @@ class StringSerializeHandler extends BaseSerializeHandler {
}
if (!excludeFinalCursorPosition) {
- // Get cursor position relative to viewport (1-indexed for ANSI)
- // cursorY is relative to the viewport, cursorX is column position
- const cursorRow = this._buffer.cursorY + 1 // 1-indexed
- const cursorCol = this._buffer.cursorX + 1 // 1-indexed
-
- // Use absolute cursor positioning (CUP - Cursor Position)
- // This is more reliable than relative moves which depend on knowing
- // exactly where the cursor ended up after all the content
+ const absoluteCursorRow = (this._buffer.baseY ?? 0) + this._buffer.cursorY
+ const cursorRow = constrain(absoluteCursorRow - this._firstRow + 1, 1, Number.MAX_SAFE_INTEGER)
+ const cursorCol = this._buffer.cursorX + 1
content += `\u001b[${cursorRow};${cursorCol}H`
}
@@ -549,22 +544,20 @@ export class SerializeAddon implements ITerminalAddon {
return ""
}
- const activeBuffer = buffer.active || buffer.normal
- if (!activeBuffer) {
+ const normalBuffer = buffer.normal || buffer.active
+ const altBuffer = buffer.alternate
+
+ if (!normalBuffer) {
return ""
}
let content = options?.range
- ? this._serializeBufferByRange(activeBuffer, options.range, true)
- : this._serializeBufferByScrollback(activeBuffer, options?.scrollback)
-
- // Handle alternate buffer if active and not excluded
- if (!options?.excludeAltBuffer) {
- const altBuffer = buffer.alternate
- if (altBuffer && buffer.active?.type === "alternate") {
- const alternateContent = this._serializeBufferByScrollback(altBuffer, undefined)
- content += `\u001b[?1049h\u001b[H${alternateContent}`
- }
+ ? this._serializeBufferByRange(normalBuffer, options.range, true)
+ : this._serializeBufferByScrollback(normalBuffer, options?.scrollback)
+
+ if (!options?.excludeAltBuffer && buffer.active?.type === "alternate" && altBuffer) {
+ const alternateContent = this._serializeBufferByScrollback(altBuffer, undefined)
+ content += `\u001b[?1049h\u001b[H${alternateContent}`
}
return content
diff --git a/packages/desktop/src/components/terminal.tsx b/packages/desktop/src/components/terminal.tsx
index f7b44b0aa..aaf5da880 100644
--- a/packages/desktop/src/components/terminal.tsx
+++ b/packages/desktop/src/components/terminal.tsx
@@ -52,19 +52,14 @@ export const Terminal = (props: TerminalProps) => {
term.open(container)
if (local.pty.buffer) {
- const originalSize = { cols: term.cols, rows: term.rows }
- let resized = false
if (local.pty.rows && local.pty.cols) {
term.resize(local.pty.cols, local.pty.rows)
- resized = true
}
+ term.reset()
term.write(local.pty.buffer)
if (local.pty.scrollY) {
term.scrollToLine(local.pty.scrollY)
}
- if (resized) {
- term.resize(originalSize.cols, originalSize.rows)
- }
}
container.focus()