diff --git a/src/browser/selection/SelectionModel.test.ts b/src/browser/selection/SelectionModel.test.ts index c15cdd29..410902d7 100644 --- a/src/browser/selection/SelectionModel.test.ts +++ b/src/browser/selection/SelectionModel.test.ts @@ -122,5 +122,13 @@ describe('SelectionModel', () => { model.selectionEnd = [5, 2]; assert.deepEqual(model.finalSelectionEnd, [5, 2]); }); + it('should not include a trailing EOL when the selection ends at the end of a line', () => { + model.selectionStart = [0, 0]; + model.selectionStartLength = 80; + assert.deepEqual(model.finalSelectionEnd, [80, 0]); + model.selectionStart = [0, 0]; + model.selectionStartLength = 160; + assert.deepEqual(model.finalSelectionEnd, [80, 1]); + }); }); }); diff --git a/src/browser/selection/SelectionModel.ts b/src/browser/selection/SelectionModel.ts index 1420444e..1d84446a 100644 --- a/src/browser/selection/SelectionModel.ts +++ b/src/browser/selection/SelectionModel.ts @@ -79,6 +79,10 @@ export class SelectionModel { if (!this.selectionEnd || this.areSelectionValuesReversed()) { const startPlusLength = this.selectionStart[0] + this.selectionStartLength; if (startPlusLength > this._bufferService.cols) { + // Ensure the trailing EOL isn't included when the selection ends on the right edge + if (startPlusLength % this._bufferService.cols === 0) { + return [this._bufferService.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._bufferService.cols) - 1]; + } return [startPlusLength % this._bufferService.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._bufferService.cols)]; } return [startPlusLength, this.selectionStart[1]];