diff options
| author | Ben Beltran <ben@nsovocal.com> | 2015-07-10 11:12:25 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2015-07-10 11:12:25 -0500 |
| commit | 24c7594d62d8d7fbbcdb64b11ce4adc5d8e6991a (patch) | |
| tree | ded312222bb108923da1820ba40b04d710d20e5b /atom/packages/vim-mode/lib/view-models/search-view-model.coffee | |
| parent | eb786e82d170e2abc351a432ade616d6ecdeeb6b (diff) | |
Adds atom
Diffstat (limited to 'atom/packages/vim-mode/lib/view-models/search-view-model.coffee')
| -rw-r--r-- | atom/packages/vim-mode/lib/view-models/search-view-model.coffee | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/atom/packages/vim-mode/lib/view-models/search-view-model.coffee b/atom/packages/vim-mode/lib/view-models/search-view-model.coffee new file mode 100644 index 0000000..8787210 --- /dev/null +++ b/atom/packages/vim-mode/lib/view-models/search-view-model.coffee @@ -0,0 +1,42 @@ +{ViewModel} = require './view-model' + +module.exports = +class SearchViewModel extends ViewModel + constructor: (@searchMotion) -> + super(@searchMotion, class: 'search') + @historyIndex = -1 + + atom.commands.add(@view.editorElement, 'core:move-up', @increaseHistorySearch) + atom.commands.add(@view.editorElement, 'core:move-down', @decreaseHistorySearch) + + restoreHistory: (index) -> + @view.editorElement.getModel().setText(@history(index)) + + history: (index) -> + @vimState.getSearchHistoryItem(index) + + increaseHistorySearch: => + if @history(@historyIndex + 1)? + @historyIndex += 1 + @restoreHistory(@historyIndex) + + decreaseHistorySearch: => + if @historyIndex <= 0 + # get us back to a clean slate + @historyIndex = -1 + @view.editorElement.getModel().setText('') + else + @historyIndex -= 1 + @restoreHistory(@historyIndex) + + confirm: (view) => + repeatChar = if @searchMotion.initiallyReversed then '?' else '/' + if @view.value is '' or @view.value is repeatChar + lastSearch = @history(0) + if lastSearch? + @view.value = lastSearch + else + @view.value = '' + atom.beep() + super(view) + @vimState.pushSearchHistory(@view.value) |