diff options
author | Alex Dima <alexdima@microsoft.com> | 2016-03-10 17:04:55 +0300 |
---|---|---|
committer | Alex Dima <alexdima@microsoft.com> | 2016-03-11 18:06:10 +0300 |
commit | f291f4ad600767626b24a4b15816b04bee9a3049 (patch) | |
tree | 371d5c45e56b9290f5cb3c7108308f1913a999a1 | |
parent | ed5e46058daf49b69e9c0ad50267ec4a64609be1 (diff) |
Fixes #3894: findPrevBracketInToken reported incorrect range for bracket match0.10.11-insiders0.10.11
-rw-r--r-- | src/vs/editor/common/modes/supports/richEditBrackets.ts | 4 | ||||
-rw-r--r-- | src/vs/editor/test/common/modes/supports/richEditBrackets.test.ts | 75 |
2 files changed, 77 insertions, 2 deletions
diff --git a/src/vs/editor/common/modes/supports/richEditBrackets.ts b/src/vs/editor/common/modes/supports/richEditBrackets.ts index 40f16ae2411..a684e74f3d6 100644 --- a/src/vs/editor/common/modes/supports/richEditBrackets.ts +++ b/src/vs/editor/common/modes/supports/richEditBrackets.ts @@ -121,11 +121,11 @@ export class BracketsUtils { return null; } - let matchOffset = reversedText.length - 1 - m.index; + let matchOffset = reversedText.length - m.index; let matchLength = m[0].length; let absoluteMatchOffset = offset + matchOffset; - return new Range(lineNumber, absoluteMatchOffset + 1, lineNumber, absoluteMatchOffset + 1 + matchLength); + return new Range(lineNumber, absoluteMatchOffset - matchLength + 1, lineNumber, absoluteMatchOffset + 1); } public static findPrevBracketInToken(reversedBracketRegex:RegExp, lineNumber:number, lineText:string, currentTokenStart:number, currentTokenEnd:number): Range { diff --git a/src/vs/editor/test/common/modes/supports/richEditBrackets.test.ts b/src/vs/editor/test/common/modes/supports/richEditBrackets.test.ts new file mode 100644 index 00000000000..2c7a5696357 --- /dev/null +++ b/src/vs/editor/test/common/modes/supports/richEditBrackets.test.ts @@ -0,0 +1,75 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import * as assert from 'assert'; +import {BracketsUtils} from 'vs/editor/common/modes/supports/richEditBrackets'; +import {IEditorRange} from 'vs/editor/common/editorCommon'; + +suite('richEditBrackets', () => { + + function findPrevBracketInToken(reversedBracketRegex:RegExp, lineText:string, currentTokenStart:number, currentTokenEnd:number): IEditorRange { + return BracketsUtils.findPrevBracketInToken(reversedBracketRegex, 1, lineText, currentTokenStart, currentTokenEnd); + } + + function findNextBracketInToken(forwardBracketRegex:RegExp, lineText:string, currentTokenStart:number, currentTokenEnd:number): IEditorRange { + return BracketsUtils.findNextBracketInToken(forwardBracketRegex, 1, lineText, currentTokenStart, currentTokenEnd); + } + + test('findPrevBracketInToken one char 1', () => { + let result = findPrevBracketInToken(/(\{)|(\})/i, '{', 0, 1); + assert.equal(result.startColumn, 1); + assert.equal(result.endColumn, 2); + }); + + test('findPrevBracketInToken one char 2', () => { + let result = findPrevBracketInToken(/(\{)|(\})/i, '{{', 0, 1); + assert.equal(result.startColumn, 1); + assert.equal(result.endColumn, 2); + }); + + test('findPrevBracketInToken one char 3', () => { + let result = findPrevBracketInToken(/(\{)|(\})/i, '{hello world!', 0, 13); + assert.equal(result.startColumn, 1); + assert.equal(result.endColumn, 2); + }); + + test('findPrevBracketInToken more chars 1', () => { + let result = findPrevBracketInToken(/(olleh)/i, 'hello world!', 0, 12); + assert.equal(result.startColumn, 1); + assert.equal(result.endColumn, 6); + }); + + test('findPrevBracketInToken more chars 2', () => { + let result = findPrevBracketInToken(/(olleh)/i, 'hello world!', 0, 5); + assert.equal(result.startColumn, 1); + assert.equal(result.endColumn, 6); + }); + + test('findPrevBracketInToken more chars 3', () => { + let result = findPrevBracketInToken(/(olleh)/i, ' hello world!', 0, 6); + assert.equal(result.startColumn, 2); + assert.equal(result.endColumn, 7); + }); + + test('findNextBracketInToken one char', () => { + let result = findNextBracketInToken(/(\{)|(\})/i, '{', 0, 1); + assert.equal(result.startColumn, 1); + assert.equal(result.endColumn, 2); + }); + + test('findNextBracketInToken more chars', () => { + let result = findNextBracketInToken(/(world)/i, 'hello world!', 0, 12); + assert.equal(result.startColumn, 7); + assert.equal(result.endColumn, 12); + }); + + test('issue #3894: [Handlebars] Curly braces edit issues', () => { + let result = findPrevBracketInToken(/(\-\-!<)|(>\-\-)|(\{\{)|(\}\})/i, '{{asd}}', 0, 2); + assert.equal(result.startColumn, 1); + assert.equal(result.endColumn, 3); + }); + +});
\ No newline at end of file |