public VisualMode(TextEditorData editor) : base(editor)
        {
            // visual mode keys
            CommandMap.Add("d", new CutSelectionCommand(editor));
            CommandMap.Add("x", new CutSelectionCommand(editor));
            CommandMap.Add("y", new YankSelectionCommand(editor));
            CommandMap.Add("Y", new YankSelectionCommand(editor));
            CommandMap.Add(">", new IndentSelectionCommand(editor));
            CommandMap.Add("<", new RemoveIndentSelectionCommand(editor));
            CommandMap.Add("c", new ChangeSelectionCommand(editor));
            CommandMap.Add("w", new WordCommand(editor));
            CommandMap.Add("e", new WordEndCommand(editor));
            CommandMap.Add("b", new WordBackCommand(editor));
            CommandMap.Add("gg", new GoToFirstLineCommand(editor));
            CommandMap.Add("G", new GoToLineCommand(editor));
            CommandMap.Add("f", new FindSelectionCommand(editor, 0));
            CommandMap.Add("t", new FindSelectionCommand(editor, -1));
            CommandMap.Add("p", new PasteSelectionCommand(editor));
            CommandMap.Add("F", new FindPreviousSelectionCommand(editor, 0));
            CommandMap.Add("T", new FindPreviousSelectionCommand(editor, 1));


            // function key remaps
            SpecialKeyCommandMap.Add(SpecialKey.Delete, new CutSelectionCommand(editor));
        }
