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

Trying to get rid of getFileSize with allowEnd

This commit is contained in:
Alex Plate 2020-06-06 18:07:15 +03:00
parent 330e717518
commit b161346171
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
8 changed files with 39 additions and 7 deletions

View File

@ -46,6 +46,7 @@ import com.maddyhome.idea.vim.group.MarkGroup
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.helper.StringHelper.stringToKeys
import com.maddyhome.idea.vim.helper.fileSize
import com.maddyhome.idea.vim.helper.subMode
import com.maddyhome.idea.vim.key.OperatorFunction
@ -146,7 +147,7 @@ class VimExchangeExtension: VimExtension {
}
return editor.markupModel.addRangeHighlighter(
editor.getMarkOffset(ex.start),
(editor.getMarkOffset(ex.end) + 1).coerceAtMost(EditorHelper.getFileSize(editor, true)),
(editor.getMarkOffset(ex.end) + 1).coerceAtMost(editor.fileSize),
HighlighterLayer.SELECTION - 1,
attributes,
hlArea

View File

@ -865,7 +865,7 @@ public class ChangeGroup {
public boolean deleteLine(@NotNull Editor editor, @NotNull Caret caret, int count) {
int start = VimPlugin.getMotion().moveCaretToLineStart(editor, caret);
int offset = Math.min(VimPlugin.getMotion().moveCaretToLineEndOffset(editor, caret, count - 1, true) + 1,
EditorHelper.getFileSize(editor, true));
EditorHelperRt.getFileSize(editor));
if (logger.isDebugEnabled()) {
logger.debug("start=" + start);
logger.debug("offset=" + offset);
@ -1732,7 +1732,7 @@ public class ChangeGroup {
final @NotNull TextRange range,
@Nullable SelectionType type) {
// Fix for https://youtrack.jetbrains.net/issue/VIM-35
if (!range.normalize(EditorHelper.getFileSize(editor, true))) {
if (!range.normalize(EditorHelperRt.getFileSize(editor))) {
return false;
}

View File

@ -146,7 +146,7 @@ public class MotionGroup {
EnumSet<CommandFlags> flags = cmd.getFlags();
if (flags.contains(CommandFlags.FLAG_MOT_LINEWISE)) {
start = EditorHelper.getLineStartForOffset(editor, start);
end = Math.min(EditorHelper.getLineEndForOffset(editor, end) + 1, EditorHelper.getFileSize(editor, true));
end = Math.min(EditorHelper.getLineEndForOffset(editor, end) + 1, EditorHelperRt.getFileSize(editor));
}
}

View File

@ -47,6 +47,7 @@ import com.maddyhome.idea.vim.group.MarkGroup
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.group.visual.VimSelection
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.fileSize
import com.maddyhome.idea.vim.option.ClipboardOptionsData
import com.maddyhome.idea.vim.option.OptionsManager
import java.util.*
@ -342,7 +343,7 @@ class PutGroup {
if (currentLine + lineCount >= EditorHelper.getLineCount(editor)) {
val limit = currentLine + lineCount - EditorHelper.getLineCount(editor)
for (i in 0 until limit) {
MotionGroup.moveCaret(editor, caret, EditorHelper.getFileSize(editor, true))
MotionGroup.moveCaret(editor, caret, editor.fileSize)
VimPlugin.getChange().insertText(editor, caret, "\n")
}
}

View File

@ -28,6 +28,7 @@ import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.fileSize
import org.jetbrains.annotations.Contract
import java.util.*
import kotlin.math.min
@ -84,7 +85,7 @@ class YankGroup {
val ranges = ArrayList<Pair<Int, Int>>(caretModel.caretCount)
for (caret in caretModel.allCarets) {
val start = VimPlugin.getMotion().moveCaretToLineStart(editor, caret)
val end = min(VimPlugin.getMotion().moveCaretToLineEndOffset(editor, caret, count - 1, true) + 1, EditorHelper.getFileSize(editor, true))
val end = min(VimPlugin.getMotion().moveCaretToLineEndOffset(editor, caret, count - 1, true) + 1, editor.fileSize)
if (end == -1) continue

View File

@ -29,6 +29,7 @@ import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.group.ChangeGroup
import com.maddyhome.idea.vim.group.MotionGroup
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.fileSize
import com.maddyhome.idea.vim.helper.inBlockSubMode
import com.maddyhome.idea.vim.helper.inSelectMode
import com.maddyhome.idea.vim.helper.inVisualMode
@ -184,7 +185,7 @@ fun lineToNativeSelection(editor: Editor, start: Int, end: Int): Pair<Int, Int>
val (nativeStart, nativeEnd) = sort(start, end)
val lineStart = EditorHelper.getLineStartForOffset(editor, nativeStart)
// Extend to \n char of line to fill full line with selection
val lineEnd = (EditorHelper.getLineEndForOffset(editor, nativeEnd) + 1).coerceAtMost(EditorHelper.getFileSize(editor, true))
val lineEnd = (EditorHelper.getLineEndForOffset(editor, nativeEnd) + 1).coerceAtMost(editor.fileSize)
return lineStart to lineEnd
}

View File

@ -158,7 +158,9 @@ public class EditorHelper {
* @param editor The editor
* @param includeEndNewLine True include newline
* @return The file's character count
* @deprecated please use the extension in EditorHelper.kt
*/
@Deprecated
public static int getFileSize(final @NotNull Editor editor, final boolean includeEndNewLine) {
final int len = editor.getDocument().getTextLength();
return includeEndNewLine || len == 0 || editor.getDocument().getCharsSequence().charAt(len - 1) != '\n' ? len : len - 1;

View File

@ -0,0 +1,26 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>.
*/
@file:JvmName("EditorHelperRt")
package com.maddyhome.idea.vim.helper
import com.intellij.openapi.editor.Editor
val Editor.fileSize: Int
get() = document.textLength