Skip to content

Commit 0a3a668

Browse files
committed
fix: make selectLines() and getWordAtCell() scrollback-aware
- selectLines(): use viewportRowToAbsolute() instead of incorrect viewportY + row formula - getWordAtCell(): convert viewport row to absolute row and use getScrollbackLine() when in scrollback region
1 parent 2fa0ba5 commit 0a3a668

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

lib/selection-manager.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ export class SelectionManager {
313313
}
314314

315315
// Convert viewport rows to absolute rows
316-
const viewportY = this.getViewportY();
317-
this.selectionStart = { col: 0, absoluteRow: viewportY + start };
318-
this.selectionEnd = { col: dims.cols - 1, absoluteRow: viewportY + end };
316+
this.selectionStart = { col: 0, absoluteRow: this.viewportRowToAbsolute(start) };
317+
this.selectionEnd = { col: dims.cols - 1, absoluteRow: this.viewportRowToAbsolute(end) };
319318
this.requestRender();
320319
this.selectionChangedEmitter.fire();
321320
}
@@ -887,7 +886,15 @@ export class SelectionManager {
887886
* Get word boundaries at a cell position
888887
*/
889888
private getWordAtCell(col: number, row: number): { startCol: number; endCol: number } | null {
890-
const line = this.wasmTerm.getLine(row);
889+
const absoluteRow = this.viewportRowToAbsolute(row);
890+
const scrollbackLength = this.wasmTerm.getScrollbackLength();
891+
let line: GhosttyCell[] | null;
892+
if (absoluteRow < scrollbackLength) {
893+
line = this.wasmTerm.getScrollbackLine(absoluteRow);
894+
} else {
895+
const screenRow = absoluteRow - scrollbackLength;
896+
line = this.wasmTerm.getLine(screenRow);
897+
}
891898
if (!line) return null;
892899

893900
// Word characters: letters, numbers, and common path/URL characters

0 commit comments

Comments
 (0)