Skip to content

Commit 1ab3c47

Browse files
committed
fix(panel/liveConsole): fix markers being in the wrong line
This happened when there was any line reflowing above it. Context: xtermjs/xterm.js#5317
1 parent ee7f450 commit 1ab3c47

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

panel/src/pages/LiveConsole/LiveConsolePage.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,13 @@ export default function LiveConsolePage() {
262262
}
263263

264264
//Markers
265+
let writeCallback: (() => void) | undefined;
265266
try {
266267
const res = getTermLineEventData(line)
267268
?? getTermLineInitialData(line)
268269
?? getTermLineRtlData(line); //https://github.com/xtermjs/xterm.js/issues/701
269270
if (res && res.markerData) {
270-
registerTermLineMarker(term, i, res.markerData);
271+
writeCallback = () => registerTermLineMarker(term, res.markerData);
271272
}
272273
if (res && res.newLine) {
273274
line = res.newLine;
@@ -282,14 +283,14 @@ export default function LiveConsolePage() {
282283
? prefixColor + termPrefixRef.current.prefix
283284
: '';
284285
if (i < lines.length - 1) {
285-
term.writeln(prefix + line);
286+
term.writeln(prefix + line, writeCallback);
286287
termPrefixRef.current.lastEol = true;
287288
} else {
288289
if (wasEolStripped) {
289-
term.writeln(prefix + line);
290+
term.writeln(prefix + line, writeCallback);
290291
termPrefixRef.current.lastEol = true;
291292
} else {
292-
term.write(prefix + line);
293+
term.write(prefix + line, writeCallback);
293294
termPrefixRef.current.lastEol = false;
294295
}
295296
}

panel/src/pages/LiveConsole/liveConsoleMarkers.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,15 @@ export const getTermLineInitialData = (line: string): TerminalMarkerGetterResult
118118
}
119119

120120

121-
/**
122-
* Gets the marker position based on the block index
123-
* The marker position is always relative to cursor, but at the first render,
124-
* the cursor is = until all the writes are done, so we need to calculate the
125-
* marker position based on the block index
126-
*/
127-
const getMarkerPos = (term: Terminal, blockIndex: number) => {
128-
return term.buffer.active.cursorY === 0 ? blockIndex + 2 : 0;
129-
}
130-
131-
132121
/**
133122
* Registers a line marker & decoration
134123
*/
135124
export const registerTermLineMarker = (
136125
term: Terminal,
137-
blockIndex: number,
138126
markerData: TerminalMarkerData,
139127
) => {
140-
const marker = term.registerMarker(getMarkerPos(term, blockIndex));
128+
//NOTE: as this is only called from a write callback, we will _always_ be one line ahead
129+
const marker = term.registerMarker(-1);
141130
const decoration = term.registerDecoration({ layer: 'top', marker });
142131
decoration && decoration.onRender((element) => {
143132
if (element.innerHTML) return; //terminal re-rendering

0 commit comments

Comments
 (0)