From 7be5553ba136a4128b6ba5f6187aa12672839cb5 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 9 Jul 2014 09:48:25 -0700 Subject: [PATCH] Index line decorations by ids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And don’t use _.deepContains --- src/editor-component.coffee | 4 ++-- src/gutter-component.coffee | 14 +++++++++----- src/lines-component.coffee | 14 +++++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 7953af570..ea2a7f5ec 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -295,8 +295,8 @@ EditorComponent = React.createClass else continue if decorationParams.onlyEmpty - decorationsByScreenRow[screenRow] ?= [] - decorationsByScreenRow[screenRow].push decorationParams + decorationsByScreenRow[screenRow] ?= {} + decorationsByScreenRow[screenRow][decoration.id] = decorationParams decorationsByScreenRow diff --git a/src/gutter-component.coffee b/src/gutter-component.coffee index cf2f5e486..4a88ac3fa 100644 --- a/src/gutter-component.coffee +++ b/src/gutter-component.coffee @@ -154,7 +154,7 @@ GutterComponent = React.createClass classes = '' if lineDecorations? and decorations = lineDecorations[screenRow] - for decoration in decorations + for id, decoration of decorations if Decoration.isType(decoration, 'gutter') classes += decoration.class + ' ' @@ -186,12 +186,13 @@ GutterComponent = React.createClass previousDecorations = @renderedDecorationsByLineNumberId[lineNumberId] if previousDecorations? - for decoration in previousDecorations - node.classList.remove(decoration.class) if Decoration.isType(decoration, 'gutter') and not _.deepContains(decorations, decoration) + for id, decoration of previousDecorations + if Decoration.isType(decoration, 'gutter') and not @hasDecoration(decorations, decoration) + node.classList.remove(decoration.class) if decorations? - for decoration in decorations - if Decoration.isType(decoration, 'gutter') and not _.deepContains(previousDecorations, decoration) + for id, decoration of decorations + if Decoration.isType(decoration, 'gutter') and not @hasDecoration(previousDecorations, decoration) node.classList.add(decoration.class) unless @screenRowsByLineNumberId[lineNumberId] is screenRow @@ -201,6 +202,9 @@ GutterComponent = React.createClass @screenRowsByLineNumberId[lineNumberId] = screenRow @lineNumberIdsByScreenRow[screenRow] = lineNumberId + hasDecoration: (decorations, decoration) -> + decorations? and decorations[decoration.id] == decoration + hasLineNumberNode: (lineNumberId) -> @lineNumberNodesById.hasOwnProperty(lineNumberId) diff --git a/src/lines-component.coffee b/src/lines-component.coffee index 06d598bf2..1ecc12e3a 100644 --- a/src/lines-component.coffee +++ b/src/lines-component.coffee @@ -135,7 +135,7 @@ LinesComponent = React.createClass classes = '' if decorations = lineDecorations[screenRow] - for decoration in decorations + for id, decoration of decorations if Decoration.isType(decoration, 'line') classes += decoration.class + ' ' classes += 'line' @@ -240,12 +240,13 @@ LinesComponent = React.createClass previousDecorations = @renderedDecorationsByLineId[line.id] if previousDecorations? - for decoration in previousDecorations - lineNode.classList.remove(decoration.class) if Decoration.isType(decoration, 'line') and not _.deepContains(decorations, decoration) + for id, decoration of previousDecorations + if Decoration.isType(decoration, 'line') and not @hasDecoration(decorations, decoration) + lineNode.classList.remove(decoration.class) if decorations? - for decoration in decorations - if Decoration.isType(decoration, 'line') and not _.deepContains(previousDecorations, decoration) + for id, decoration of decorations + if Decoration.isType(decoration, 'line') and not @hasDecoration(previousDecorations, decoration) lineNode.classList.add(decoration.class) lineNode.style.width = lineWidth + 'px' if updateWidth @@ -256,6 +257,9 @@ LinesComponent = React.createClass @screenRowsByLineId[line.id] = screenRow @lineIdsByScreenRow[screenRow] = line.id + hasDecoration: (decorations, decoration) -> + decorations? and decorations[decoration.id] == decoration + lineNodeForScreenRow: (screenRow) -> @lineNodesByLineId[@lineIdsByScreenRow[screenRow]]