Clear timeout when select-list is cancelled

This commit is contained in:
Corey Johnson & Kevin Sawicki 2012-12-12 17:21:08 -08:00
parent f8dd51cab6
commit 6f6dfe78a9
3 changed files with 11 additions and 6 deletions

View File

@ -2,7 +2,6 @@ $ = require 'jquery'
{ View } = require 'space-pen'
Editor = require 'editor'
fuzzyFilter = require 'fuzzy-filter'
_ = require 'underscore'
module.exports =
class SelectList extends View
@ -16,6 +15,7 @@ class SelectList extends View
@viewClass: -> 'select-list'
maxItems: Infinity
scheduleTimeout: null
inputThrottle: 200
filteredArray: null
cancelling: false
@ -23,7 +23,7 @@ class SelectList extends View
initialize: ->
requireStylesheet 'select-list.css'
@miniEditor.getBuffer().on 'change', _.debounce((=> @populateList()), @inputThrottle)
@miniEditor.getBuffer().on 'change', => @schedulePopulateList()
@miniEditor.on 'focusout', => @cancel() unless @cancelling
@on 'core:move-up', => @selectPreviousItem()
@on 'core:move-down', => @selectNextItem()
@ -38,6 +38,10 @@ class SelectList extends View
@confirmSelection() if $(e.target).closest('li').hasClass('selected')
e.preventDefault()
schedulePopulateList: ->
clearTimeout(@scheduleTimeout)
@scheduleTimeout = setTimeout((=> @populateList()), @inputThrottle)
setArray: (@array) ->
@populateList()
@selectItem(@list.find('li:first'))
@ -59,7 +63,6 @@ class SelectList extends View
@loading.text(message).show()
populateList: ->
return unless @hasParent()
filterQuery = @miniEditor.getText()
if filterQuery.length
filteredArray = fuzzyFilter(@array, filterQuery, key: @filterKey)
@ -119,4 +122,4 @@ class SelectList extends View
@cancelled()
@detach()
@cancelling = false
clearTimeout(@scheduleTimeout)

View File

@ -20,7 +20,9 @@ class EventPalette extends SelectList
keyBindings: null
initialize: (@rootView) ->
@command 'event-palette:toggle', => @cancel()
@command 'event-palette:toggle', =>
@cancel()
false
super
attach: ->

View File

@ -41,8 +41,8 @@ class FuzzyFinder extends SelectList
else
return unless @rootView.project.getPath()?
@allowActiveEditorChange = false
@attach()
@populateProjectPaths()
@attach()
toggleBufferFinder: ->
if @hasParent()