Skip to content

Commit

Permalink
Merge pull request #3860 from Tyriar/3855
Browse files Browse the repository at this point in the history
Fix column selection issues
  • Loading branch information
Tyriar authored Jun 14, 2022
2 parents fe99422 + efb939d commit 1bb465d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions addons/xterm-addon-webgl/src/WebglRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,12 @@ export class WebglRenderer extends Disposable implements IRenderer {
}
y -= this._terminal.buffer.active.viewportY;
if (this._model.selection.columnSelectMode) {
return x >= this._model.selection.startCol && y >= this._model.selection.viewportCappedStartRow &&
x < this._model.selection.endCol && y < this._model.selection.viewportCappedEndRow;
if (this._model.selection.startCol <= this._model.selection.endCol) {
return x >= this._model.selection.startCol && y >= this._model.selection.viewportCappedStartRow &&
x < this._model.selection.endCol && y <= this._model.selection.viewportCappedEndRow;
}
return x < this._model.selection.startCol && y >= this._model.selection.viewportCappedStartRow &&
x >= this._model.selection.endCol && y <= this._model.selection.viewportCappedEndRow;
}
return (y > this._model.selection.viewportStartRow && y < this._model.selection.viewportEndRow) ||
(this._model.selection.viewportStartRow === this._model.selection.viewportEndRow && y === this._model.selection.viewportStartRow && x >= this._model.selection.startCol && x < this._model.selection.endCol) ||
Expand Down
3 changes: 2 additions & 1 deletion src/browser/renderer/dom/DomRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ export class DomRenderer extends Disposable implements IRenderer {
const documentFragment = document.createDocumentFragment();

if (columnSelectMode) {
const isXFlipped = start[0] > end[0];
documentFragment.appendChild(
this._createSelectionElement(viewportCappedStartRow, start[0], end[0], viewportCappedEndRow - viewportCappedStartRow + 1)
this._createSelectionElement(viewportCappedStartRow, isXFlipped ? end[0] : start[0], isXFlipped ? start[0] : end[0], viewportCappedEndRow - viewportCappedStartRow + 1)
);
} else {
// Draw first row
Expand Down
8 changes: 6 additions & 2 deletions src/browser/renderer/dom/DomRendererRowFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,12 @@ export class DomRendererRowFactory {
return false;
}
if (this._columnSelectMode) {
return x >= start[0] && y >= start[1] &&
x < end[0] && y < end[1];
if (start[0] <= end[0]) {
return x >= start[0] && y >= start[1] &&
x < end[0] && y <= end[1];
}
return x < start[0] && y >= start[1] &&
x >= end[0] && y <= end[1];
}
return (y > start[1] && y < end[1]) ||
(start[1] === end[1] && y === start[1] && x >= start[0] && x < end[0]) ||
Expand Down
6 changes: 5 additions & 1 deletion src/browser/services/SelectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ export class SelectionService extends Disposable implements ISelectionService {
return '';
}

// For column selection it's not enough to rely on final selection's swapping of reversed
// values, it also needs the x coordinates to swap independently of the y coordinate is needed
const startCol = start[0] < end[0] ? start[0] : end[0];
const endCol = start[0] < end[0] ? end[0] : start[0];
for (let i = start[1]; i <= end[1]; i++) {
const lineText = buffer.translateBufferLineToString(i, true, start[0], end[0]);
const lineText = buffer.translateBufferLineToString(i, true, startCol, endCol);
result.push(lineText);
}
} else {
Expand Down

0 comments on commit 1bb465d

Please sign in to comment.