diff --git a/src/packages/bracket-matcher/lib/bracket-matcher.coffee b/src/packages/bracket-matcher/lib/bracket-matcher.coffee index 11398aad2..a08e49e43 100644 --- a/src/packages/bracket-matcher/lib/bracket-matcher.coffee +++ b/src/packages/bracket-matcher/lib/bracket-matcher.coffee @@ -30,6 +30,8 @@ module.exports = editor.on 'cursor:moved.bracket-matcher', => @updateMatch(editor) editor.command 'editor:go-to-matching-bracket.bracket-matcher', => @goToMatchingPair(editor) + editor.command 'editor:select-to-matching-bracket.bracket-matcher', => + @selectToMatchingPair(editor) editor.on 'editor:will-be-removed', => editor.off('.bracket-matcher') editor.startHighlightView = @addHighlightView(editor) editor.endHighlightView = @addHighlightView(editor) @@ -57,6 +59,24 @@ module.exports = else if previousPosition.isEqual(endPosition) editor.setCursorBufferPosition(startPosition) + selectToMatchingPair: (editor) -> + return unless @pairHighlighted + return unless underlayer = editor.getPane()?.find('.underlayer') + + position = editor.getCursorBufferPosition() + previousPosition = position.translate([0, -1]) + startPosition = underlayer.find('.bracket-matcher:first').data('bufferPosition') + endPosition = underlayer.find('.bracket-matcher:last').data('bufferPosition') + + if position.isEqual(startPosition) + editor.selectToScreenPosition(editor.screenPositionForBufferPosition(endPosition.translate([0, 1]))) + else if previousPosition.isEqual(startPosition) + editor.selectToScreenPosition(editor.screenPositionForBufferPosition(endPosition)) + else if position.isEqual(endPosition) + editor.selectToScreenPosition(editor.screenPositionForBufferPosition(startPosition.translate([0, 1]))) + else if previousPosition.isEqual(endPosition) + editor.selectToScreenPosition(editor.screenPositionForBufferPosition(startPosition)) + moveHighlightViews: (editor, bufferRange) -> { start, end } = Range.fromObject(bufferRange) startPixelPosition = editor.pixelPositionForBufferPosition(start) diff --git a/src/packages/bracket-matcher/spec/bracket-matcher-spec.coffee b/src/packages/bracket-matcher/spec/bracket-matcher-spec.coffee index 9a44ba3a7..58c971c6c 100644 --- a/src/packages/bracket-matcher/spec/bracket-matcher-spec.coffee +++ b/src/packages/bracket-matcher/spec/bracket-matcher-spec.coffee @@ -86,6 +86,17 @@ describe "bracket matching", -> editor.trigger "editor:go-to-matching-bracket" expect(editor.getCursorBufferPosition()).toEqual [0, 28] + describe "when editor:select-to-matching-bracket is triggered", -> + it " selects until the next matched bracket", -> + editor.moveCursorToEndOfLine() + editor.moveCursorLeft() + editor.trigger "editor:select-to-matching-bracket" + expect(editor.getCursorBufferPosition()).toEqual [12, 1] + selections = editor.getSelections() + expect(selections.length).toBe(1) + range = selections[0].getBufferRange() + expect(range).toEqual([[0,28], [12,1]]) + describe "matching bracket insertion", -> beforeEach -> editSession.buffer.setText("")