From 58259f8bd965ec23fc8e07a588bb8a03c48ed895 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 30 Sep 2017 08:30:19 -0400 Subject: [PATCH] Fix select word on wide characters --- src/Buffer.ts | 4 ++-- src/SelectionManager.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index 9c5c717f..8922c3d6 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -228,10 +228,10 @@ export class Buffer implements IBuffer { // column indexes if (char[CHAR_DATA_WIDTH_INDEX] === 0) { if (startCol >= i) { - startIndex -= char[CHAR_DATA_CHAR_INDEX].length; + startIndex--; } if (endCol >= i) { - endIndex -= char[CHAR_DATA_CHAR_INDEX].length; + endIndex--; } } else { // Adjust the columns to take glyphs that are represented by multiple diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 9ba66efd..f8464d09 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -10,7 +10,7 @@ import { CircularList } from './utils/CircularList'; import { EventEmitter } from './EventEmitter'; import { ITerminal, ICircularList, ISelectionManager, IBuffer } from './Interfaces'; import { SelectionModel } from './SelectionModel'; -import { LineData } from './Types'; +import { LineData, CharData } from './Types'; import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from './Buffer'; /** @@ -611,7 +611,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager endCol++; } // Expand the string in both directions until a space is hit - while (startIndex > 0 && !this._isCharWordSeparator(bufferLine[startCol - 1][CHAR_DATA_CHAR_INDEX])) { + while (startIndex > 0 && !this._isCharWordSeparator(bufferLine[startCol - 1])) { const char = bufferLine[startCol - 1]; if (char[CHAR_DATA_WIDTH_INDEX] === 0) { // If the next character is a wide char, record it and skip the column @@ -625,7 +625,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager startIndex--; startCol--; } - while (endIndex + 1 < line.length && !this._isCharWordSeparator(bufferLine[endCol + 1][CHAR_DATA_CHAR_INDEX])) { + while (endIndex + 1 < line.length && !this._isCharWordSeparator(bufferLine[endCol + 1])) { const char = bufferLine[endCol + 1]; if (char[CHAR_DATA_WIDTH_INDEX] === 2) { // If the next character is a wide char, record it and skip the column @@ -674,8 +674,13 @@ export class SelectionManager extends EventEmitter implements ISelectionManager * word logic. * @param char The character to check. */ - private _isCharWordSeparator(char: string): boolean { - return WORD_SEPARATORS.indexOf(char) >= 0; + private _isCharWordSeparator(charData: CharData): boolean { + // Zero width characters are never separators as they are always to the + // right of wide characters + if (charData[CHAR_DATA_WIDTH_INDEX] === 0) { + return false; + } + return WORD_SEPARATORS.indexOf(charData[CHAR_DATA_CHAR_INDEX]) >= 0; } /**