Ejemplo n.º 1
0
        internal static CommandBinding CreateNormalBinding(string name, Func <CommandData, CommandResult> func)
        {
            var fsharpFunc  = func.ToFSharpFunc();
            var list        = name.Select(KeyInputUtil.CharToKeyInput).ToFSharpList();
            var commandName = KeyInputSet.NewManyKeyInputs(list);
            var command     = NormalCommand.NewPing(new PingData(fsharpFunc));

            return(CommandBinding.NewNormalBinding(commandName, CommandFlags.None, command));
        }
Ejemplo n.º 2
0
        public static void SetupCommandNormal(this Mock <ICommandUtil> commandUtil, NormalCommand normalCommand, int?count = null, RegisterName registerName = null)
        {
            var realCount   = FSharpOption.CreateForNullable(count);
            var realName    = FSharpOption.CreateForReference(registerName);
            var commandData = new CommandData(realCount, realName);
            var command     = Command.NewNormalCommand(normalCommand, commandData);

            commandUtil
            .Setup(x => x.RunCommand(command))
            .Returns(CommandResult.NewCompleted(ModeSwitch.NoSwitch))
            .Verifiable();
        }
Ejemplo n.º 3
0
        internal static NormalCommand CreatePing(Action <CommandData> action)
        {
            Func <CommandData, CommandResult> func =
                commandData =>
            {
                action(commandData);
                return(CommandResult.NewCompleted(ModeSwitch.NoSwitch));
            };
            var data = new PingData(func.ToFSharpFunc());

            return(NormalCommand.NewPing(data));
        }
Ejemplo n.º 4
0
        public void Run_CommandMatch7()
        {
            Create("foo bar");
            var count1 = 0;

            _runner.Add(VimUtil.CreateMotionBinding("aa", data => { count1++; return(NormalCommand.NewYank(data)); }));
            var count2 = 0;

            _runner.Add(VimUtil.CreateNormalBinding("aab", data => { count2++; return(CommandResult.NewCompleted(ModeSwitch.NoSwitch)); }));
            Run("aaw");
            Assert.AreEqual(1, count1);
            Assert.AreEqual(0, count2);
        }
Ejemplo n.º 5
0
        public void Run_CommandMatch6()
        {
            Create(String.Empty);
            var count1 = 0;

            _runner.Add(VimUtil.CreateMotionBinding("aa", data => { count1++; return(NormalCommand.NewYank(data)); }));
            var count2 = 0;

            _runner.Add(VimUtil.CreateLegacyBinding("aab", (count, reg) => { count2++; return(CommandResult.NewCompleted(ModeSwitch.NoSwitch)); }));
            Run("aab");
            Assert.AreEqual(0, count1);
            Assert.AreEqual(1, count2);
        }
Ejemplo n.º 6
0
        public VimKeyProcessor(IVimBuffer vimBuffer, IKeyUtil keyUtil, IWpfTextView wpfTextView)
        {
            _vimBuffer = vimBuffer;
            _keyUtil   = keyUtil;
            wpfTextView.VisualElement.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed)
                {
                    var position = e.GetPosition(wpfTextView.VisualElement);
                    var viewLine = wpfTextView.TextViewLines.GetTextViewLineContainingYCoordinate(position.Y + wpfTextView.ViewportTop);
                    wpfTextView.Caret.MoveTo(viewLine, position.X + wpfTextView.ViewportLeft);

                    // Run the 'put' command directly here.  Don't try to run 'P' because a key mapping could
                    // prevent it from running correctly
                    var command = Command.NewNormalCommand(NormalCommand.NewPutBeforeCaret(false), CommandData.Default);
                    _vimBuffer.CommandUtil.RunCommand(command);
                }
            };
        }
Ejemplo n.º 7
0
        internal static CommandBinding CreateComplexNormalBinding(
            string name,
            Action <KeyInput> action,
            CommandFlags flags = CommandFlags.None)
        {
            Func <KeyInput, BindResult <NormalCommand> > func = keyInput =>
            {
                action(keyInput);
                return(BindResult <NormalCommand> .NewComplete(NormalCommand.NewPutAfterCaret(false)));
            };

            var bindData = new BindData <NormalCommand>(
                FSharpOption <KeyRemapMode> .None,
                func.ToFSharpFunc());
            var bindDataStorage = BindDataStorage <NormalCommand> .NewSimple(bindData);

            return(CommandBinding.NewComplexNormalBinding(
                       KeyNotationUtil.StringToKeyInputSet(name),
                       flags,
                       bindDataStorage));
        }
Ejemplo n.º 8
0
            public void CommandMatch5()
            {
                Create(string.Empty);
                var count1 = 0;

                _runner.Add(VimUtil.CreateMotionBinding("aa", data => { count1++; return(NormalCommand.NewYank(data)); }));
                var count2 = 0;

                _runner.Add(VimUtil.CreateNormalBinding("aab", data => { count2++; return(CommandResult.NewCompleted(ModeSwitch.NoSwitch)); }));
                Run("aa");
                Assert.Equal(0, count1);
                Assert.Equal(0, count2);
            }
Ejemplo n.º 9
0
 private void SetLastCommand(NormalCommand command, int? count = null, RegisterName name = null)
 {
     var data = VimUtil.CreateCommandData(count, name);
     var storedCommand = StoredCommand.NewNormalCommand(command, data, CommandFlags.None);
     _vimData.LastCommand = FSharpOption.Create(storedCommand);
 }
