mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-10 06:40:37 +02:00
Convert GotoLineHandler to kotlin
This commit is contained in:
parent
d8d1daca67
commit
42cbbbfc3a
src/com/maddyhome/idea/vim/ex/handler
@ -1,70 +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 com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* This handles Ex commands that just specify a range which translates to moving the cursor to the line given by the
|
||||
* range.
|
||||
*/
|
||||
public class GotoLineHandler extends CommandHandler {
|
||||
/**
|
||||
* Create the handler
|
||||
*/
|
||||
public GotoLineHandler() {
|
||||
super(RANGE_REQUIRED | ARGUMENT_OPTIONAL, EnumSet.of(CommandFlags.FLAG_MOT_EXCLUSIVE), true, CaretOrder.DECREASING_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the cursor to the line entered by the user
|
||||
*
|
||||
* @param editor The editor to perform the action in
|
||||
* @param caret The caret to perform the action on
|
||||
* @param context The data context
|
||||
* @param cmd The complete Ex command including range, command, and arguments
|
||||
* @return True if able to perform the command, false if not
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
|
||||
@NotNull ExCommand cmd) throws ExException {
|
||||
final int line = Math.min(cmd.getLine(editor, caret, context), EditorHelper.getLineCount(editor) - 1);
|
||||
|
||||
if (line >= 0) {
|
||||
MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, line));
|
||||
return true;
|
||||
}
|
||||
|
||||
MotionGroup.moveCaret(editor, caret, 0);
|
||||
return false;
|
||||
}
|
||||
}
|
64
src/com/maddyhome/idea/vim/ex/handler/GotoLineHandler.kt
Normal file
64
src/com/maddyhome/idea/vim/ex/handler/GotoLineHandler.kt
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.flags
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
import com.maddyhome.idea.vim.handler.CaretOrder
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* This handles Ex commands that just specify a range which translates to moving the cursor to the line given by the
|
||||
* range.
|
||||
*/
|
||||
class GotoLineHandler : CommandHandler(
|
||||
flags(RANGE_REQUIRED, ARGUMENT_OPTIONAL),
|
||||
EnumSet.of(CommandFlags.FLAG_MOT_EXCLUSIVE),
|
||||
true, CaretOrder.DECREASING_OFFSET
|
||||
) {
|
||||
/**
|
||||
* Moves the cursor to the line entered by the user
|
||||
*
|
||||
* @param editor The editor to perform the action in
|
||||
* @param caret The caret to perform the action on
|
||||
* @param context The data context
|
||||
* @param cmd The complete Ex command including range, command, and arguments
|
||||
* @return True if able to perform the command, false if not
|
||||
*/
|
||||
override fun execute(editor: Editor, caret: Caret, context: DataContext,
|
||||
cmd: ExCommand): Boolean {
|
||||
val line = Math.min(cmd.getLine(editor, caret, context), EditorHelper.getLineCount(editor) - 1)
|
||||
|
||||
if (line >= 0) {
|
||||
MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, line))
|
||||
return true
|
||||
}
|
||||
|
||||
MotionGroup.moveCaret(editor, caret, 0)
|
||||
return false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user