Skip to content

Commit a63890e

Browse files
authored
Merge pull request #3624 from Tyriar/3617_clear_on_buffer_change
Ensure the glyph vertices are cleared when switching buffers
2 parents b557ebe + 904b491 commit a63890e

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

addons/xterm-addon-webgl/src/GlyphRenderer.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -299,32 +299,37 @@ export class GlyphRenderer {
299299
return this._colors.ansi[idx];
300300
}
301301

302-
public onResize(): void {
302+
public clear(force?: boolean): void {
303303
const terminal = this._terminal;
304-
const gl = this._gl;
305-
306-
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
307-
308-
// Update vertices
309304
const newCount = terminal.cols * terminal.rows * INDICES_PER_CELL;
310-
if (this._vertices.count !== newCount) {
311-
this._vertices.count = newCount;
312-
this._vertices.attributes = new Float32Array(newCount);
313-
for (let i = 0; i < this._vertices.attributesBuffers.length; i++) {
314-
this._vertices.attributesBuffers[i] = new Float32Array(newCount);
315-
}
316305

317-
let i = 0;
318-
for (let y = 0; y < terminal.rows; y++) {
319-
for (let x = 0; x < terminal.cols; x++) {
320-
this._vertices.attributes[i + 8] = x / terminal.cols;
321-
this._vertices.attributes[i + 9] = y / terminal.rows;
322-
i += INDICES_PER_CELL;
323-
}
306+
// Don't clear if not forced and the array length is correct
307+
if (!force && this._vertices.count === newCount) {
308+
return;
309+
}
310+
311+
// Clear vertices
312+
this._vertices.count = newCount;
313+
this._vertices.attributes = new Float32Array(newCount);
314+
for (let i = 0; i < this._vertices.attributesBuffers.length; i++) {
315+
this._vertices.attributesBuffers[i] = new Float32Array(newCount);
316+
}
317+
let i = 0;
318+
for (let y = 0; y < terminal.rows; y++) {
319+
for (let x = 0; x < terminal.cols; x++) {
320+
this._vertices.attributes[i + 8] = x / terminal.cols;
321+
this._vertices.attributes[i + 9] = y / terminal.rows;
322+
i += INDICES_PER_CELL;
324323
}
325324
}
326325
}
327326

327+
public onResize(): void {
328+
const gl = this._gl;
329+
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
330+
this.clear();
331+
}
332+
328333
public setColors(): void {
329334
}
330335

addons/xterm-addon-webgl/src/WebglRenderer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ export class WebglRenderer extends Disposable implements IRenderer {
247247
}
248248

249249
public clear(): void {
250+
this._model.clear();
251+
this._glyphRenderer.clear(true);
250252
for (const l of this._renderLayers) {
251253
l.reset(this._terminal);
252254
}

src/browser/services/RenderService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export class RenderService extends Disposable implements IRenderService {
6565
this._screenDprMonitor.setListener(() => this.onDevicePixelRatioChange());
6666
this.register(this._screenDprMonitor);
6767

68-
this.register(bufferService.onResize(e => this._fullRefresh()));
68+
this.register(bufferService.onResize(() => this._fullRefresh()));
69+
this.register(bufferService.buffers.onBufferActivate(() => this._renderer?.clear()));
6970
this.register(optionsService.onOptionChange(() => this._renderer.onOptionsChanged()));
7071
this.register(this._charSizeService.onCharSizeChange(() => this.onCharSizeChanged()));
7172

src/common/InputHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ export class InputHandler extends Disposable implements IInputHandler {
546546

547547
// Log debug data, the log level gate is to prevent extra work in this hot path
548548
if (this._logService.logLevel <= LogLevelEnum.DEBUG) {
549-
this._logService.debug(`parsing data${typeof data === 'string' ? ` "${data}"` : ''}`, typeof data === 'string'
549+
this._logService.debug(`parsing data${typeof data === 'string' ? ` "${data}"` : ` "${Array.prototype.map.call(data, e => String.fromCharCode(e)).join('')}"`}`, typeof data === 'string'
550550
? data.split('').map(e => e.charCodeAt(0))
551551
: data
552552
);

0 commit comments

Comments
 (0)