Source code: com/maddyhome/idea/vim/ex/handler/GotoCharacterHandler.java
1 package com.maddyhome.idea.vim.ex.handler;
2
3 /*
4 * IdeaVim - A Vim emulator plugin for IntelliJ Idea
5 * Copyright (C) 2003 Rick Maddy
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 import com.intellij.openapi.actionSystem.DataContext;
23 import com.intellij.openapi.editor.Editor;
24 import com.maddyhome.idea.vim.command.Command;
25 import com.maddyhome.idea.vim.ex.CommandHandler;
26 import com.maddyhome.idea.vim.ex.ExCommand;
27 import com.maddyhome.idea.vim.group.CommandGroups;
28 import com.maddyhome.idea.vim.group.MotionGroup;
29
30 /**
31 *
32 */
33 public class GotoCharacterHandler extends CommandHandler
34 {
35 public GotoCharacterHandler()
36 {
37 super("go", "to", RANGE_OPTIONAL | ARGUMENT_OPTIONAL | RANGE_IS_COUNT, Command.FLAG_MOT_EXCLUSIVE);
38 }
39
40 public boolean execute(Editor editor, DataContext context, ExCommand cmd)
41 {
42 int count = cmd.getCount(editor, context, 1, true);
43
44 if (count > 0)
45 {
46 int res = CommandGroups.getInstance().getMotion().moveCaretToNthCharacter(editor, count - 1);
47 if (res != -1)
48 {
49 MotionGroup.moveCaret(editor, context, res);
50
51 return true;
52 }
53 }
54
55 return false;
56 }
57 }