From 3bd98ff182200e8f5bd0adaf988945aa446af32a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki & Nathan Sobo Date: Thu, 14 Feb 2013 17:30:08 -0700 Subject: [PATCH] Calculate pixel position of both bracket highlights before adding them Before, we were causing a layout to occur twice because we needed to read the DOM for the pixel position of the second highlight view after invalidating the DOM when adding the first highlight view. --- .../lib/bracket-matcher.coffee | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/packages/bracket-matcher/lib/bracket-matcher.coffee b/src/packages/bracket-matcher/lib/bracket-matcher.coffee index 8cf47f879..7aaae09ff 100644 --- a/src/packages/bracket-matcher/lib/bracket-matcher.coffee +++ b/src/packages/bracket-matcher/lib/bracket-matcher.coffee @@ -50,12 +50,23 @@ module.exports = else if previousPosition.isEqual(endPosition) editor.setCursorBufferPosition(startPosition) - createView: (editor, bufferPosition) -> - pixelPosition = editor.pixelPositionForBufferPosition(bufferPosition) + addHighlightViews: (editor, bufferRange) -> + { start, end } = Range.fromObject(bufferRange) + startPixelPosition = editor.pixelPositionForBufferPosition(start) + endPixelPosition = editor.pixelPositionForBufferPosition(end) + @addHighlightViewAtPixelPosition(editor, bufferPosition: start, pixelPosition: startPixelPosition) + @addHighlightViewAtPixelPosition(editor, bufferPosition: end, pixelPosition: endPixelPosition) + + addHighlightViewAtPixelPosition: (editor, {bufferPosition, pixelPosition}) -> view = $$ -> @div class: 'bracket-matcher' view.data('bufferPosition', bufferPosition) - view.css('top', pixelPosition.top).css('left', pixelPosition.left) - view.width(editor.charWidth).height(editor.lineHeight) + view.css( + top: pixelPosition.top + left: pixelPosition.left + width: editor.charWidth + height: editor.lineHeight + ) + editor.underlayer.append(view) findCurrentPair: (editor, buffer, matches) -> position = editor.getCursorBufferPosition() @@ -117,12 +128,7 @@ module.exports = matchPosition = @findMatchingStartPair(buffer, position, matchingPair, currentPair) if position? and matchPosition? - if position.isLessThan(matchPosition) - underlayer.append(@createView(editor, position)) - underlayer.append(@createView(editor, matchPosition)) - else - underlayer.append(@createView(editor, matchPosition)) - underlayer.append(@createView(editor, position)) + @addHighlightViews(editor, [position, matchPosition]) @pairHighlighted = true subscribeToEditSession: (editSession) ->