mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Debounce filter input on select lists
This commit is contained in:
@@ -35,6 +35,8 @@ describe "SelectList", ->
|
||||
|
||||
it "filters the elements in the list based on the scoreElement function and selects the first item", ->
|
||||
miniEditor.insertText('la')
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li').length).toBe 2
|
||||
expect(list.find('li:contains(Alpha)')).toExist()
|
||||
expect(list.find('li:contains(Delta)')).toExist()
|
||||
@@ -44,11 +46,15 @@ describe "SelectList", ->
|
||||
|
||||
it "displays an error if there are no matches, removes error when there are matches", ->
|
||||
miniEditor.insertText('nothing will match this')
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li').length).toBe 0
|
||||
expect(selectList.error).not.toBeHidden()
|
||||
expect(selectList).toHaveClass("error")
|
||||
|
||||
miniEditor.setText('la')
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li').length).toBe 2
|
||||
expect(selectList.error).not.toBeVisible()
|
||||
expect(selectList).not.toHaveClass("error")
|
||||
@@ -109,6 +115,8 @@ describe "SelectList", ->
|
||||
describe "when there is no item selected (because the list is empty)", ->
|
||||
it "does not trigger the confirmed hook", ->
|
||||
miniEditor.insertText("i will never match anything")
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li')).not.toExist()
|
||||
miniEditor.trigger 'core:confirm'
|
||||
expect(selectList.confirmed).not.toHaveBeenCalled()
|
||||
|
||||
@@ -2,6 +2,7 @@ $ = require 'jquery'
|
||||
{ View } = require 'space-pen'
|
||||
Editor = require 'editor'
|
||||
fuzzyFilter = require 'fuzzy-filter'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class SelectList extends View
|
||||
@@ -15,13 +16,14 @@ class SelectList extends View
|
||||
@viewClass: -> 'select-list'
|
||||
|
||||
maxItems: Infinity
|
||||
inputThrottle: 50
|
||||
filteredArray: null
|
||||
cancelling: false
|
||||
|
||||
initialize: ->
|
||||
requireStylesheet 'select-list.css'
|
||||
|
||||
@miniEditor.getBuffer().on 'change', => @populateList()
|
||||
@miniEditor.getBuffer().on 'change', _.debounce((=> @populateList()), @inputThrottle)
|
||||
@miniEditor.on 'focusout', => @cancel() unless @cancelling
|
||||
@on 'core:move-up', => @selectPreviousItem()
|
||||
@on 'core:move-down', => @selectNextItem()
|
||||
|
||||
@@ -45,6 +45,8 @@ describe "OutlineView", ->
|
||||
|
||||
runs ->
|
||||
outlineView.miniEditor.setText("nothing will match this")
|
||||
window.advanceClock(outlineView.inputThrottle)
|
||||
|
||||
expect(rootView.find('.outline-view')).toExist()
|
||||
expect(outlineView.list.children('li').length).toBe 0
|
||||
expect(outlineView.error).toBeVisible()
|
||||
@@ -53,6 +55,8 @@ describe "OutlineView", ->
|
||||
|
||||
# Should remove error
|
||||
outlineView.miniEditor.setText("")
|
||||
window.advanceClock(outlineView.inputThrottle)
|
||||
|
||||
expect(outlineView.list.children('li').length).toBe 2
|
||||
expect(outlineView).not.toHaveClass "error"
|
||||
expect(outlineView.error).not.toBeVisible()
|
||||
|
||||
Reference in New Issue
Block a user