示例#2
0
        public virtual bool KeyPress(KeyDescriptor descriptor)
        {
            // build repeat buffer
            if (_command == null && (_count > 0 || descriptor.KeyChar > '0') && descriptor.KeyChar >= '0' && descriptor.KeyChar <= '9')
            {
                _count = (_count * 10) + (descriptor.KeyChar - 48);
                return(false);
            }

            _buf += Char.ToString(descriptor.KeyChar);

            if (_command == null)
            {
                if (descriptor.ModifierKeys == ModifierKeys.Control)
                {
                    _buf = "^" + _buf;
                }

                if (!SpecialKeyCommandMap.TryGetValue(descriptor.SpecialKey, out _command))
                {
                    if (!CommandMap.ContainsKey(_buf))
                    {
                        foreach (var k in CommandMap.Keys)
                        {
                            if (k.StartsWith(_buf, StringComparison.Ordinal))
                            {
                                return(false);
                            }
                        }

                        Reset();
                        return(false);
                    }

                    _command = CommandMap[_buf];
                }

                _buf = "";
                if (_command.TakeArgument)
                {
                    return(false);
                }
            }

            CaretOffEol();

            RequestedMode = _command.RunCommand(_count, (char)(_buf.Length > 0 ? _buf[0] : 0));
            _command      = null;
            Reset();

            CaretOffEol();
            return(false);
        }
        public VisualMode(TextEditorData editor) : base(editor)
        {
            // visual mode keys
            CommandMap.Add("d", new CutSelectionCommand(editor));
            CommandMap.Add("x", new CutSelectionCommand(editor));
            CommandMap.Add("y", new YankSelectionCommand(editor));
            CommandMap.Add("Y", new YankSelectionCommand(editor));
            CommandMap.Add(">", new IndentSelectionCommand(editor));
            CommandMap.Add("<", new RemoveIndentSelectionCommand(editor));
            CommandMap.Add("c", new ChangeSelectionCommand(editor));
            CommandMap.Add("w", new WordCommand(editor));
            CommandMap.Add("e", new WordEndCommand(editor));
            CommandMap.Add("b", new WordBackCommand(editor));
            CommandMap.Add("G", new GoToLineCommand(editor));

            // function key remaps
            SpecialKeyCommandMap.Add(SpecialKey.Delete, new CutSelectionCommand(editor));
        }
        public NormalMode(TextEditorData editor) : base(editor)
        {
            // normal mode commands
            CommandMap.Add("a", new AppendCommand(editor));
            CommandMap.Add("A", new AppendEndCommand(editor));
            CommandMap.Add("b", new WordBackCommand(editor));
            CommandMap.Add("cc", new ChangeLineCommand(editor));
            CommandMap.Add("ci'", new ChangeCommand(editor, TextObject.InnerQuotedString, '\''));
            CommandMap.Add("ci\"", new ChangeCommand(editor, TextObject.InnerQuotedString, '\"'));
            CommandMap.Add("ci(", new ChangeInnerBlock(editor, '(', ')'));
            CommandMap.Add("ci)", new ChangeInnerBlock(editor, '(', ')'));
            CommandMap.Add("ci{", new ChangeInnerBlock(editor, '{', '}'));
            CommandMap.Add("ci}", new ChangeInnerBlock(editor, '{', '}'));
            CommandMap.Add("ci[", new ChangeInnerBlock(editor, '[', ']'));
            CommandMap.Add("ci]", new ChangeInnerBlock(editor, '[', ']'));
            CommandMap.Add("ci<", new ChangeInnerBlock(editor, '<', '>'));
            CommandMap.Add("ci>", new ChangeInnerBlock(editor, '<', '>'));
            CommandMap.Add("ca(", new ChangeCommand(editor, TextObject.Block, '(', ')'));
            CommandMap.Add("ca)", new ChangeCommand(editor, TextObject.Block, '(', ')'));
            CommandMap.Add("cab", new ChangeCommand(editor, TextObject.Block, '(', ')'));
            CommandMap.Add("ca{", new ChangeCommand(editor, TextObject.Block, '{', '}'));
            CommandMap.Add("ca}", new ChangeCommand(editor, TextObject.Block, '{', '}'));
            CommandMap.Add("caB", new ChangeCommand(editor, TextObject.Block, '{', '}'));
            CommandMap.Add("ca[", new ChangeCommand(editor, TextObject.Block, '[', ']'));
            CommandMap.Add("ca]", new ChangeCommand(editor, TextObject.Block, '[', ']'));
            CommandMap.Add("ca<", new ChangeCommand(editor, TextObject.Block, '<', '>'));
            CommandMap.Add("ca>", new ChangeCommand(editor, TextObject.Block, '<', '>'));
            CommandMap.Add("ca'", new ChangeCommand(editor, TextObject.QuotedString, '\''));
            CommandMap.Add("ca\"", new ChangeCommand(editor, TextObject.QuotedString, '\"'));
            CommandMap.Add("ca`", new ChangeCommand(editor, TextObject.QuotedString, '`'));
            CommandMap.Add("di[", new DeleteInnerBlock(editor, '[', ']'));
            CommandMap.Add("di]", new DeleteInnerBlock(editor, '[', ']'));
            CommandMap.Add("di'", new DeleteCommand(editor, TextObject.InnerQuotedString, '\''));
            CommandMap.Add("di\"", new DeleteCommand(editor, TextObject.InnerQuotedString, '"'));
            CommandMap.Add("di(", new DeleteInnerBlock(editor, '(', ')'));
            CommandMap.Add("di)", new DeleteInnerBlock(editor, '(', ')'));
            CommandMap.Add("di{", new DeleteInnerBlock(editor, '{', '}'));
            CommandMap.Add("di}", new DeleteInnerBlock(editor, '{', '}'));
            CommandMap.Add("di<", new DeleteInnerBlock(editor, '<', '>'));
            CommandMap.Add("di>", new DeleteInnerBlock(editor, '<', '>'));
            CommandMap.Add("cw", new ChangeWordCommand(editor));
            CommandMap.Add("ce", new ChangeWordEndCommand(editor));
            CommandMap.Add("dt", new DeleteToCharCommand(editor, 0));
            CommandMap.Add("df", new DeleteToCharCommand(editor, 1));
            CommandMap.Add("ct", new ChangeToCharCommand(editor, 0));
            CommandMap.Add("cf", new ChangeToCharCommand(editor, 1));
            CommandMap.Add("c$", new ChangeToEndCommand(editor));
            CommandMap.Add("C", new ChangeToEndCommand(editor));
            CommandMap.Add("dd", new DeleteLineCommand(editor));
            CommandMap.Add("dw", new DeleteWordCommand(editor));
            CommandMap.Add("de", new DeleteWordEndCommand(editor));
            CommandMap.Add("d$", new DeleteLineEndCommand(editor));
            CommandMap.Add("D", new DeleteLineEndCommand(editor));
            CommandMap.Add("f", new FindCommand(editor, 0));
            CommandMap.Add("F", new FindPreviousCommand(editor, 0));
            CommandMap.Add("t", new FindCommand(editor, -1));
            CommandMap.Add("T", new FindPreviousCommand(editor, 1));
            CommandMap.Add("gg", new GoToFirstLineCommand(editor));
            CommandMap.Add("gd", new GoToDeclarationCommand(editor));
            CommandMap.Add("gt", new GoToNextDocumentCommand(editor));
            CommandMap.Add("gT", new GoToPreviousDocumentCommand(editor));
            CommandMap.Add("G", new GoToLineCommand(editor));
            CommandMap.Add("i", new InsertCommand(editor));
            CommandMap.Add("I", new InsertLineStartCommand(editor));
            CommandMap.Add("J", new JoinCommand(editor));
            CommandMap.Add("n", new SearchNextCommand(editor));
            CommandMap.Add("N", new SearchPreviousCommand(editor));
            CommandMap.Add("o", new OpenBelowCommand(editor));
            CommandMap.Add("O", new OpenAboveCommand(editor));
            CommandMap.Add("p", new PasteAppendCommand(editor));
            CommandMap.Add("P", new PasteInsertCommand(editor));
            CommandMap.Add("r", new ReplaceCommand(editor));
            CommandMap.Add("s", new ChangeCharacterCommand(editor));
            CommandMap.Add("S", new ChangeLineCommand(editor));
            CommandMap.Add("u", new UndoCommand(editor));
            CommandMap.Add("v", new VisualCommand(editor));
            CommandMap.Add("V", new VisualLineCommand(editor));
            CommandMap.Add("w", new WordCommand(editor));
            CommandMap.Add("x", new DeleteCharacterCommand(editor));
            CommandMap.Add("X", new DeletePreviousCharacterCommand(editor));
            CommandMap.Add("yy", new YankLineCommand(editor));
            CommandMap.Add("Y", new YankLineCommand(editor));
            CommandMap.Add("zz", new RecenterCommand(editor));
            CommandMap.Add("/", new SearchCommand(editor));
            CommandMap.Add(">", new IndentCommand(editor));
            CommandMap.Add(">>", new IndentOnceCommand(editor));
            CommandMap.Add("<", new RemoveIndentCommand(editor));
            CommandMap.Add("<<", new RemoveIndentOnceCommand(editor));
            CommandMap.Add("%", new MatchingBraceCommand(editor));
            CommandMap.Add("e", new WordEndCommand(editor));
            CommandMap.Add("R", new ReplaceModeCommand(editor));
            CommandMap.Add("*", new SearchForwardCommand(editor));
            CommandMap.Add("~", new SwapCaseCommand(editor));


            // remaps
            SpecialKeyCommandMap.Add(SpecialKey.Delete, new DeleteCharacterCommand(editor));
        }