From 7a9710b8c3c812a176904b3344157fc6a6592968 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 18 Jun 2014 13:47:38 -0700 Subject: [PATCH 1/4] Add fold markers to folded lines Fixes #2634 --- spec/editor-component-spec.coffee | 13 +++++++++++++ src/lines-component.coffee | 1 + 2 files changed, 14 insertions(+) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 7f4af3164..7a5ec468a 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -232,6 +232,19 @@ describe "EditorComponent", -> editor.setText("a\0b") expect(editor.pixelPositionForScreenPosition([0, Infinity]).left).toEqual 2 * charWidth + describe "when there is a fold", -> + it "renders a fold marker on the folded line", -> + foldedLineNode = component.lineNodeForScreenRow(4) + expect(foldedLineNode.querySelector('.fold-marker')).toBeFalsy() + + editor.foldBufferRow(4) + foldedLineNode = component.lineNodeForScreenRow(4) + expect(foldedLineNode.querySelector('.fold-marker')).toBeTruthy() + + editor.unfoldBufferRow(4) + foldedLineNode = component.lineNodeForScreenRow(4) + expect(foldedLineNode.querySelector('.fold-marker')).toBeFalsy() + describe "gutter rendering", -> [gutter] = [] diff --git a/src/lines-component.coffee b/src/lines-component.coffee index 70342d9c0..2f73ad9dc 100644 --- a/src/lines-component.coffee +++ b/src/lines-component.coffee @@ -121,6 +121,7 @@ LinesComponent = React.createClass else lineHTML += @buildLineInnerHTML(line) + lineHTML += '' if fold lineHTML += "" lineHTML From d5ea7665419bfd64b1df1982e12031c9f064425f Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 18 Jun 2014 14:07:06 -0700 Subject: [PATCH 2/4] Make click of fold marker unfold the row --- spec/editor-component-spec.coffee | 11 +++++++++++ src/editor-component.coffee | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 7a5ec468a..366b47b5f 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -1007,6 +1007,17 @@ describe "EditorComponent", -> nextAnimationFrame() expect(editor.getSelectedScreenRange()).toEqual [[2, 4], [6, 8]] + describe "when a line is folded", -> + beforeEach -> + editor.foldBufferRow 4 + + describe "when the folded line's fold-marker is clicked", -> + it "unfolds the buffer row", -> + target = component.lineNodeForScreenRow(4).querySelector '.fold-marker' + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([4, 8]), {target})) + expect(editor.isFoldedAtBufferRow 4).toBe false + + clientCoordinatesForScreenPosition = (screenPosition) -> positionOffset = editor.pixelPositionForScreenPosition(screenPosition) scrollViewClientRect = node.querySelector('.scroll-view').getBoundingClientRect() diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 282b5e913..7ddddd323 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -485,6 +485,11 @@ EditorComponent = React.createClass {detail, shiftKey, metaKey} = event screenPosition = @screenPositionForMouseEvent(event) + if event.target?.classList.contains('fold-marker') + bufferRow = editor.bufferRowForScreenRow(screenPosition.row) + editor.unfoldBufferRow(bufferRow) + return + if shiftKey editor.selectToScreenPosition(screenPosition) else if metaKey From 63587abe97943ce9cd36c568580954ee4897e09d Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 18 Jun 2014 14:21:03 -0700 Subject: [PATCH 3/4] Give fold markers a pointer on hover --- static/editor.less | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/static/editor.less b/static/editor.less index bf3da1930..990097d06 100644 --- a/static/editor.less +++ b/static/editor.less @@ -151,6 +151,10 @@ } } +.editor .fold-marker { + cursor: default; +} + .editor .fold-marker:after { .icon(0.8em, inline); content: @ellipsis; From 02757fc2de7babdd3d58fe5d33e85c7b63c4fb6b Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 18 Jun 2014 14:22:05 -0700 Subject: [PATCH 4/4] :lipstick: --- spec/editor-component-spec.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 366b47b5f..7153f18b5 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -1017,7 +1017,6 @@ describe "EditorComponent", -> linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([4, 8]), {target})) expect(editor.isFoldedAtBufferRow 4).toBe false - clientCoordinatesForScreenPosition = (screenPosition) -> positionOffset = editor.pixelPositionForScreenPosition(screenPosition) scrollViewClientRect = node.querySelector('.scroll-view').getBoundingClientRect()