From 2865d935b646a43b2dbaa7f8e5f176b4d2f90518 Mon Sep 17 00:00:00 2001 From: Bruno Ribeito Date: Tue, 7 Nov 2017 21:21:44 +0000 Subject: [PATCH] Adress feedback --- fixtures/typings-test/typings-test.ts | 2 ++ src/SelectionManager.test.ts | 2 +- src/SelectionManager.ts | 13 +++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fixtures/typings-test/typings-test.ts b/fixtures/typings-test/typings-test.ts index 9d73535e..d61b22f2 100644 --- a/fixtures/typings-test/typings-test.ts +++ b/fixtures/typings-test/typings-test.ts @@ -143,6 +143,7 @@ namespace methods_core { const r20: string = t.getOption('bellStyle'); const r21: boolean = t.getOption('enableBold'); const r22: number = t.getOption('letterSpacing'); + const r23: boolean = t.getOption('rightClickSelectsWord'); } { const t: Terminal = new Terminal(); @@ -177,6 +178,7 @@ namespace methods_core { t.setOption('lineHeight', 1); t.setOption('fontFamily', 'foo'); t.setOption('theme', {background: '#ff0000'}); + t.setOption('rightClickSelectsWord', false); } } namespace scrolling { diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index 8c6ea3e1..e229889e 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -26,7 +26,7 @@ class TestSelectionManager extends SelectionManager { public get model(): SelectionModel { return this._model; } public selectLineAt(line: number): void { this._selectLineAt(line); } - public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords); } + public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords, true); } // Disable DOM interaction public enable(): void {} diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 87b71a12..1fccc8b1 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -250,7 +250,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager } /** - * Selects word at the current mouse event coordenates. + * Selects word at the current mouse event coordinates. * @param event The mouse event. */ public selectWordAtCursor(event: MouseEvent): void { @@ -590,7 +590,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager * Gets positional information for the word at the coordinated specified. * @param coords The coordinates to get the word at. */ - private _getWordAt(coords: [number, number], selectWhiteSpace: boolean): IWordPosition { + private _getWordAt(coords: [number, number], allowWhitespaceOnlySelection: boolean): IWordPosition { const bufferLine = this._buffer.lines.get(coords[1]); if (!bufferLine) { return null; @@ -696,8 +696,9 @@ export class SelectionManager extends EventEmitter implements ISelectionManager - leftLongCharOffset // The number of additional chars left of the initial char added by columns with strings longer than 1 (emojis) - rightLongCharOffset); // The number of additional chars right of the initial char (inclusive) added by columns with strings longer than 1 (emojis) - if (!selectWhiteSpace && line.slice(startIndex, endIndex).trim() === '') + if (!allowWhitespaceOnlySelection && line.slice(startIndex, endIndex).trim() === '') { return null; + } return { start, length }; } @@ -705,10 +706,10 @@ export class SelectionManager extends EventEmitter implements ISelectionManager /** * Selects the word at the coordinates specified. * @param coords The coordinates to get the word at. - * @param selectWhiteSpace If whitespace should be selected + * @param allowWhitespaceOnlySelection If whitespace should be selected */ - protected _selectWordAt(coords: [number, number], selectWhiteSpace: boolean): void { - const wordPosition = this._getWordAt(coords, selectWhiteSpace); + protected _selectWordAt(coords: [number, number], allowWhitespaceOnlySelection: boolean): void { + const wordPosition = this._getWordAt(coords, allowWhitespaceOnlySelection); if (wordPosition) { this._model.selectionStart = [wordPosition.start, coords[1]]; this._model.selectionStartLength = wordPosition.length;