From c4fdb54650e7c3e3dafcf17d7ff103ede6672fa0 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 1 Apr 2014 17:11:10 -0600 Subject: [PATCH] Update editor component when a visible selection is removed --- spec/editor-component-spec.coffee | 10 ++++++++-- src/editor-component.coffee | 4 ++++ src/editor.coffee | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index b89b782e5..437f7c913 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -53,8 +53,8 @@ describe "EditorComponent", -> expect(cursorNodes[0].offsetTop).toBe 0 expect(cursorNodes[0].offsetLeft).toBe 5 * charWidth - cursor3 = editor.addCursorAtScreenPosition([6, 11]) - cursor2 = editor.addCursorAtScreenPosition([4, 10]) + cursor2 = editor.addCursorAtScreenPosition([6, 11]) + cursor3 = editor.addCursorAtScreenPosition([4, 10]) cursorNodes = node.querySelectorAll('.cursor') expect(cursorNodes.length).toBe 2 @@ -72,3 +72,9 @@ describe "EditorComponent", -> expect(cursorNodes[0].offsetLeft).toBe 11 * charWidth expect(cursorNodes[1].offsetTop).toBe 4 * lineHeight expect(cursorNodes[1].offsetLeft).toBe 10 * charWidth + + cursor3.destroy() + cursorNodes = node.querySelectorAll('.cursor') + expect(cursorNodes.length).toBe 1 + expect(cursorNodes[0].offsetTop).toBe 6 * lineHeight + expect(cursorNodes[0].offsetLeft).toBe 11 * charWidth diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 3a6c5b46a..bba079a3f 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -65,6 +65,7 @@ EditorCompont = React.createClass {editor} = @props @subscribe editor, 'screen-lines-changed', @onScreenLinesChanged @subscribe editor, 'selection-added', @onSelectionAdded + @subscribe editor, 'selection-removed', @onSelectionAdded @updateAllDimensions() @props.editor.setVisible(true) @@ -104,6 +105,9 @@ EditorCompont = React.createClass onSelectionAdded: (selection) -> @forceUpdate() if @selectionIntersectsVisibleRowRange(selection) + onSelectionRemoved: (selection) -> + @forceUpdate() if @selectionIntersectsVisibleRowRange(selection) + getVisibleRowRange: -> return [0, 0] unless @state.lineHeight > 0 diff --git a/src/editor.coffee b/src/editor.coffee index 24aa7873a..8c389b312 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -1202,6 +1202,7 @@ class Editor extends Model # Remove the given selection. removeSelection: (selection) -> _.remove(@selections, selection) + @emit 'selection-removed', selection # Reduce one or more selections to a single empty selection based on the most # recently added cursor.