Skip to content

Commit

Permalink
Merge pull request #184730 from microsoft/tyriar/181834
Browse files Browse the repository at this point in the history
Remove nbsp replacing from buffer content tracker
  • Loading branch information
Tyriar committed Jun 14, 2023
2 parents aa82bd5 + e845b77 commit f8a02c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ export class BufferContentTracker {
const isWrapped = buffer.getLine(i + 1)?.isWrapped;
currentLine += line.translateToString(!isWrapped);
if (currentLine && !isWrapped || i === (buffer.baseY + this._xterm.raw.rows - 1)) {
const line = replaceWithNonBreakingSpaces(currentLine);
if (line.length) {
cachedLines.push(line);
cachedLines.push(currentLine);
currentLine = '';
}
}
Expand Down Expand Up @@ -122,18 +121,13 @@ export class BufferContentTracker {
const isWrapped = buffer.getLine(i + 1)?.isWrapped;
currentLine += line.translateToString(!isWrapped);
if (currentLine && !isWrapped || i === (buffer.baseY + this._xterm.raw.rows - 1)) {
const line = replaceWithNonBreakingSpaces(currentLine);
if (line.length) {
if (currentLine.length) {
this._priorEditorViewportLineCount++;
this._lines.push(line);
this._lines.push(currentLine);
currentLine = '';
}
}
}
this._logService.debug('Viewport content update complete, ', this._lines.length, ' lines in the viewport');
}
}

export function replaceWithNonBreakingSpaces(s: string): string {
return s.replace(new RegExp(' ', 'g'), ' \xA0');
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/term
import { writeP } from 'vs/workbench/contrib/terminal/browser/terminalTestHelpers';
import { XtermTerminal } from 'vs/workbench/contrib/terminal/browser/xterm/xtermTerminal';
import { ITerminalConfiguration } from 'vs/workbench/contrib/terminal/common/terminal';
import { BufferContentTracker, replaceWithNonBreakingSpaces } from 'vs/workbench/contrib/terminalContrib/accessibility/browser/bufferContentTracker';
import { BufferContentTracker } from 'vs/workbench/contrib/terminalContrib/accessibility/browser/bufferContentTracker';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { TestLifecycleService } from 'vs/workbench/test/browser/workbenchTestServices';
import { Terminal } from 'xterm';
Expand Down Expand Up @@ -72,22 +72,18 @@ suite('Buffer Content Tracker', () => {
assert.strictEqual(bufferTracker.lines.length, 0);
await writeP(xterm.raw, prompt);
xterm.clearBuffer();
await bufferTracker.update();
bufferTracker.update();
assert.deepStrictEqual(bufferTracker.lines, [prompt]);
assert.strictEqual(bufferTracker.lines.length, 1);
});
test('repeated updates should not change the content', async () => {
assert.strictEqual(bufferTracker.lines.length, 0);
await writeP(xterm.raw, prompt);
await bufferTracker.update();
bufferTracker.update();
assert.deepStrictEqual(bufferTracker.lines, [prompt]);
assert.strictEqual(bufferTracker.lines.length, 1);
await bufferTracker.update();
bufferTracker.update();
assert.deepStrictEqual(bufferTracker.lines, [prompt]);
assert.strictEqual(bufferTracker.lines.length, 1);
await bufferTracker.update();
bufferTracker.update();
assert.deepStrictEqual(bufferTracker.lines, [prompt]);
assert.strictEqual(bufferTracker.lines.length, 1);
});
test('should add lines in the viewport and scrollback', async () => {
await writeAndAssertBufferState(promptPlusData, 38, xterm.raw, bufferTracker);
Expand All @@ -98,31 +94,31 @@ suite('Buffer Content Tracker', () => {
test('should refresh viewport', async () => {
await writeAndAssertBufferState(promptPlusData, 6, xterm.raw, bufferTracker);
await writeP(xterm.raw, '\x1b[3Ainserteddata');
await bufferTracker.update();
assert.deepStrictEqual(bufferTracker.lines, [promptPlusData, promptPlusData, `${promptPlusData}inserteddata`, promptPlusData, promptPlusData, promptPlusData].map(s => replaceWithNonBreakingSpaces(s)));
bufferTracker.update();
assert.deepStrictEqual(bufferTracker.lines, [promptPlusData, promptPlusData, `${promptPlusData}inserteddata`, promptPlusData, promptPlusData, promptPlusData]);
});
test('should refresh viewport with full scrollback', async () => {
const content = replaceWithNonBreakingSpaces(`${prompt}\r\n`.repeat(1030).trimEnd());
const content = `${prompt}\r\n`.repeat(1030).trimEnd();
await writeP(xterm.raw, content);
await bufferTracker.update();
bufferTracker.update();
await writeP(xterm.raw, '\x1b[4Ainsertion');
await bufferTracker.update();
bufferTracker.update();
const expected = content.split('\r\n');
expected[1025] = `${prompt}insertion`;
assert.deepStrictEqual(bufferTracker.lines[1025], `${prompt}insertion`);
});
test('should cap the size of the cached lines, removing old lines in favor of new lines', async () => {
const content = `${prompt}\r\n`.repeat(1036).trimEnd();
await writeP(xterm.raw, content);
await bufferTracker.update();
const expected = content.split('\r\n').map(s => replaceWithNonBreakingSpaces(s));
bufferTracker.update();
const expected = content.split('\r\n');
// delete the 6 lines that should be trimmed
for (let i = 0; i < 6; i++) {
expected.pop();
}
// insert a new character
await writeP(xterm.raw, '\x1b[2Ainsertion');
await bufferTracker.update();
bufferTracker.update();
expected[1027] = `${prompt}insertion`;
assert.strictEqual(bufferTracker.lines.length, expected.length);
assert.deepStrictEqual(bufferTracker.lines, expected);
Expand All @@ -132,8 +128,8 @@ suite('Buffer Content Tracker', () => {
async function writeAndAssertBufferState(data: string, rows: number, terminal: Terminal, bufferTracker: BufferContentTracker): Promise<void> {
const content = `${data}\r\n`.repeat(rows).trimEnd();
await writeP(terminal, content);
await bufferTracker.update();
bufferTracker.update();
assert.strictEqual(bufferTracker.lines.length, rows);
assert.deepStrictEqual(bufferTracker.lines, content.split('\r\n').map(s => replaceWithNonBreakingSpaces(s)));
assert.deepStrictEqual(bufferTracker.lines, content.split('\r\n'));
}

0 comments on commit f8a02c3

Please sign in to comment.