提交 89824341 编写于 作者: A Alex Dima

Fixes #183: Jump to bracket should jump such that it matches the same bracket pair

上级 46863552
......@@ -492,23 +492,25 @@ export class OneCursorOp {
// -------------------- START handlers that simply change cursor state
public static jumpToBracket(cursor:OneCursor, ctx: IOneCursorOperationContext): boolean {
var bracketDecorations = cursor.getBracketsDecorations();
var len = bracketDecorations.length;
let bracketDecorations = cursor.getBracketsDecorations();
if (len !== 2) {
if (bracketDecorations.length !== 2) {
return false;
}
var position = cursor.getPosition();
let firstBracket = cursor.model.getDecorationRange(bracketDecorations[0]);
let secondBracket = cursor.model.getDecorationRange(bracketDecorations[1]);
for (var i = 0; i < 2; i++) {
var range = cursor.model.getDecorationRange(bracketDecorations[i]);
var otherRange = cursor.model.getDecorationRange(bracketDecorations[1 - i]);
let position = cursor.getPosition();
if (Utils.isPositionAtRangeEdges(position, range) || Utils.isPositionInsideRange(position, range)) {
cursor.moveModelPosition(false, otherRange.startLineNumber, otherRange.startColumn, 0, false);
return true;
}
if (Utils.isPositionAtRangeEdges(position, firstBracket) || Utils.isPositionInsideRange(position, firstBracket)) {
cursor.moveModelPosition(false, secondBracket.endLineNumber, secondBracket.endColumn, 0, false);
return true;
}
if (Utils.isPositionAtRangeEdges(position, secondBracket) || Utils.isPositionInsideRange(position, secondBracket)) {
cursor.moveModelPosition(false, firstBracket.endLineNumber, firstBracket.endColumn, 0, false);
return true;
}
return false;
......
......@@ -814,6 +814,31 @@ suite('Editor Controller - Cursor Configuration', () => {
var thisHighlighter = new ModelModes.CursorMode();
test('issue #183: jump to matching bracket position', () => {
let mode = new ModelModes.BracketMode();
let model = new Model.Model([
'var x = (3 + (5-7));'
].join('\n'), mode);
let cursor = new Cursor.Cursor(1, new MockConfiguration(null), model, null, false);
// ensure is tokenized
model.getLineContext(1);
moveTo(cursor, 1, 20);
cursorCommand(cursor, H.JumpToBracket, null, null, 'keyboard');
cursorEqual(cursor, 1, 10);
cursorCommand(cursor, H.JumpToBracket, null, null, 'keyboard');
cursorEqual(cursor, 1, 20);
cursorCommand(cursor, H.JumpToBracket, null, null, 'keyboard');
cursorEqual(cursor, 1, 10);
cursor.dispose();
model.dispose();
});
test('Cursor honors insertSpaces configuration on new line', () => {
var text = ' \tMy First Line\t \n' + '\tMy Second Line\n' + ' Third Line\n' + '\n' + '1';
var model = new Model.Model(text, thisHighlighter);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册