Update editor component when a visible selection is removed

This commit is contained in:
Nathan Sobo
2014-04-01 17:11:10 -06:00
parent a55c329226
commit c4fdb54650
3 changed files with 13 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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.