aboutsummaryrefslogtreecommitdiff
path: root/atom/packages/vim-mode/lib/prefixes.coffee
blob: c9109632d29fb95d7c2f6ac053cc399189b1e40e (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Prefix
  complete: null
  composedObject: null

  isComplete: -> @complete

  isRecordable: -> @composedObject.isRecordable()

  # Public: Marks this as complete upon receiving an object to compose with.
  #
  # composedObject - The next motion or operator.
  #
  # Returns nothing.
  compose: (@composedObject) ->
    @complete = true

  # Public: Executes the composed operator or motion.
  #
  # Returns nothing.
  execute: ->
    @composedObject.execute?(@count)

  # Public: Selects using the composed motion.
  #
  # Returns an array of booleans representing whether each selections' success.
  select: ->
    @composedObject.select?(@count)

  isLinewise: ->
    @composedObject.isLinewise?()

#
# Used to track the number of times either a motion or operator should
# be repeated.
#
class Repeat extends Prefix
  count: null

  # count - The initial digit of the repeat sequence.
  constructor: (@count) -> @complete = false

  # Public: Adds an additional digit to this repeat sequence.
  #
  # digit - A single digit, 0-9.
  #
  # Returns nothing.
  addDigit: (digit) ->
    @count = @count * 10 + digit

#
# Used to track which register the following operator should operate on.
#
class Register extends Prefix
  name: null

  # name - The single character name of the desired register
  constructor: (@name) -> @complete = false

  # Public: Marks as complete and sets the operator's register if it accepts it.
  #
  # composedOperator - The operator this register pertains to.
  #
  # Returns nothing.
  compose: (composedObject) ->
    super(composedObject)
    composedObject.register = @name if composedObject.register?

module.exports = {Repeat, Register}