diff --git a/addons/xterm-addon-webgl/package.json b/addons/xterm-addon-webgl/package.json index 34422774..ca49e795 100644 --- a/addons/xterm-addon-webgl/package.json +++ b/addons/xterm-addon-webgl/package.json @@ -1,6 +1,6 @@ { "name": "xterm-addon-webgl", - "version": "0.5.0", + "version": "0.5.1", "author": { "name": "The xterm.js authors", "url": "https://xtermjs.org/" diff --git a/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts b/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts index 1072a171..2ade8007 100644 --- a/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts +++ b/addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts @@ -128,6 +128,9 @@ export class CursorRenderLayer extends BaseRenderLayer { const cursorY = terminal.buffer.baseY + terminal.buffer.cursorY; const viewportRelativeCursorY = cursorY - terminal.buffer.viewportY; + // in case cursor.x == cols adjust visual cursor to cols - 1 + const cursorX = Math.min(terminal.buffer.cursorX, terminal.cols - 1); + // Don't draw the cursor if it's off-screen if (viewportRelativeCursorY < 0 || viewportRelativeCursorY >= terminal.rows) { this._clearCursor(); @@ -135,7 +138,7 @@ export class CursorRenderLayer extends BaseRenderLayer { } // TODO: Need fast buffer API for loading cell - (terminal as any)._core.buffer.lines.get(cursorY).loadCell(terminal.buffer.cursorX, this._cell); + (terminal as any)._core.buffer.lines.get(cursorY).loadCell(cursorX, this._cell); if (this._cell.content === undefined) { return; } @@ -146,12 +149,12 @@ export class CursorRenderLayer extends BaseRenderLayer { this._ctx.fillStyle = this._colors.cursor.css; const cursorStyle = terminal.getOption('cursorStyle'); if (cursorStyle && cursorStyle !== 'block') { - this._cursorRenderers[cursorStyle](terminal, terminal.buffer.cursorX, viewportRelativeCursorY, this._cell); + this._cursorRenderers[cursorStyle](terminal, cursorX, viewportRelativeCursorY, this._cell); } else { - this._renderBlurCursor(terminal, terminal.buffer.cursorX, viewportRelativeCursorY, this._cell); + this._renderBlurCursor(terminal, cursorX, viewportRelativeCursorY, this._cell); } this._ctx.restore(); - this._state.x = terminal.buffer.cursorX; + this._state.x = cursorX; this._state.y = viewportRelativeCursorY; this._state.isFocused = false; this._state.style = cursorStyle; @@ -167,7 +170,7 @@ export class CursorRenderLayer extends BaseRenderLayer { if (this._state) { // The cursor is already in the correct spot, don't redraw - if (this._state.x === terminal.buffer.cursorX && + if (this._state.x === cursorX && this._state.y === viewportRelativeCursorY && this._state.isFocused === isTerminalFocused(terminal) && this._state.style === terminal.getOption('cursorStyle') && @@ -178,10 +181,10 @@ export class CursorRenderLayer extends BaseRenderLayer { } this._ctx.save(); - this._cursorRenderers[terminal.getOption('cursorStyle') || 'block'](terminal, terminal.buffer.cursorX, viewportRelativeCursorY, this._cell); + this._cursorRenderers[terminal.getOption('cursorStyle') || 'block'](terminal, cursorX, viewportRelativeCursorY, this._cell); this._ctx.restore(); - this._state.x = terminal.buffer.cursorX; + this._state.x = cursorX; this._state.y = viewportRelativeCursorY; this._state.isFocused = false; this._state.style = terminal.getOption('cursorStyle'); diff --git a/src/browser/renderer/CursorRenderLayer.ts b/src/browser/renderer/CursorRenderLayer.ts index 64ecf33f..8b25667b 100644 --- a/src/browser/renderer/CursorRenderLayer.ts +++ b/src/browser/renderer/CursorRenderLayer.ts @@ -140,7 +140,9 @@ export class CursorRenderLayer extends BaseRenderLayer { return; } - this._bufferService.buffer.lines.get(cursorY)!.loadCell(this._bufferService.buffer.x, this._cell); + // in case cursor.x == cols adjust visual cursor to cols - 1 + const cursorX = Math.min(this._bufferService.buffer.x, this._bufferService.cols - 1); + this._bufferService.buffer.lines.get(cursorY)!.loadCell(cursorX, this._cell); if (this._cell.content === undefined) { return; } @@ -151,12 +153,12 @@ export class CursorRenderLayer extends BaseRenderLayer { this._ctx.fillStyle = this._colors.cursor.css; const cursorStyle = this._optionsService.options.cursorStyle; if (cursorStyle && cursorStyle !== 'block') { - this._cursorRenderers[cursorStyle](this._bufferService.buffer.x, viewportRelativeCursorY, this._cell); + this._cursorRenderers[cursorStyle](cursorX, viewportRelativeCursorY, this._cell); } else { - this._renderBlurCursor(this._bufferService.buffer.x, viewportRelativeCursorY, this._cell); + this._renderBlurCursor(cursorX, viewportRelativeCursorY, this._cell); } this._ctx.restore(); - this._state.x = this._bufferService.buffer.x; + this._state.x = cursorX; this._state.y = viewportRelativeCursorY; this._state.isFocused = false; this._state.style = cursorStyle; @@ -172,7 +174,7 @@ export class CursorRenderLayer extends BaseRenderLayer { if (this._state) { // The cursor is already in the correct spot, don't redraw - if (this._state.x === this._bufferService.buffer.x && + if (this._state.x === cursorX && this._state.y === viewportRelativeCursorY && this._state.isFocused === this._coreBrowserService.isFocused && this._state.style === this._optionsService.options.cursorStyle && @@ -183,10 +185,10 @@ export class CursorRenderLayer extends BaseRenderLayer { } this._ctx.save(); - this._cursorRenderers[this._optionsService.options.cursorStyle || 'block'](this._bufferService.buffer.x, viewportRelativeCursorY, this._cell); + this._cursorRenderers[this._optionsService.options.cursorStyle || 'block'](cursorX, viewportRelativeCursorY, this._cell); this._ctx.restore(); - this._state.x = this._bufferService.buffer.x; + this._state.x = cursorX; this._state.y = viewportRelativeCursorY; this._state.isFocused = false; this._state.style = this._optionsService.options.cursorStyle; diff --git a/src/browser/renderer/dom/DomRenderer.ts b/src/browser/renderer/dom/DomRenderer.ts index c2464d0e..f8ad717b 100644 --- a/src/browser/renderer/dom/DomRenderer.ts +++ b/src/browser/renderer/dom/DomRenderer.ts @@ -352,7 +352,7 @@ export class DomRenderer extends Disposable implements IRenderer { public renderRows(start: number, end: number): void { const cursorAbsoluteY = this._bufferService.buffer.ybase + this._bufferService.buffer.y; - const cursorX = this._bufferService.buffer.x; + const cursorX = Math.min(this._bufferService.buffer.x, this._bufferService.cols - 1); const cursorBlink = this._optionsService.options.cursorBlink; for (let y = start; y <= end; y++) { diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 4fb50ae3..bed7e883 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -1177,7 +1177,7 @@ declare module 'xterm' { /** * The x position of the cursor. This ranges between `0` (left side) and - * `Terminal.cols - 1` (right side). + * `Terminal.cols` (after last cell of the row). */ readonly cursorX: number;