Ejemplo n.º 10
0
 protected void RunNormalCommand(NormalCommand command)
 {
     var commandData = CommandData.Default;
     _commandUtil.RunNormalCommand(command, commandData);
 }
Ejemplo n.º 11
0
        public static void InitializeControllersForGameplay(Game1 game, KeyboardController keyboard, GamepadController gamepad)
        {
            keyboard.ClearDictionary();
            gamepad.ClearDictionary();
            //Background sound
            ICommand mutecommand = new MuteCommand(Stage.sound);

            keyboard.Add((int)Keys.M, mutecommand);
            //Add the Reset command to the r
            ICommand resetcommand = new ResetCommand();

            keyboard.Add((int)Keys.R, resetcommand);
            gamepad.Add((int)Buttons.Back, resetcommand);
            //Add the Exit Command to the controllers
            ICommand exitcommand = new ExitCommand(game);

            keyboard.Add((int)Keys.Q, exitcommand);
            gamepad.Add((int)Buttons.Start, exitcommand);
            //add the left command
            ICommand leftcommand = new LeftCommand(Stage.mario);

            keyboard.Add((int)Keys.A, leftcommand);
            keyboard.Add((int)Keys.Left, leftcommand);
            gamepad.Add((int)Buttons.DPadLeft, leftcommand);
            //add the right commmand
            ICommand rightcommand = new RightCommand(Stage.mario);

            keyboard.Add((int)Keys.D, rightcommand);
            keyboard.Add((int)Keys.Right, rightcommand);
            gamepad.Add((int)Buttons.DPadRight, rightcommand);
            //Add the srpint command
            ICommand sprintcommand = new SprintCommand(Stage.mario);

            keyboard.Add((int)Keys.LeftShift, sprintcommand);
            keyboard.Add((int)Keys.RightShift, sprintcommand);
            //add the down command
            ICommand downcommand = new DownCommand(Stage.mario);

            keyboard.Add((int)Keys.S, downcommand);
            keyboard.Add((int)Keys.Down, downcommand);
            gamepad.Add((int)Buttons.DPadDown, downcommand);
            //add the up command
            ICommand upcommand = new UpCommand(Stage.mario);

            keyboard.Add((int)Keys.W, upcommand);
            keyboard.Add((int)Keys.Up, upcommand);
            gamepad.Add((int)Buttons.DPadUp, upcommand);
            //add fireflower command
            ICommand firecommand = new FireMarioCommand(Stage.mario);

            keyboard.Add((int)Keys.I, firecommand);
            //add super command
            ICommand supercommand = new SuperCommand(Stage.mario);

            keyboard.Add((int)Keys.U, supercommand);
            //add normal mario command
            ICommand normalcommand = new NormalCommand(Stage.mario);

            keyboard.Add((int)Keys.Y, normalcommand);
            //add take damage command
            ICommand damagecommand = new DamageCommand(Stage.mario);

            keyboard.Add((int)Keys.O, damagecommand);
            //add star power command
            ICommand starcommand = new StarCommand(Stage.mario);

            keyboard.Add((int)Keys.L, starcommand);
            //add the fireball command with space
            ICommand fireballcommand = new MakeFireBall(Stage.mario);

            keyboard.Add((int)Keys.Space, fireballcommand);
            //add the Pause hud command with N
            ICommand pausehudcommand = new PauseCommand();

            keyboard.Add((int)Keys.P, pausehudcommand);
            ICommand interact = new InteractCommand();

            keyboard.Add((int)Keys.V, interact);
            gamepad.Add((int)Buttons.RightTrigger, interact);
            //add hold command E, no current mapping on gamepad
            ICommand holdcommand = new HoldingCommand(Stage.mario);

            keyboard.Add((int)Keys.E, holdcommand);


            /*
             * Add release commands. These are mainly for mario movement.
             */
            ICommand rightR = new ReleaseRightCommand(Stage.mario);

            keyboard.AddRelease((int)Keys.D, rightR);
            keyboard.AddRelease((int)Keys.Right, rightR);


            ICommand leftR = new ReleaseLeftCommand(Stage.mario);

            keyboard.AddRelease((int)Keys.A, leftR);
            keyboard.AddRelease((int)Keys.Left, leftR);

            ICommand downR = new ReleaseDownCommand(Stage.mario);

            keyboard.AddRelease((int)Keys.S, downR);
            keyboard.AddRelease((int)Keys.Down, downR);


            ICommand upR = new ReleaseUpCommand(Stage.mario);

            keyboard.AddRelease((int)Keys.W, upR);
            keyboard.AddRelease((int)Keys.Up, upR);

            ICommand sprintR = new ReleaseSprintCommand(Stage.mario);

            keyboard.AddRelease((int)Keys.LeftShift, sprintR);
            keyboard.AddRelease((int)Keys.RightShift, sprintR);

            ICommand holdR = new ReleaseHoldingCommand(Stage.mario);

            keyboard.AddRelease((int)Keys.E, holdR);
        }
Ejemplo n.º 12
0
        internal static NormalCommand CreatePing(Action <CommandData> action)
        {
            var data = new PingData(action.ToFSharpFunc());

            return(NormalCommand.NewPing(data));
        }