]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - atom/packages/vim-mode/lib/view-models/search-view-model.coffee
Remove taglist vim plugin
[rbdr/dotfiles] / atom / packages / vim-mode / lib / view-models / search-view-model.coffee
... / ...
CommitLineData
1{ViewModel} = require './view-model'
2
3module.exports =
4class SearchViewModel extends ViewModel
5 constructor: (@searchMotion) ->
6 super(@searchMotion, class: 'search')
7 @historyIndex = -1
8
9 atom.commands.add(@view.editorElement, 'core:move-up', @increaseHistorySearch)
10 atom.commands.add(@view.editorElement, 'core:move-down', @decreaseHistorySearch)
11
12 restoreHistory: (index) ->
13 @view.editorElement.getModel().setText(@history(index))
14
15 history: (index) ->
16 @vimState.getSearchHistoryItem(index)
17
18 increaseHistorySearch: =>
19 if @history(@historyIndex + 1)?
20 @historyIndex += 1
21 @restoreHistory(@historyIndex)
22
23 decreaseHistorySearch: =>
24 if @historyIndex <= 0
25 # get us back to a clean slate
26 @historyIndex = -1
27 @view.editorElement.getModel().setText('')
28 else
29 @historyIndex -= 1
30 @restoreHistory(@historyIndex)
31
32 confirm: (view) =>
33 repeatChar = if @searchMotion.initiallyReversed then '?' else '/'
34 if @view.value is '' or @view.value is repeatChar
35 lastSearch = @history(0)
36 if lastSearch?
37 @view.value = lastSearch
38 else
39 @view.value = ''
40 atom.beep()
41 super(view)
42 @vimState.pushSearchHistory(@view.value)
43
44 update: (reverse) ->
45 if reverse
46 @view.classList.add('reverse-search-input')
47 @view.classList.remove('search-input')
48 else
49 @view.classList.add('search-input')
50 @view.classList.remove('reverse-search-input')