From 8c94c97a283e816242523f5d723a1c567aa7f3fe Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 21 Dec 2021 10:49:58 -0800 Subject: [PATCH] Don't include trailing EOL when selecting multiple lines Fixes #3552 --- src/browser/selection/SelectionModel.test.ts | 8 ++++++++ src/browser/selection/SelectionModel.ts | 4 ++++ 2 files changed, 12 insertions(+) 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]];