1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-03-06 18:32:51 +01:00

Convert GotoCharacterHandler to kotlin

This commit is contained in:
Alex Plate 2019-02-19 20:01:47 +03:00
parent 1aa021b157
commit d8d1daca67
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
2 changed files with 49 additions and 57 deletions
src/com/maddyhome/idea/vim/ex/handler

View File

@ -1,57 +0,0 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2016 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.ex.handler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.command.CommandFlags;
import com.maddyhome.idea.vim.ex.CommandHandler;
import com.maddyhome.idea.vim.ex.ExCommand;
import com.maddyhome.idea.vim.ex.ExException;
import com.maddyhome.idea.vim.group.MotionGroup;
import com.maddyhome.idea.vim.handler.CaretOrder;
import org.jetbrains.annotations.NotNull;
import java.util.EnumSet;
/**
*
*/
public class GotoCharacterHandler extends CommandHandler {
public GotoCharacterHandler() {
super("go", "to", RANGE_OPTIONAL | ARGUMENT_OPTIONAL | RANGE_IS_COUNT, EnumSet.of(CommandFlags.FLAG_MOT_EXCLUSIVE), true,
CaretOrder.DECREASING_OFFSET);
}
@Override
public boolean execute(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
@NotNull ExCommand cmd) throws ExException {
final int count = cmd.getCount(editor, caret, context, 1, true);
if (count <= 0) return false;
final int offset = VimPlugin.getMotion().moveCaretToNthCharacter(editor, count - 1);
if (offset == -1) return false;
MotionGroup.moveCaret(editor, caret, offset);
return true;
}
}

View File

@ -0,0 +1,49 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2016 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.ex.handler
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandFlags
import com.maddyhome.idea.vim.ex.CommandHandler
import com.maddyhome.idea.vim.ex.ExCommand
import com.maddyhome.idea.vim.ex.commands
import com.maddyhome.idea.vim.ex.flags
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.handler.CaretOrder
import java.util.*
class GotoCharacterHandler : CommandHandler(commands("go[to]"),
flags(RANGE_OPTIONAL, ARGUMENT_OPTIONAL, RANGE_IS_COUNT),
EnumSet.of(CommandFlags.FLAG_MOT_EXCLUSIVE), true, CaretOrder.DECREASING_OFFSET
) {
override fun execute(editor: Editor, caret: Caret, context: DataContext, cmd: ExCommand): Boolean {
val count = cmd.getCount(editor, caret, context, 1, true)
if (count <= 0) return false
val offset = VimPlugin.getMotion().moveCaretToNthCharacter(editor, count - 1)
if (offset == -1) return false
MotionGroup.moveCaret(editor, caret, offset)
return true
}
}