use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class ChangeGroup method deleteEndOfLine.
/**
* Delete from the cursor to the end of count - 1 lines down
*
* @param editor The editor to delete from
* @param count The number of lines affected
* @return true if able to delete the text, false if not
*/
public boolean deleteEndOfLine(@NotNull Editor editor, int count) {
int offset = VimPlugin.getMotion().moveCaretToLineEndOffset(editor, count - 1, true);
if (offset != -1) {
boolean res = deleteText(editor, new TextRange(editor.getCaretModel().getOffset(), offset), SelectionType.CHARACTER_WISE);
int pos = VimPlugin.getMotion().moveCaretHorizontal(editor, -1, false);
if (pos != -1) {
MotionGroup.moveCaret(editor, pos);
}
return res;
}
return false;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class ChangeGroup method getDeleteMotionRange.
@Nullable
public static TextRange getDeleteMotionRange(@NotNull Editor editor, DataContext context, int count, int rawCount, @NotNull Argument argument) {
TextRange range = MotionGroup.getMotionRange(editor, context, count, rawCount, argument, true);
// This is a kludge for dw, dW, and d[w. Without this kludge, an extra newline is deleted when it shouldn't be.
if (range != null) {
String text = editor.getDocument().getCharsSequence().subSequence(range.getStartOffset(), range.getEndOffset()).toString();
final int lastNewLine = text.lastIndexOf('\n');
if (lastNewLine > 0) {
final Command motion = argument.getMotion();
if (motion != null) {
final String id = ActionManager.getInstance().getId(motion.getAction());
if (id.equals("VimMotionWordRight") || id.equals("VimMotionBigWordRight") || id.equals("VimMotionCamelRight")) {
if (!SearchHelper.anyNonWhitespace(editor, range.getEndOffset(), -1)) {
final int start = range.getStartOffset();
range = new TextRange(start, start + lastNewLine);
}
}
}
}
}
return range;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class CommandParser method processCommand.
/**
* Parse and execute an Ex command entered by the user
*
* @param editor The editor to run the command in
* @param context The data context
* @param cmd The text entered by the user
* @param count The count entered before the colon
* @return A bitwise collection of flags, if any, from the result of running the command.
* @throws ExException if any part of the command is invalid or unknown
*/
public int processCommand(@NotNull Editor editor, @NotNull DataContext context, @NotNull String cmd, int count) throws ExException {
// Nothing entered
int result = 0;
if (cmd.length() == 0) {
return result | RES_EMPTY;
}
// Save the command history
VimPlugin.getHistory().addEntry(HistoryGroup.COMMAND, cmd);
// Parse the command
final ExCommand command = parse(cmd);
final CommandHandler handler = getCommandHandler(command);
if (handler == null) {
final String message = MessageHelper.message(Msg.NOT_EX_CMD, command.getCommand());
throw new InvalidCommandException(message, cmd);
}
if ((handler.getArgFlags() & CommandHandler.WRITABLE) > 0 && !editor.getDocument().isWritable()) {
VimPlugin.indicateError();
return result | RES_READONLY;
}
// Run the command
boolean ok = handler.process(editor, context, command, count);
if (ok && (handler.getArgFlags() & CommandHandler.DONT_SAVE_LAST) == 0) {
VimPlugin.getRegister().storeTextInternal(editor, new TextRange(-1, -1), cmd, SelectionType.CHARACTER_WISE, ':', false);
}
if ((handler.getArgFlags() & CommandHandler.DONT_REOPEN) != 0) {
result |= RES_DONT_REOPEN;
}
return result;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class CopyTextHandler method execute.
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) throws ExException {
TextRange range = cmd.getTextRange(editor, context, false);
final ExCommand argumentCmd = CommandParser.getInstance().parse(cmd.getArgument());
int line = argumentCmd.getRanges().getFirstLine(editor, context);
int offset = VimPlugin.getMotion().moveCaretToLineStart(editor, line + 1);
String text = EditorHelper.getText(editor, range.getStartOffset(), range.getEndOffset());
VimPlugin.getCopy().putText(editor, context, offset, text, SelectionType.LINE_WISE, 1, true, false, CommandState.SubMode.NONE);
return true;
}
use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class DeleteLinesHandler method execute.
public boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) throws ExException {
StringBuilder arg = new StringBuilder(cmd.getArgument());
char register = VimPlugin.getRegister().getDefaultRegister();
if (arg.length() > 0 && (arg.charAt(0) < '0' || arg.charAt(0) > '9')) {
register = arg.charAt(0);
arg.deleteCharAt(0);
cmd.setArgument(arg.toString());
}
VimPlugin.getRegister().selectRegister(register);
TextRange range = cmd.getTextRange(editor, context, true);
return VimPlugin.getChange().deleteRange(editor, range, SelectionType.LINE_WISE, false);
}
Aggregations