From 4799832a33521e2378ba4a56268679626e5e95fc Mon Sep 17 00:00:00 2001 From: Simon Lamon Date: Wed, 2 Mar 2022 16:17:31 +0000 Subject: [PATCH] Keep the initial wrapped line upon dragging --- src/browser/selection/SelectionModel.test.ts | 6 ++++++ src/browser/selection/SelectionModel.ts | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/browser/selection/SelectionModel.test.ts b/src/browser/selection/SelectionModel.test.ts index 410902d75..5ce3e316c 100644 --- a/src/browser/selection/SelectionModel.test.ts +++ b/src/browser/selection/SelectionModel.test.ts @@ -116,6 +116,12 @@ describe('SelectionModel', () => { model.selectionStartLength = 4; assert.deepEqual(model.finalSelectionEnd, [2, 3]); }); + it('should return the end on a different row when start + length overflows onto a following row with selectionEnd inbetween', () => { + model.selectionStart = [78, 2]; + model.selectionEnd = [79, 2]; + model.selectionStartLength = 4; + assert.deepEqual(model.finalSelectionEnd, [2, 3]); + }); it('should return selection end if selection end is after selection start + length', () => { model.selectionStart = [2, 2]; model.selectionStartLength = 2; diff --git a/src/browser/selection/SelectionModel.ts b/src/browser/selection/SelectionModel.ts index 1d84446a0..6c8abbfd2 100644 --- a/src/browser/selection/SelectionModel.ts +++ b/src/browser/selection/SelectionModel.ts @@ -92,7 +92,12 @@ export class SelectionModel { if (this.selectionStartLength) { // Select the larger of the two when start and end are on the same line if (this.selectionEnd[1] === this.selectionStart[1]) { - return [Math.max(this.selectionStart[0] + this.selectionStartLength, this.selectionEnd[0]), this.selectionEnd[1]]; + // Keep the whole wrapped word/line selected if the content wraps multiple lines + const startPlusLength = this.selectionStart[0] + this.selectionStartLength; + if (startPlusLength > this._bufferService.cols) { + return [startPlusLength % this._bufferService.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._bufferService.cols)]; + } + return [Math.max(startPlusLength, this.selectionEnd[0]), this.selectionEnd[1]]; } } return this.selectionEnd;