diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 3086fd41..3fcc600a 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -856,13 +856,16 @@ export class SelectionManager extends EventEmitter implements ISelectionManager endRow--; } - // Adjust wrapped length value - while (wordPosition.start + wordPosition.length > this._terminal.cols) { - wordPosition.length -= this._terminal.cols; - endRow++; + // Adjust wrapped length value, this only needs to happen when values are reversed as in that + // case we're interested in the start of the word, not the end + if (!this._model.areSelectionValuesReversed()) { + while (wordPosition.start + wordPosition.length > this._terminal.cols) { + wordPosition.length -= this._terminal.cols; + endRow++; + } } - this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : (wordPosition.start + wordPosition.length), endRow]; + this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : wordPosition.start + wordPosition.length, endRow]; } } diff --git a/src/SelectionModel.ts b/src/SelectionModel.ts index a92ba933..b8e770b7 100644 --- a/src/SelectionModel.ts +++ b/src/SelectionModel.ts @@ -77,7 +77,7 @@ export class SelectionModel { } // Use the selection start if the end doesn't exist or they're reversed - if (!this.selectionEnd) { + if (!this.selectionEnd || this.areSelectionValuesReversed()) { const startPlusLength = this.selectionStart[0] + this.selectionStartLength; if (startPlusLength > this._terminal.cols) { return [startPlusLength % this._terminal.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._terminal.cols)];