From a2b90cd5015afc35f98e772122441442bee101d2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 25 Jun 2014 19:55:55 -0600 Subject: [PATCH] Add 'onlyHead' option for decorations It only decorates the head position of the decoration's marker. --- spec/editor-component-spec.coffee | 10 +++++++++- src/editor-component.coffee | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index b9335c697..099444ee4 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -324,7 +324,7 @@ describe "EditorComponent", -> editor.addDecorationForMarker(marker, decoration) runSetImmediateCallbacks() - it "does not render off-screen lines with line number classes until they are with in the rendered row range", -> + it "does not render off-screen lines with decoration classes until they are with in the rendered row range", -> node.style.height = 4.5 * lineHeightInPixels + 'px' component.measureScrollView() runSetImmediateCallbacks() @@ -348,6 +348,14 @@ describe "EditorComponent", -> expect(lineHasClass(3, 'someclass')).toBe true expect(lineHasClass(4, 'someclass')).toBe false + it "only renders 'onlyHead' decorations on lines containing the marker's head", -> + editor.addDecorationForMarker(marker, type: 'line', class: 'only-head', onlyHead: true) + runSetImmediateCallbacks() + expect(lineHasClass(1, 'only-head')).toBe false + expect(lineHasClass(2, 'only-head')).toBe false + expect(lineHasClass(3, 'only-head')).toBe true + expect(lineHasClass(4, 'only-head')).toBe false + it "removes line classes when a decoration's marker is invalidated", -> editor.getBuffer().insert([3, 2], 'n') runSetImmediateCallbacks() diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 86b3abaad..f005fea85 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -262,14 +262,17 @@ EditorComponent = React.createClass for markerId, decorations of decorationsByMarkerId marker = editor.getMarker(markerId) screenRange = null + headScreenRow = null if marker.isValid() for decoration in decorations if editor.decorationMatchesType(decoration, 'gutter') or editor.decorationMatchesType(decoration, 'line') screenRange ?= marker.getScreenRange() + headScreenRow ?= marker.getHeadScreenPosition().row startRow = screenRange.start.row endRow = screenRange.end.row endRow-- if not screenRange.isEmpty() and screenRange.end.column == 0 for screenRow in [startRow..endRow] + continue if decoration.onlyHead and screenRow isnt headScreenRow decorationsByScreenRow[screenRow] ?= [] decorationsByScreenRow[screenRow].push decoration