Autocomplete preempts Editor move-up and move-down events and unsubscribes from Buffer change events when Editor is removed.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-18 15:56:09 -07:00
parent 6037d83f2b
commit a8d9d1690e
3 changed files with 43 additions and 15 deletions

View File

@@ -6,8 +6,7 @@ Range = require 'range'
module.exports =
class Autocomplete extends View
@content: ->
@div id: 'autocomplete', tabindex: -1, =>
@input class: 'hidden-input', outlet: 'hiddenInput'
@div id: 'autocomplete', =>
@ol outlet: 'matchesList'
editor: null
@@ -30,16 +29,10 @@ class Autocomplete extends View
@editor.on 'autocomplete:toggle', => @toggle()
@editor.on 'autocomplete:select', => @select()
@editor.on 'autocomplete:cancel', => @cancel()
@on 'move-up', => @previousMatch()
@on 'move-down', => @nextMatch()
@on 'focus', =>
@hiddenInput.focus()
false
@editor.on 'before-remove', => @currentBuffer?.off '.autocomplete'
setCurrentBuffer: (buffer) ->
@currentBuffer.off '.autocomplete' if @currentBuffer
@currentBuffer?.off '.autocomplete'
@currentBuffer = buffer
@buildWordList()
@@ -55,6 +48,14 @@ class Autocomplete extends View
if @parent()[0] then @detach() else @attach()
attach: ->
@editor.preempt 'move-up.autocomplete', =>
@previousMatch()
false
@editor.preempt 'move-down.autocomplete', =>
@nextMatch()
false
@editor.addClass('autocomplete')
@originalSelectedText = @editor.getSelectedText()
@originalSelectionBufferRange = @editor.getSelection().getBufferRange()
@@ -68,6 +69,7 @@ class Autocomplete extends View
@focus()
detach: ->
@editor.off(".autocomplete")
@editor.removeClass('autocomplete')
super

View File

@@ -519,6 +519,8 @@ class Editor extends View
remove: (selector, keepData) ->
return super if keepData
@trigger 'before-remove'
@unsubscribeFromBuffer()
rootView = @rootView()
if @pane() then @pane().remove() else super