mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Clear timeout when select-list is cancelled
This commit is contained in:
parent
f8dd51cab6
commit
6f6dfe78a9
@ -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)
|
||||
|
@ -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: ->
|
||||
|
@ -41,8 +41,8 @@ class FuzzyFinder extends SelectList
|
||||
else
|
||||
return unless @rootView.project.getPath()?
|
||||
@allowActiveEditorChange = false
|
||||
@attach()
|
||||
@populateProjectPaths()
|
||||
@attach()
|
||||
|
||||
toggleBufferFinder: ->
|
||||
if @hasParent()
|
||||
|
Loading…
Reference in New Issue
Block a user