selectionManager.selectWordAt([14, 0]);
assert.equal(selectionManager.selectionText, 'foo');
});
+ it('should select up to non-path characters that are commonly adjacent to paths', () => {
+ buffer.push(stringToRow(':ab:(cd)[ef]{gh}'));
+ selectionManager.selectWordAt([0, 0]);
+ assert.equal(selectionManager.selectionText, ':ab');
+ selectionManager.selectWordAt([1, 0]);
+ assert.equal(selectionManager.selectionText, 'ab');
+ selectionManager.selectWordAt([2, 0]);
+ assert.equal(selectionManager.selectionText, 'ab');
+ selectionManager.selectWordAt([3, 0]);
+ assert.equal(selectionManager.selectionText, 'ab:');
+ selectionManager.selectWordAt([4, 0]);
+ assert.equal(selectionManager.selectionText, '(cd');
+ selectionManager.selectWordAt([5, 0]);
+ assert.equal(selectionManager.selectionText, 'cd');
+ selectionManager.selectWordAt([6, 0]);
+ assert.equal(selectionManager.selectionText, 'cd');
+ selectionManager.selectWordAt([7, 0]);
+ assert.equal(selectionManager.selectionText, 'cd)');
+ selectionManager.selectWordAt([8, 0]);
+ assert.equal(selectionManager.selectionText, '[ef');
+ selectionManager.selectWordAt([9, 0]);
+ assert.equal(selectionManager.selectionText, 'ef');
+ selectionManager.selectWordAt([10, 0]);
+ assert.equal(selectionManager.selectionText, 'ef');
+ selectionManager.selectWordAt([11, 0]);
+ assert.equal(selectionManager.selectionText, 'ef]');
+ selectionManager.selectWordAt([12, 0]);
+ assert.equal(selectionManager.selectionText, '{gh');
+ selectionManager.selectWordAt([13, 0]);
+ assert.equal(selectionManager.selectionText, 'gh');
+ selectionManager.selectWordAt([14, 0]);
+ assert.equal(selectionManager.selectionText, 'gh');
+ selectionManager.selectWordAt([15, 0]);
+ assert.equal(selectionManager.selectionText, 'gh}');
+ });
});
describe('_selectLineAt', () => {
*/
const CLEAR_MOUSE_DISTANCE = 10;
+/**
+ * A string containing all characters that are considered word separated by the
+ * double click to select work logic.
+ */
+const WORD_SEPARATORS = ' ()[]{}:';
+
// TODO: Move these constants elsewhere, they belong in a buffer or buffer
// data/line class.
const LINE_DATA_CHAR_INDEX = 1;
endCol++;
}
// Expand the string in both directions until a space is hit
- while (startIndex > 0 && line.charAt(startIndex - 1) !== ' ') {
+ while (startIndex > 0 && !this._isCharWordSeparator(line.charAt(startIndex - 1))) {
if (bufferLine[startCol - 1][LINE_DATA_WIDTH_INDEX] === 0) {
// If the next character is a wide char, record it and skip the column
leftWideCharCount++;
startIndex--;
startCol--;
}
- while (endIndex + 1 < line.length && line.charAt(endIndex + 1) !== ' ') {
+ while (endIndex + 1 < line.length && !this._isCharWordSeparator(line.charAt(endIndex + 1))) {
if (bufferLine[endCol + 1][LINE_DATA_WIDTH_INDEX] === 2) {
// If the next character is a wide char, record it and skip the column
rightWideCharCount++;
this._model.selectionStartLength = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1/*include endIndex char*/, this._terminal.cols);
}
+ /**
+ * Gets whether the character is considered a word separator by the select
+ * word logic.
+ * @param char The character to check.
+ */
+ private _isCharWordSeparator(char: string): boolean {
+ return WORD_SEPARATORS.indexOf(char) >= 0;
+ }
+
/**
* Selects the line specified.
* @param line The line index.