aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py2/prompt_toolkit/key_binding/vi_state.py
blob: c6e3e366b0c25ae6d4d7c6bf5b890d73273f5eed (plain) (blame)
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
from __future__ import unicode_literals 
 
__all__ = ( 
    'InputMode', 
    'CharacterFind', 
    'ViState', 
) 
 
 
class InputMode(object): 
    INSERT = 'vi-insert' 
    INSERT_MULTIPLE = 'vi-insert-multiple'
    NAVIGATION = 'vi-navigation' 
    REPLACE = 'vi-replace' 
 
 
class CharacterFind(object): 
    def __init__(self, character, backwards=False): 
        self.character = character 
        self.backwards = backwards 
 
 
class ViState(object): 
    """ 
    Mutable class to hold the state of the Vi navigation. 
    """ 
    def __init__(self): 
        #: None or CharacterFind instance. (This is used to repeat the last 
        #: search in Vi mode, by pressing the 'n' or 'N' in navigation mode.) 
        self.last_character_find = None 
 
        # When an operator is given and we are waiting for text object,
        # -- e.g. in the case of 'dw', after the 'd' --, an operator callback
        # is set here.
        self.operator_func = None
        self.operator_arg = None

        #: Named registers. Maps register name (e.g. 'a') to
        #: :class:`ClipboardData` instances.
        self.named_registers = {}

        #: The Vi mode we're currently in to. 
        self.input_mode = InputMode.INSERT 
 
        #: Waiting for digraph.
        self.waiting_for_digraph = False
        self.digraph_symbol1 = None  # (None or a symbol.)

        #: When true, make ~ act as an operator.
        self.tilde_operator = False

    def reset(self, mode=InputMode.INSERT):
        """
        Reset state, go back to the given mode. INSERT by default.
        """
        # Go back to insert mode. 
        self.input_mode = mode

        self.waiting_for_digraph = False
        self.operator_func = None
        self.operator_arg = None