1 {ViewModel} = require './view-model'
4 class SearchViewModel extends ViewModel
5 constructor: (@searchMotion) ->
6 super(@searchMotion, class: 'search')
9 atom.commands.add(@view.editorElement, 'core:move-up', @increaseHistorySearch)
10 atom.commands.add(@view.editorElement, 'core:move-down', @decreaseHistorySearch)
12 restoreHistory: (index) ->
13 @view.editorElement.getModel().setText(@history(index))
16 @vimState.getSearchHistoryItem(index)
18 increaseHistorySearch: =>
19 if @history(@historyIndex + 1)?
21 @restoreHistory(@historyIndex)
23 decreaseHistorySearch: =>
25 # get us back to a clean slate
27 @view.editorElement.getModel().setText('')
30 @restoreHistory(@historyIndex)
33 repeatChar = if @searchMotion.initiallyReversed then '?' else '/'
34 if @view.value is '' or @view.value is repeatChar
35 lastSearch = @history(0)
37 @view.value = lastSearch
42 @vimState.pushSearchHistory(@view.value)