mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 23:48:05 +03:00
Add move-down event to Autocomplete
This commit is contained in:
parent
f8fd7251e4
commit
904c05660d
@ -78,6 +78,24 @@ describe "Autocomplete", ->
|
||||
expect(editor.getCursorBufferPosition()).toEqual [5,11]
|
||||
expect(editor.getSelection().getBufferRange()).toEqual [[5,7], [5,11]]
|
||||
|
||||
describe 'move-up event', ->
|
||||
it 'replaces selection with previous match', ->
|
||||
editor.buffer.insert([10,0] ,"extra:t:extra")
|
||||
editor.setCursorBufferPosition([10,6])
|
||||
autocomplete.trigger "autocomplete:toggle"
|
||||
|
||||
autocomplete.trigger "move-up"
|
||||
expect(editor.lineForBufferRow(10)).toBe "extra:concat:extra"
|
||||
expect(autocomplete.find('li:eq(0)')).not.toHaveClass('selected')
|
||||
expect(autocomplete.find('li:eq(1)')).not.toHaveClass('selected')
|
||||
expect(autocomplete.find('li:eq(7)')).toHaveClass('selected')
|
||||
|
||||
autocomplete.trigger "move-up"
|
||||
expect(editor.lineForBufferRow(10)).toBe "extra:right:extra"
|
||||
expect(autocomplete.find('li:eq(0)')).not.toHaveClass('selected')
|
||||
expect(autocomplete.find('li:eq(7)')).not.toHaveClass('selected')
|
||||
expect(autocomplete.find('li:eq(6)')).toHaveClass('selected')
|
||||
|
||||
describe 'move-down event', ->
|
||||
it 'replaces selection with next match', ->
|
||||
editor.buffer.insert([10,0] ,"extra:s:extra")
|
||||
|
@ -20,6 +20,7 @@ class Autocomplete extends View
|
||||
initialize: (@editor) ->
|
||||
requireStylesheet 'autocomplete.css'
|
||||
@on 'autocomplete:toggle', => @toggle()
|
||||
@on 'move-up', => @previousMatch()
|
||||
@on 'move-down', => @nextMatch()
|
||||
@editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)
|
||||
|
||||
@ -45,6 +46,11 @@ class Autocomplete extends View
|
||||
@css {left: left, top: top + @editor.lineHeight}
|
||||
$(document.body).append(this)
|
||||
|
||||
previousMatch: ->
|
||||
previousIndex = @currentMatchIndex - 1
|
||||
previousIndex = @matches.length - 1 if previousIndex < 0
|
||||
@selectMatch(previousIndex)
|
||||
|
||||
nextMatch: ->
|
||||
nextIndex = (@currentMatchIndex + 1) % @matches.length
|
||||
@selectMatch(nextIndex)
|
||||
|
Loading…
Reference in New Issue
Block a user