MCPcopy
hub / github.com/xtermjs/xterm.js / reflowLargerGetLinesToRemove

Function reflowLargerGetLinesToRemove

src/common/buffer/BufferReflow.ts:25–109  ·  view source on GitHub ↗
(lines: CircularList<IBufferLine>, oldCols: number, newCols: number, bufferAbsoluteY: number, nullCell: ICellData, reflowCursorLine: boolean)

Source from the content-addressed store, hash-verified

23 * @param reflowCursorLine Whether to reflow the line containing the cursor.
24 */
25export function reflowLargerGetLinesToRemove(lines: CircularList<IBufferLine>, oldCols: number, newCols: number, bufferAbsoluteY: number, nullCell: ICellData, reflowCursorLine: boolean): number[] {
26 // Gather all BufferLines that need to be removed from the Buffer here so that they can be
27 // batched up and only committed once
28 const toRemove: number[] = [];
29
30 for (let y = 0; y < lines.length - 1; y++) {
31 // Check if this row is wrapped
32 let i = y;
33 let nextLine = lines.get(++i) as BufferLine;
34 if (!nextLine.isWrapped) {
35 continue;
36 }
37
38 // Check how many lines it's wrapped for
39 const wrappedLines: BufferLine[] = [lines.get(y) as BufferLine];
40 while (i < lines.length && nextLine.isWrapped) {
41 wrappedLines.push(nextLine);
42 nextLine = lines.get(++i) as BufferLine;
43 }
44
45 if (!reflowCursorLine) {
46 // If these lines contain the cursor don't touch them, the program will handle fixing up
47 // wrapped lines with the cursor
48 if (bufferAbsoluteY >= y && bufferAbsoluteY < i) {
49 y += wrappedLines.length - 1;
50 continue;
51 }
52 }
53
54 // Copy buffer data to new locations
55 let destLineIndex = 0;
56 let destCol = getWrappedLineTrimmedLength(wrappedLines, destLineIndex, oldCols);
57 let srcLineIndex = 1;
58 let srcCol = 0;
59 while (srcLineIndex < wrappedLines.length) {
60 const srcTrimmedTineLength = getWrappedLineTrimmedLength(wrappedLines, srcLineIndex, oldCols);
61 const srcRemainingCells = srcTrimmedTineLength - srcCol;
62 const destRemainingCells = newCols - destCol;
63 const cellsToCopy = Math.min(srcRemainingCells, destRemainingCells);
64
65 wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[srcLineIndex], srcCol, destCol, cellsToCopy, false);
66
67 destCol += cellsToCopy;
68 if (destCol === newCols) {
69 destLineIndex++;
70 destCol = 0;
71 }
72 srcCol += cellsToCopy;
73 if (srcCol === srcTrimmedTineLength) {
74 srcLineIndex++;
75 srcCol = 0;
76 }
77
78 // Make sure the last cell isn't wide, if it is copy it to the current dest
79 if (destCol === 0 && destLineIndex !== 0) {
80 if (wrappedLines[destLineIndex - 1].getWidth(newCols - 1) === 2) {
81 wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[destLineIndex - 1], newCols - 1, destCol++, 1, false);
82 // Null out the end of the last row

Callers 1

_reflowLargerMethod · 0.90

Calls 8

copyCellsFromMethod · 0.80
getMethod · 0.65
pushMethod · 0.65
getWidthMethod · 0.65
setCellMethod · 0.65
replaceCellsMethod · 0.65
getTrimmedLengthMethod · 0.65

Tested by

no test coverage detected