aboutsummaryrefslogtreecommitdiff
path: root/atom/packages/ex-mode/lib/ex-view-model.coffee
blob: 0c99be9e3bbbb18be1b6e0bccd7d2694581e3648 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{ViewModel, Input} = require './view-model'

module.exports =
class ExViewModel extends ViewModel
  constructor: (@exCommand) ->
    super(@exCommand, class: 'command')
    @historyIndex = -1

    atom.commands.add(@view.editorElement, 'core:move-up', @increaseHistoryEx)
    atom.commands.add(@view.editorElement, 'core:move-down', @decreaseHistoryEx)

  restoreHistory: (index) ->
    @view.editorElement.getModel().setText(@history(index).value)

  history: (index) ->
    @exState.getExHistoryItem(index)

  increaseHistoryEx: =>
    if @history(@historyIndex + 1)?
      @historyIndex += 1
      @restoreHistory(@historyIndex)

  decreaseHistoryEx: =>
    if @historyIndex <= 0
      # get us back to a clean slate
      @historyIndex = -1
      @view.editorElement.getModel().setText('')
    else
      @historyIndex -= 1
      @restoreHistory(@historyIndex)

  confirm: (view) =>
    @value = @view.value
    @exState.pushExHistory(@)
    super(view)