private void FindCommand(bool backward = false, bool before = false) { _command = (x, _) => { Task.Run(() => EmbeddedCommand.Find(_startIndex, x, backward, before)); _repeatFind = () => Task.Run(() => EmbeddedCommand.Find(_startIndex, x, backward, before)); _reverseFind = () => Task.Run(() => EmbeddedCommand.Find(_startIndex, x, !backward, before)); _command = null; }; }
private Action ParseCommand(string command, Key[] keys) { if (string.IsNullOrEmpty(command)) { return(null); } var commands = command.Split(' '); if (commands[0] == "Cancel") { return(() => { if (_command != null) { _command = null; return; } SwitchMode(_settings.Mode); }); } else if (commands[0] == "Exit") { return(() => { Toggle(); }); } else if (commands[0] == "ChangeMode") { if (commands.Length < 2) { return(null); } var mode = ModeExtensions.GetMode(commands[1]); var modeName = commands[1]; if (mode == Mode.Unknown) { return(() => { _startIndex = -1; if (mode == Mode.Visual) { if (_stateController.Mode == Mode.Visual) { //SwitchMode(Mode.Normal); SwitchMode(_settings.Mode); return; } _startIndex = EmbeddedCommand.GetCaretPos(); } SwitchMode(modeName); }); } return(() => { _startIndex = -1; if (mode == Mode.Visual) { if (_stateController.Mode == Mode.Visual) { //SwitchMode(Mode.Normal); SwitchMode(_settings.Mode); return; } _startIndex = EmbeddedCommand.GetCaretPos(); } SwitchMode(mode); }); } else if (commands[0] == "VimLike") { if (commands.Length < 2) { return(null); } if (commands[1] == "f") { return(() => FindCommand()); } else if (commands[1] == "F") { return(() => FindCommand(true)); } else if (commands[1] == "t") { return(() => FindCommand(false, true)); } else if (commands[1] == "T") { return(() => FindCommand(true, true)); } else if (commands[1] == ";") { return(() => _repeatFind?.Invoke()); } else if (commands[1] == ",") { return(() => _reverseFind?.Invoke()); } else if (commands[1] == "y") { return(() => YankCommand(keys)); } } else if (commands[0] == "EmacsLike") { if (commands.Length < 2) { return(null); } if (commands[1] == "yank") { return(() => EmacsLikeCommand.Yank(_stateController, _settings)); } else if (commands[1] == "kill-ring-save") { return(() => EmacsLikeCommand.KillRingSave(_stateController, _settings)); } else if (commands[1] == "kill-region") { return(() => EmacsLikeCommand.KillRegion(_stateController, _settings)); } } return(null); }