Skip to content

Commit

Permalink
Merge pull request #181940 from microsoft/merogge/orc
Browse files Browse the repository at this point in the history
replace double vs single space in terminal accessible buffer
  • Loading branch information
meganrogge authored May 10, 2023
2 parents 2fb606e + 19b0a53 commit 996418d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ 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 = currentLine.replace(new RegExp(' ', 'g'), '\xA0');
const line = replaceWithNonBreakingSpaces(currentLine);
if (line.length) {
cachedLines.push(line);
currentLine = '';
Expand Down Expand Up @@ -122,7 +122,7 @@ 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 = currentLine.replace(new RegExp(' ', 'g'), '\xA0');
const line = replaceWithNonBreakingSpaces(currentLine);
if (line.length) {
this._priorEditorViewportLineCount++;
this._lines.push(line);
Expand All @@ -133,3 +133,7 @@ export class BufferContentTracker {
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 } from 'vs/workbench/contrib/terminalContrib/accessibility/browser/bufferContentTracker';
import { BufferContentTracker, replaceWithNonBreakingSpaces } 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 @@ -99,10 +99,10 @@ suite('Buffer Content Tracker', () => {
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 => s.replace(new RegExp(' ', 'g'), '\xA0')));
assert.deepStrictEqual(bufferTracker.lines, [promptPlusData, promptPlusData, `${promptPlusData}inserteddata`, promptPlusData, promptPlusData, promptPlusData].map(s => replaceWithNonBreakingSpaces(s)));
});
test('should refresh viewport with full scrollback', async () => {
const content = `${prompt}\r\n`.repeat(1030).trimEnd().replace(new RegExp(' ', 'g'), '\xA0');
const content = replaceWithNonBreakingSpaces(`${prompt}\r\n`.repeat(1030).trimEnd());
await writeP(xterm.raw, content);
await bufferTracker.update();
await writeP(xterm.raw, '\x1b[4Ainsertion');
Expand All @@ -115,7 +115,7 @@ suite('Buffer Content Tracker', () => {
const content = `${prompt}\r\n`.repeat(1036).trimEnd();
await writeP(xterm.raw, content);
await bufferTracker.update();
const expected = content.split('\r\n').map(s => s.replace(new RegExp(' ', 'g'), '\xA0'));
const expected = content.split('\r\n').map(s => replaceWithNonBreakingSpaces(s));
// delete the 6 lines that should be trimmed
for (let i = 0; i < 6; i++) {
expected.pop();
Expand All @@ -134,6 +134,6 @@ async function writeAndAssertBufferState(data: string, rows: number, terminal: T
await writeP(terminal, content);
await bufferTracker.update();
assert.strictEqual(bufferTracker.lines.length, rows);
assert.deepStrictEqual(bufferTracker.lines, content.split('\r\n').map(s => s.replace(new RegExp(' ', 'g'), '\xA0')));
assert.deepStrictEqual(bufferTracker.lines, content.split('\r\n').map(s => replaceWithNonBreakingSpaces(s)));
}

0 comments on commit 996418d

Please sign in to comment.