Beispiel #1
0
        public override void DoKeyPress(char code, out string viShortcut, out bool scrollToCursor)
        {
            ViChar viChar = new ViChar(code, false);

            viChar.c = context.GetMapped(code);
            ProcessKey(viChar, out viShortcut, out scrollToCursor);
        }
 public bool AddKey(ViChar code)
 {
     if (_lastResult != ParseResult.WaitNext)
     {
         Reset();
     }
     _lastResult = Parse(code);
     return(_lastResult == ParseResult.Complete);
 }
Beispiel #3
0
 private void ProcessKey(ViChar code, out string viShortcut, out bool scrollToCursor)
 {
     viShortcut     = null;
     scrollToCursor = false;
     if (!code.control)
     {
         text += code.c;
         bool hasStartsWith = false;
         foreach (Position position in positions)
         {
             if (position.text == text)
             {
                 if (mode == Mode.Single)
                 {
                     controller.PutCursor(GetPlace(position), false);
                     controller.ViAddHistoryPosition(true);
                     context.SetState(new ViReceiver(null, false));
                     scrollToCursor = true;
                 }
                 else if (mode == Mode.Selection)
                 {
                     controller.PutCursor(GetPlace(position), true);
                     controller.ViAddHistoryPosition(true);
                     context.SetState(new ViReceiverVisual(false));
                     scrollToCursor = true;
                 }
                 else if (mode == Mode.LinesSelection)
                 {
                     controller.PutCursor(GetPlace(position), true);
                     controller.ViAddHistoryPosition(true);
                     context.SetState(new ViReceiverVisual(true));
                     scrollToCursor = true;
                 }
                 else if (mode == Mode.New)
                 {
                     controller.PutNewCursor(GetPlace(position));
                     controller.ViAddHistoryPosition(true);
                     context.SetState(new ViReceiver(null, false));
                     scrollToCursor = true;
                 }
                 hasStartsWith = true;
                 break;
             }
             else if (position.text.StartsWith(text))
             {
                 hasStartsWith = true;
             }
         }
         if (!hasStartsWith)
         {
             context.SetState(new ViReceiver(null, false));
         }
     }
 }
        public void Reset()
        {
            _lastResult = ParseResult.Complete;
            _state      = State.Init;
            _stateText  = "";

            rawCount = -1;
            move     = new ViChar('\0', false);
            moveChar = new ViChar('\0', false);
            action   = new ViChar('\0', false);
            register = '\0';
            shortcut = null;
        }
 private void ProcessKey(ViChar code, out string viShortcut, out bool scrollToCursor)
 {
     viShortcut = null;
     if (!parser.AddKey(code))
     {
         scrollToCursor = false;
         return;
     }
     if (parser.shortcut != null)
     {
         viShortcut     = parser.shortcut;
         scrollToCursor = false;
         return;
     }
     ProcessParserCommand(out viShortcut, out scrollToCursor);
 }
        private ParseResult Parse(ViChar code)
        {
            switch (_state)
            {
            case State.Init:
                if (char.IsNumber(code.c) && code.c != '0')
                {
                    _state = State.Count;
                    return(Parse(code));
                }
                if (code.c == '"')
                {
                    _state = State.WaitRegister;
                    return(ParseResult.WaitNext);
                }
                if (code.c == '/')
                {
                    shortcut = code.control ? "C/" : "/";
                    return(ParseResult.Complete);
                }
                if (code.c == '?')
                {
                    shortcut = code.control ? "C?" : "?";
                    return(ParseResult.Complete);
                }
                if (code.c == ':')
                {
                    shortcut = ":";
                    return(ParseResult.Complete);
                }
                _state = State.Action;
                return(Parse(code));

            case State.Count:
                if (char.IsNumber(code.c))
                {
                    _stateText += code;
                    return(ParseResult.WaitNext);
                }
                if (_stateText != "")
                {
                    rawCount   = int.Parse(_stateText);
                    _stateText = "";
                }
                _state = State.Action;
                return(Parse(code));

            case State.Action:
                if (code.control)
                {
                    switch (code.c)
                    {
                    case 'f':
                    case 'b':
                        move = code;
                        return(ParseResult.Complete);

                    case 'r':
                    case 'j':
                    case 'k':
                    case 'd':
                    case 'D':
                    case 'J':
                    case 'K':
                    case 'o':
                    case 'i':
                        action = code;
                        return(ParseResult.Complete);
                    }
                }
                else
                {
                    switch (code.c)
                    {
                    case 'j':
                    case 'k':
                    case 'h':
                    case 'l':
                    case 'w':
                    case 'W':
                    case 'e':
                    case 'E':
                    case 'b':
                    case 'B':
                    case '0':
                    case '^':
                    case '$':
                    case 'G':
                    case 'n':
                    case 'N':
                    case '%':
                        move = code;
                        return(ParseResult.Complete);

                    case 'v':
                    case 'V':
                    case '*':
                    case '#':
                        action = code;
                        return(ParseResult.Complete);

                    case 'd':
                        if (action.IsChar('d'))
                        {
                            move = code;
                            return(ParseResult.Complete);
                        }
                        action = code;
                        return(_visualMode ? ParseResult.Complete : ParseResult.WaitNext);

                    case 'c':
                        if (action.IsChar('c'))
                        {
                            move = code;
                            return(ParseResult.Complete);
                        }
                        action = code;
                        return(_visualMode ? ParseResult.Complete : ParseResult.WaitNext);

                    case 'y':
                        if (action.IsChar('y'))
                        {
                            move = code;
                            return(ParseResult.Complete);
                        }
                        action = code;
                        return(_visualMode ? ParseResult.Complete : ParseResult.WaitNext);

                    case 'Y':
                        action = code;
                        return(ParseResult.Complete);

                    case '>':
                        if (action.IsChar('>'))
                        {
                            move = code;
                            return(ParseResult.Complete);
                        }
                        action = code;
                        return(_visualMode ? ParseResult.Complete : ParseResult.WaitNext);

                    case '<':
                        if (action.IsChar('<'))
                        {
                            move = code;
                            return(ParseResult.Complete);
                        }
                        action = code;
                        return(_visualMode ? ParseResult.Complete : ParseResult.WaitNext);

                    case 'f':
                    case 'F':
                    case 't':
                    case 'T':
                    case 'g':
                    case '\'':
                    case '`':
                        _state = State.WaitChar;
                        move   = code;
                        return(ParseResult.WaitNext);

                    case 'm':
                        _state = State.WaitChar;
                        action = code;
                        return(ParseResult.WaitNext);

                    case 'r':
                    case ' ':
                        _state = State.WaitChar;
                        action = code;
                        return(ParseResult.WaitNext);

                    case 'I':
                    case 'A':
                    case 'u':
                    case 'U':
                    case 'x':
                    case '~':
                    case 'p':
                    case 'P':
                    case 'J':
                    case '.':
                    case 'o':
                    case 'O':
                    case 'C':
                    case 'D':
                        action = code;
                        return(ParseResult.Complete);

                    case 'i':
                    case 'a':
                        if (action.c != '\0' || _visualMode)
                        {
                            move   = code;
                            _state = State.WaitObject;
                            return(ParseResult.WaitNext);
                        }
                        action = code;
                        return(ParseResult.Complete);

                    case 's':
                    case '\b':
                    case '\r':
                        action = code;
                        return(ParseResult.Complete);

                    case ',':
                    case '\\':
                        action     = new ViChar(',', false);
                        _state     = State.Leader;
                        _stateText = "";
                        return(ParseResult.WaitNext);
                    }
                    if (char.IsNumber(code.c))
                    {
                        _state = State.Count;
                        return(Parse(code));
                    }
                }
                return(ParseResult.Incorrect);

            case State.WaitChar:
                if (!move.control && move.c == 'g')
                {
                    if (code.c == 'j' || code.c == 'k')
                    {
                        moveChar = move;
                        move     = code;
                        return(ParseResult.Complete);
                    }
                }
                moveChar = code;
                return(ParseResult.Complete);

            case State.WaitRegister:
                register = code.c;
                _state   = State.Init;
                return(ParseResult.WaitNext);

            case State.WaitObject:
                moveChar = code;
                return(ParseResult.Complete);

            case State.Leader:
                if (!code.control)
                {
                    switch (code.c)
                    {
                    case ' ':
                        move   = code;
                        _state = State.WaitChar;
                        return(ParseResult.WaitNext);

                    case 'b':
                        shortcut = "\\b";
                        return(ParseResult.Complete);

                    case 'n':
                        shortcut = "\\n";
                        return(ParseResult.Complete);

                    case 'N':
                        shortcut = "\\N";
                        return(ParseResult.Complete);

                    case 's':
                        shortcut = "\\s";
                        return(ParseResult.Complete);

                    case 'r':
                        shortcut = "\\r";
                        return(ParseResult.Complete);

                    case 'c':
                        shortcut = "\\c";
                        return(ParseResult.Complete);

                    case 'f':
                        shortcut = "\\f";
                        return(ParseResult.Complete);

                    case 'g':
                        shortcut = "\\g";
                        return(ParseResult.Complete);
                    }
                }
                return(ParseResult.Incorrect);
            }
            return(ParseResult.Incorrect);
        }