From a2f75c8337821a2983627cddd40a99bcb54f3236 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 14 Mar 2017 15:35:13 -0600 Subject: [PATCH] Toggle folds when clicking the arrow icon in the line number gutter --- spec/text-editor-component-spec.js | 13 +++++++++++++ src/text-editor-component.js | 12 ++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index c532c1518..cfd0e1afd 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -1145,6 +1145,19 @@ describe('TextEditorComponent', () => { ]) }) + it('toggles folding when clicking on the right icon of a foldable line number', async () => { + const {component, element, editor} = buildComponent() + const target = element.querySelectorAll('.line-number')[1].querySelector('.icon-right') + expect(editor.isFoldedAtScreenRow(1)).toBe(false) + + component.didMouseDownOnLineNumberGutter({target, button: 0, clientY: clientTopForLine(component, 1)}) + expect(editor.isFoldedAtScreenRow(1)).toBe(true) + await component.getNextUpdatePromise() + + component.didMouseDownOnLineNumberGutter({target, button: 0, clientY: clientTopForLine(component, 1)}) + expect(editor.isFoldedAtScreenRow(1)).toBe(false) + }) + it('autoscrolls the content when dragging near the edge of the screen', async () => { const {component, editor} = buildComponent({width: 200, height: 200}) const {scroller} = component.refs diff --git a/src/text-editor-component.js b/src/text-editor-component.js index aef4b9b54..5b59d0d24 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -813,17 +813,21 @@ class TextEditorComponent { } didMouseDownOnLineNumberGutter (event) { - if (global.debug) debugger - const {model} = this.props - const {button, ctrlKey, shiftKey, metaKey} = event + const {target, button, ctrlKey, shiftKey, metaKey} = event // Only handle mousedown events for left mouse button if (button !== 0) return - const addOrRemoveSelection = metaKey || (ctrlKey && this.getPlatform() !== 'darwin') const clickedScreenRow = this.screenPositionForMouseEvent(event).row const startBufferRow = model.bufferPositionForScreenPosition([clickedScreenRow, 0]).row + + if (target.matches('.foldable .icon-right')) { + model.toggleFoldAtBufferRow(startBufferRow) + return + } + + const addOrRemoveSelection = metaKey || (ctrlKey && this.getPlatform() !== 'darwin') const endBufferRow = model.bufferPositionForScreenPosition([clickedScreenRow, Infinity]).row const clickedLineBufferRange = Range(Point(startBufferRow, 0), Point(endBufferRow + 1, 0))