1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-03-01 04:46:02 +01:00

refactorings

This commit is contained in:
Oleg Shpynov 2011-12-03 20:24:46 +04:00
parent 4895f4d0a5
commit 0486618b26
11 changed files with 156 additions and 227 deletions

View File

@ -26,7 +26,6 @@ import com.maddyhome.idea.vim.command.Argument;
import com.maddyhome.idea.vim.ex.LineRange;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler;
import com.maddyhome.idea.vim.helper.EditorHelper;
/**
*/
@ -37,7 +36,7 @@ public class ChangeLastSearchReplaceAction extends EditorAction {
private static class Handler extends ChangeEditorActionHandler {
public boolean execute(Editor editor, DataContext context, int count, int rawCount, Argument argument) {
int line = EditorHelper.getCurrentLogicalLine(editor);
int line = editor.getCaretModel().getLogicalPosition().line;
LineRange range = new LineRange(line, line);
return CommandGroups.getInstance().getSearch().searchAndReplace(editor, context, range, "s", "//~/");
}

View File

@ -23,7 +23,6 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.ex.*;
import com.maddyhome.idea.vim.helper.EditorHelper;
/**
*
@ -38,7 +37,7 @@ public class DumpLineHandler extends CommandHandler {
public boolean execute(Editor editor, DataContext context, ExCommand cmd) throws ExException {
LineRange range = cmd.getLineRange(editor, context, false);
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
for (int l = range.getStartLine(); l <= range.getEndLine(); l++) {
int start = editor.getDocument().getLineStartOffset(l);
int end = editor.getDocument().getLineEndOffset(l);

View File

@ -24,7 +24,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.helper.EditorHelper;
import java.util.ArrayList;
import java.util.List;
@ -98,7 +97,7 @@ public class SearchRange extends AbstractRange {
*/
protected int getRangeLine(Editor editor, DataContext context, boolean lastZero) {
// Each subsequent pattern is searched for starting in the line after the previous search match
int line = EditorHelper.getCurrentLogicalLine(editor);
int line = editor.getCaretModel().getLogicalPosition().line;
int pos = -1;
for (int i = 0; i < patterns.size(); i++) {
String pattern = patterns.get(i);

View File

@ -157,7 +157,7 @@ public class ChangeGroup extends AbstractActionGroup {
* @param context The data context
*/
public void insertNewLineAbove(final Editor editor, final DataContext context) {
if (EditorHelper.getCurrentVisualLine(editor) == 0) {
if (editor.getCaretModel().getVisualPosition().line == 0) {
MotionGroup.moveCaret(editor, context, CommandGroups.getInstance().getMotion().moveCaretToLineStart(editor));
initInsert(editor, context, CommandState.MODE_INSERT);
@ -281,8 +281,8 @@ public class ChangeGroup extends AbstractActionGroup {
vp = new VisualPosition(vp.line + dir, vp.column);
int len = EditorHelper.getLineLength(editor, EditorHelper.visualLineToLogicalLine(editor, vp.line));
if (vp.column < len) {
int offset = EditorHelper.visualPostionToOffset(editor, vp);
char ch = EditorHelper.getDocumentChars(editor).charAt(offset);
int offset = EditorHelper.visualPositionToOffset(editor, vp);
char ch = editor.getDocument().getCharsSequence().charAt(offset);
processKey(editor, context, KeyStroke.getKeyStroke(ch));
res = true;
}
@ -391,8 +391,8 @@ public class ChangeGroup extends AbstractActionGroup {
private void repeatInsert(Editor editor, DataContext context, int count, boolean started) {
int cpos;
if (repeatLines > 0) {
int vline = EditorHelper.getCurrentVisualLine(editor);
int lline = EditorHelper.getCurrentLogicalLine(editor);
int vline = editor.getCaretModel().getVisualPosition().line;
int lline = editor.getCaretModel().getLogicalPosition().line;
cpos = editor.logicalPositionToOffset(new LogicalPosition(vline, repeatColumn));
for (int i = 0; i < repeatLines; i++) {
if (repeatAppend && repeatColumn < MotionGroup.LAST_COLUMN &&
@ -608,7 +608,7 @@ public class ChangeGroup extends AbstractActionGroup {
if (offset != -1) {
boolean res = deleteText(editor, context, new TextRange(editor.getCaretModel().getOffset(), offset), Command.FLAG_MOT_INCLUSIVE);
int pos = editor.getCaretModel().getOffset();
int norm = EditorHelper.normalizeOffset(editor, EditorHelper.getCurrentLogicalLine(editor), pos, false);
int norm = EditorHelper.normalizeOffset(editor, editor.getCaretModel().getLogicalPosition().line, pos, false);
if (norm != pos) {
MotionGroup.moveCaret(editor, context, norm);
}
@ -685,7 +685,7 @@ public class ChangeGroup extends AbstractActionGroup {
*/
public boolean deleteJoinLines(Editor editor, DataContext context, int count, boolean spaces) {
if (count < 2) count = 2;
int lline = EditorHelper.getCurrentLogicalLine(editor);
int lline = editor.getCaretModel().getLogicalPosition().line;
int total = EditorHelper.getLineCount(editor);
//noinspection SimplifiableIfStatement
if (lline + count > total) {
@ -766,10 +766,10 @@ public class ChangeGroup extends AbstractActionGroup {
}
// This is a kludge for dw, dW, and d[w. Without this kludge, an extra newline is deleted when it shouldn't be.
String text = EditorHelper.getDocumentChars(editor).subSequence(range.getStartOffset(),
String text = editor.getDocument().getCharsSequence().subSequence(range.getStartOffset(),
range.getEndOffset()).toString();
if (text.indexOf('\n') >= 0 &&
!(range.getStartOffset() == 0 || EditorHelper.getDocumentChars(editor).charAt(range.getStartOffset() - 1) == '\n')) {
!(range.getStartOffset() == 0 || editor.getDocument().getCharsSequence().charAt(range.getStartOffset() - 1) == '\n')) {
String id = ActionManager.getInstance().getId(argument.getMotion().getAction());
if (logger.isDebugEnabled()) {
logger.debug("action id=" + id);
@ -860,7 +860,7 @@ public class ChangeGroup extends AbstractActionGroup {
* @return true if able to change count characters, false if not
*/
public boolean changeCharacter(Editor editor, DataContext context, int count, char ch) {
int col = EditorHelper.getCurrentLogicalColumn(editor);
int col = editor.getCaretModel().getLogicalPosition().column;
int len = EditorHelper.getLineLength(editor);
int offset = editor.getCaretModel().getOffset();
if (len - col < count) {
@ -931,7 +931,7 @@ public class ChangeGroup extends AbstractActionGroup {
}
*/
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int[] starts = range.getStartOffsets();
int[] ends = range.getEndOffsets();
for (int j = ends.length - 1; j >= 0; j--) {
@ -955,7 +955,7 @@ public class ChangeGroup extends AbstractActionGroup {
*/
public boolean changeCharacters(Editor editor, DataContext context, int count) {
int len = EditorHelper.getLineLength(editor);
int col = EditorHelper.getCurrentLogicalColumn(editor);
int col = editor.getCaretModel().getLogicalPosition().column;
if (col + count >= len) {
return changeEndOfLine(editor, context, 1);
}
@ -1021,7 +1021,7 @@ public class ChangeGroup extends AbstractActionGroup {
boolean skipPunc = false;
if (id.equals("VimMotionWordRight")) {
if (EditorHelper.getFileSize(editor) > 0 &&
!Character.isWhitespace(EditorHelper.getDocumentChars(editor).charAt(editor.getCaretModel().getOffset()))) {
!Character.isWhitespace(editor.getDocument().getCharsSequence().charAt(editor.getCaretModel().getOffset()))) {
kludge = true;
argument.getMotion().setAction(ActionManager.getInstance().getAction("VimMotionWordEndRight"));
argument.getMotion().setFlags(Command.FLAG_MOT_INCLUSIVE);
@ -1029,7 +1029,7 @@ public class ChangeGroup extends AbstractActionGroup {
}
else if (id.equals("VimMotionBigWordRight")) {
if (EditorHelper.getFileSize(editor) > 0 &&
!Character.isWhitespace(EditorHelper.getDocumentChars(editor).charAt(editor.getCaretModel().getOffset()))) {
!Character.isWhitespace(editor.getDocument().getCharsSequence().charAt(editor.getCaretModel().getOffset()))) {
kludge = true;
skipPunc = true;
argument.getMotion().setAction(ActionManager.getInstance().getAction("VimMotionBigWordEndRight"));
@ -1038,7 +1038,7 @@ public class ChangeGroup extends AbstractActionGroup {
}
else if (id.equals("VimMotionCamelRight")) {
if (EditorHelper.getFileSize(editor) > 0 &&
!Character.isWhitespace(EditorHelper.getDocumentChars(editor).charAt(editor.getCaretModel().getOffset()))) {
!Character.isWhitespace(editor.getDocument().getCharsSequence().charAt(editor.getCaretModel().getOffset()))) {
kludge = true;
argument.getMotion().setAction(ActionManager.getInstance().getAction("VimMotionCamelEndRight"));
argument.getMotion().setFlags(Command.FLAG_MOT_INCLUSIVE);
@ -1049,8 +1049,8 @@ public class ChangeGroup extends AbstractActionGroup {
int pos = editor.getCaretModel().getOffset();
int size = EditorHelper.getFileSize(editor);
int cnt = count * argument.getMotion().getCount();
int pos1 = SearchHelper.findNextWordEnd(EditorHelper.getDocumentChars(editor), pos, size, cnt, skipPunc, false, false);
int pos2 = SearchHelper.findNextWordEnd(EditorHelper.getDocumentChars(editor), pos1, size, -cnt, skipPunc, false, false);
int pos1 = SearchHelper.findNextWordEnd(editor.getDocument().getCharsSequence(), pos, size, cnt, skipPunc, false, false);
int pos2 = SearchHelper.findNextWordEnd(editor.getDocument().getCharsSequence(), pos1, size, -cnt, skipPunc, false, false);
if (logger.isDebugEnabled()) {
logger.debug("pos=" + pos);
logger.debug("pos1=" + pos1);
@ -1240,7 +1240,7 @@ public class ChangeGroup extends AbstractActionGroup {
start = t;
}
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
for (int i = start; i < end; i++) {
if (i >= chars.length()) {
break;
@ -1343,7 +1343,7 @@ public class ChangeGroup extends AbstractActionGroup {
}
else {
// Left shift blockwise selection
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
for (int l = sline; l <= eline; l++) {
int len = EditorHelper.getLineLength(editor, l);
if (len > col) {
@ -1435,15 +1435,18 @@ public class ChangeGroup extends AbstractActionGroup {
* @param type The type of deletion (FLAG_MOT_LINEWISE, FLAG_MOT_CHARACTERWISE)
* @return true if able to delete the text, false if not
*/
private boolean deleteText(Editor editor, DataContext context, TextRange range, int type) {
private boolean deleteText(final Editor editor, final DataContext context, final TextRange range, final int type) {
// Fix for http://youtrack.jetbrains.net/issue/VIM-35
if (!range.normalize(EditorHelper.getFileSize(editor, true))) {
return false;
}
if (type == 0 || CommandGroups.getInstance().getRegister().storeText(editor, context, range, type, true, false)) {
final Document document = editor.getDocument();
final int[] startOffsets = range.getStartOffsets();
final int[] endOffsets = range.getEndOffsets();
for (int i = range.size() - 1; i >= 0; i--) {
editor.getDocument().deleteString(range.getStartOffsets()[i], range.getEndOffsets()[i]);
document.deleteString(startOffsets[i], endOffsets[i]);
}
if (type != 0) {

View File

@ -162,7 +162,7 @@ public class CopyGroup extends AbstractActionGroup {
pos = Math.min(editor.getDocument().getTextLength(),
CommandGroups.getInstance().getMotion().moveCaretToLineEnd(editor, true) + 1);
if (pos > 0 && pos == editor.getDocument().getTextLength() &&
EditorHelper.getDocumentChars(editor).charAt(pos - 1) != '\n') {
editor.getDocument().getCharsSequence().charAt(pos - 1) != '\n') {
editor.getDocument().insertString(pos, "\n");
pos++;
}

View File

@ -317,7 +317,7 @@ public class FileGroup extends AbstractActionGroup {
msg.append("-").append(elp.column + 1);
}
int lline = EditorHelper.getCurrentLogicalLine(editor);
int lline = editor.getCaretModel().getLogicalPosition().line;
int total = EditorHelper.getLineCount(editor);
msg.append("; Line ").append(lline + 1).append(" of ").append(total);
@ -409,7 +409,7 @@ public class FileGroup extends AbstractActionGroup {
msg.append("[+] ");
}
int lline = EditorHelper.getCurrentLogicalLine(editor);
int lline = editor.getCaretModel().getLogicalPosition().line;
int total = EditorHelper.getLineCount(editor);
int pct = (int)((float)lline / (float)total * 100f + 0.5);

View File

@ -201,7 +201,7 @@ public class MotionGroup extends AbstractActionGroup {
visualOffset = editor.getCaretModel().getOffset();
EditorData.setLastColumn(editor, EditorHelper.getCurrentVisualColumn(editor));
EditorData.setLastColumn(editor, editor.getCaretModel().getVisualPosition().column);
if (logger.isDebugEnabled()) {
logger.debug("Mouse click: vp=" + editor.getCaretModel().getVisualPosition() +
"lp=" + editor.getCaretModel().getLogicalPosition() +
@ -828,9 +828,9 @@ public class MotionGroup extends AbstractActionGroup {
}
}
int vcol = EditorHelper.getCurrentVisualColumn(editor);
int vcol = editor.getCaretModel().getVisualPosition().column;
scrollColumnToLeftOfScreen(editor, EditorHelper.normalizeVisualColumn(editor,
EditorHelper.getCurrentVisualLine(editor), vcol - scol + 1,
editor.getCaretModel().getVisualPosition().line, vcol - scol + 1,
false));
}
@ -853,16 +853,16 @@ public class MotionGroup extends AbstractActionGroup {
}
int vline = rawCount == 0 ?
EditorHelper.getCurrentVisualLine(editor) : EditorHelper.logicalLineToVisualLine(editor, count - 1);
editor.getCaretModel().getVisualPosition().line : EditorHelper.logicalLineToVisualLine(editor, count - 1);
scrollLineToTopOfScreen(editor, EditorHelper.normalizeVisualLine(editor, vline - sline + 1));
if (vline != EditorHelper.getCurrentVisualLine(editor) || start) {
if (vline != editor.getCaretModel().getVisualPosition().line || start) {
int offset;
if (start) {
offset = moveCaretToLineStartSkipLeading(editor, EditorHelper.visualLineToLogicalLine(editor, vline));
}
else {
offset = moveCaretVertical(editor,
EditorHelper.visualLineToLogicalLine(editor, vline) - EditorHelper.getCurrentLogicalLine(editor));
EditorHelper.visualLineToLogicalLine(editor, vline) - editor.getCaretModel().getLogicalPosition().line);
}
moveCaret(editor, context, offset);
@ -926,7 +926,7 @@ public class MotionGroup extends AbstractActionGroup {
public boolean scrollColumn(Editor editor, DataContext context, int columns) {
int vcol = EditorHelper.getVisualColumnAtLeftOfScreen(editor);
vcol = EditorHelper.normalizeVisualColumn(editor, EditorHelper.getCurrentVisualLine(editor), vcol + columns,
vcol = EditorHelper.normalizeVisualColumn(editor, editor.getCaretModel().getVisualPosition().line, vcol + columns,
false);
scrollColumnToLeftOfScreen(editor, vcol);
@ -962,7 +962,7 @@ public class MotionGroup extends AbstractActionGroup {
}
int vline = EditorHelper.getVisualLineAtTopOfScreen(editor);
int cline = EditorHelper.getCurrentVisualLine(editor);
int cline = editor.getCaretModel().getVisualPosition().line;
int newline = cline;
if (cline < vline + scrolloff) {
newline = EditorHelper.normalizeVisualLine(editor, vline + scrolloff);
@ -972,7 +972,7 @@ public class MotionGroup extends AbstractActionGroup {
}
if (logger.isDebugEnabled()) logger.debug("vline=" + vline + ", cline=" + cline + ", newline=" + newline);
int col = EditorHelper.getCurrentVisualColumn(editor);
int col = editor.getCaretModel().getVisualPosition().column;
int ocol = col;
if (col >= EditorHelper.getLineLength(editor) - 1) {
col = EditorData.getLastColumn(editor);
@ -995,7 +995,7 @@ public class MotionGroup extends AbstractActionGroup {
newcol = EditorHelper.normalizeVisualColumn(editor, newline, newcol, CommandState.inInsertMode(editor));
if (newline != cline || newcol != ocol) {
int offset = EditorHelper.visualPostionToOffset(editor, new VisualPosition(newline, newcol));
int offset = EditorHelper.visualPositionToOffset(editor, new VisualPosition(newline, newcol));
moveCaret(editor, context, offset);
EditorData.setLastColumn(editor, col);
@ -1040,7 +1040,7 @@ public class MotionGroup extends AbstractActionGroup {
return true;
}
else if (partial) {
int cline = EditorHelper.getCurrentVisualLine(editor);
int cline = editor.getCaretModel().getVisualPosition().line;
int vline = cline + pages * height;
vline = EditorHelper.normalizeVisualLine(editor, vline);
if (cline == vline) {
@ -1082,19 +1082,19 @@ public class MotionGroup extends AbstractActionGroup {
}
public int moveCaretToColumn(Editor editor, int count, boolean allowEnd) {
int line = EditorHelper.getCurrentLogicalLine(editor);
int line = editor.getCaretModel().getLogicalPosition().line;
int pos = EditorHelper.normalizeColumn(editor, line, count, allowEnd);
return editor.logicalPositionToOffset(new LogicalPosition(line, pos));
}
public int moveCaretToLineStartSkipLeading(Editor editor) {
int lline = EditorHelper.getCurrentLogicalLine(editor);
int lline = editor.getCaretModel().getLogicalPosition().line;
return moveCaretToLineStartSkipLeading(editor, lline);
}
public int moveCaretToLineStartSkipLeadingOffset(Editor editor, int offset) {
int line = EditorHelper.normalizeVisualLine(editor, EditorHelper.getCurrentVisualLine(editor) + offset);
int line = EditorHelper.normalizeVisualLine(editor, editor.getCaretModel().getVisualPosition().line + offset);
return moveCaretToLineStartSkipLeading(editor, EditorHelper.visualLineToLogicalLine(editor, line));
}
@ -1103,14 +1103,14 @@ public class MotionGroup extends AbstractActionGroup {
}
public int moveCaretToLineEndSkipLeadingOffset(Editor editor, int offset) {
int line = EditorHelper.normalizeVisualLine(editor, EditorHelper.getCurrentVisualLine(editor) + offset);
int line = EditorHelper.normalizeVisualLine(editor, editor.getCaretModel().getVisualPosition().line + offset);
return moveCaretToLineEndSkipLeading(editor, EditorHelper.visualLineToLogicalLine(editor, line));
}
public int moveCaretToLineEndSkipLeading(Editor editor, int lline) {
int start = EditorHelper.getLineStartOffset(editor, lline);
int end = EditorHelper.getLineEndOffset(editor, lline, true);
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = start;
for (int offset = end; offset > start; offset--) {
if (offset >= chars.length()) {
@ -1127,7 +1127,7 @@ public class MotionGroup extends AbstractActionGroup {
}
public int moveCaretToLineEnd(Editor editor, boolean allowPastEnd) {
return moveCaretToLineEnd(editor, EditorHelper.getCurrentLogicalLine(editor), allowPastEnd);
return moveCaretToLineEnd(editor, editor.getCaretModel().getLogicalPosition().line, allowPastEnd);
}
public int moveCaretToLineEnd(Editor editor, int lline, boolean allowPastEnd) {
@ -1137,7 +1137,7 @@ public class MotionGroup extends AbstractActionGroup {
}
public int moveCaretToLineEndOffset(Editor editor, int cntForward, boolean allowPastEnd) {
int line = EditorHelper.normalizeVisualLine(editor, EditorHelper.getCurrentVisualLine(editor) + cntForward);
int line = EditorHelper.normalizeVisualLine(editor, editor.getCaretModel().getVisualPosition().line + cntForward);
if (line < 0) {
return 0;
@ -1148,7 +1148,7 @@ public class MotionGroup extends AbstractActionGroup {
}
public int moveCaretToLineStart(Editor editor) {
int lline = EditorHelper.getCurrentLogicalLine(editor);
int lline = editor.getCaretModel().getLogicalPosition().line;
return moveCaretToLineStart(editor, lline);
}
@ -1161,7 +1161,7 @@ public class MotionGroup extends AbstractActionGroup {
}
public int moveCaretToLineStartOffset(Editor editor, int offset) {
int line = EditorHelper.normalizeVisualLine(editor, EditorHelper.getCurrentVisualLine(editor) + offset);
int line = EditorHelper.normalizeVisualLine(editor, editor.getCaretModel().getVisualPosition().line + offset);
return moveCaretToLineStart(editor, EditorHelper.visualLineToLogicalLine(editor, line));
}
@ -1172,7 +1172,7 @@ public class MotionGroup extends AbstractActionGroup {
public int moveCaretToLineScreenStartSkipLeading(Editor editor) {
int col = EditorHelper.getVisualColumnAtLeftOfScreen(editor);
int lline = EditorHelper.getCurrentLogicalLine(editor);
int lline = editor.getCaretModel().getLogicalPosition().line;
return EditorHelper.getLeadingCharacterOffset(editor, lline, col);
}
@ -1195,7 +1195,7 @@ public class MotionGroup extends AbstractActionGroup {
public int moveCaretHorizontal(Editor editor, int count, boolean allowPastEnd) {
int oldoffset = editor.getCaretModel().getOffset();
int offset = EditorHelper.normalizeOffset(editor, EditorHelper.getCurrentLogicalLine(editor), oldoffset + count,
int offset = EditorHelper.normalizeOffset(editor, editor.getCaretModel().getLogicalPosition().line, oldoffset + count,
allowPastEnd);
if (offset == oldoffset) {
return -1;
@ -1215,7 +1215,7 @@ public class MotionGroup extends AbstractActionGroup {
int line = EditorHelper.normalizeVisualLine(editor, pos.line + count);
VisualPosition newPos = new VisualPosition(line, EditorHelper.normalizeVisualColumn(editor, line, col, CommandState.inInsertMode(editor)));
return EditorHelper.visualPostionToOffset(editor, newPos);
return EditorHelper.visualPositionToOffset(editor, newPos);
}
}
@ -1298,7 +1298,7 @@ public class MotionGroup extends AbstractActionGroup {
public static void scrollCaretIntoView(Editor editor) {
int cline = EditorHelper.getCurrentVisualLine(editor);
int cline = editor.getCaretModel().getVisualPosition().line;
int vline = EditorHelper.getVisualLineAtTopOfScreen(editor);
boolean scrolljump = (CommandState.getInstance(editor).getFlags() & Command.FLAG_IGNORE_SCROLL_JUMP) == 0;
int scrolloff = ((NumberOption)Options.getInstance().getOption("scrolloff")).value();
@ -1347,7 +1347,7 @@ public class MotionGroup extends AbstractActionGroup {
scrollLineToTopOfScreen(editor, line);
}
int ccol = EditorHelper.getCurrentVisualColumn(editor);
int ccol = editor.getCaretModel().getVisualPosition().column;
int vcol = EditorHelper.getVisualColumnAtLeftOfScreen(editor);
int width = EditorHelper.getScreenWidth(editor);
scrolljump = (CommandState.getInstance(editor).getFlags() & Command.FLAG_IGNORE_SIDE_SCROLL_JUMP) == 0;

View File

@ -34,7 +34,6 @@ import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.ex.CommandParser;
import com.maddyhome.idea.vim.ex.ExException;
import com.maddyhome.idea.vim.helper.EditorData;
import com.maddyhome.idea.vim.helper.EditorHelper;
import com.maddyhome.idea.vim.helper.RunnableHelper;
import com.maddyhome.idea.vim.key.KeyParser;
import com.maddyhome.idea.vim.ui.ExEntryPanel;
@ -250,7 +249,7 @@ public class ProcessGroup extends AbstractActionGroup {
public boolean executeFilter(Editor editor, DataContext context, TextRange range, String command) throws IOException {
if (logger.isDebugEnabled()) logger.debug("command=" + command);
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
StringReader car = new StringReader(chars.subSequence(range.getStartOffset(),
range.getEndOffset()).toString());
StringWriter sw = new StringWriter();

View File

@ -73,7 +73,7 @@ public class EditorData {
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
Integer col = editor.getUserData(LAST_COLUMN);
if (col == null) {
return EditorHelper.getCurrentVisualColumn(editor);
return editor.getCaretModel().getVisualPosition().column;
}
else {
return col;
@ -195,14 +195,9 @@ public class EditorData {
public static boolean isConsoleOutput(Editor editor) {
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
Object res = editor.getUserData(CONSOLE_OUTPUT);
Object res = editor.getUserData(CONSOLE_VIEW_IN_EDITOR_VIEW);
logger.debug("isConsoleOutput for editor " + editor + " - " + res);
if (res != null) {
return true;
}
else {
return false;
}
return res != null;
}
/**
@ -230,7 +225,7 @@ public class EditorData {
private static final Key<CommandState> COMMAND_STATE = new Key<CommandState>("commandState");
private static final Key<Boolean> CHANGE_GROUP = new Key<Boolean>("changeGroup");
private static final Key<Boolean> MOTION_GROUP = new Key<Boolean>("motionGroup");
private static Key CONSOLE_OUTPUT = Key.create("CONSOLE_VIEW_IN_EDITOR_VIEW");
private static Key CONSOLE_VIEW_IN_EDITOR_VIEW = Key.create("CONSOLE_VIEW_IN_EDITOR_VIEW");
private static Logger logger = Logger.getInstance(EditorData.class.getName());
@ -252,7 +247,7 @@ public class EditorData {
if (f.getType().equals(Key.class)) {
f.setAccessible(true);
Key key = (Key)f.get(null);
CONSOLE_OUTPUT = key;
CONSOLE_VIEW_IN_EDITOR_VIEW = key;
break;
}
}

View File

@ -27,6 +27,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.maddyhome.idea.vim.common.CharacterPosition;
import com.maddyhome.idea.vim.common.TextRange;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.nio.CharBuffer;
@ -35,53 +36,16 @@ import java.nio.CharBuffer;
* This is a set of helper methods for working with editors. All line and column values are zero based.
*/
public class EditorHelper {
/**
* Gets the visual line number the cursor is on
*
* @param editor The editor
* @return The cursor's visual line number
*/
public static int getCurrentVisualLine(Editor editor) {
return editor.getCaretModel().getVisualPosition().line;
}
/**
* Gets the visual column number the cursor is on
*
* @param editor The editor
* @return The cursor's visual column number
*/
public static int getCurrentVisualColumn(Editor editor) {
return editor.getCaretModel().getVisualPosition().column;
}
private static final Logger logger = Logger.getInstance(EditorHelper.class.getName());
/**
* Gets the logical line number the cursor is on
*
* @param editor The editor
* @return The cursor's logical line number
*/
public static int getCurrentLogicalLine(Editor editor) {
return editor.getCaretModel().getLogicalPosition().line;
}
/**
* Gets the logical column number the cursor is on
*
* @param editor The editor
* @return The cursor's logical column number
*/
public static int getCurrentLogicalColumn(Editor editor) {
return editor.getCaretModel().getLogicalPosition().column;
}
public static int getVisualLineAtTopOfScreen(Editor editor) {
public static int getVisualLineAtTopOfScreen(final Editor editor) {
int lh = editor.getLineHeight();
return (editor.getScrollingModel().getVerticalScrollOffset() + lh - 1) / lh;
}
public static int getCurrentVisualScreenLine(Editor editor) {
return getCurrentVisualLine(editor) - getVisualLineAtTopOfScreen(editor) + 1;
public static int getCurrentVisualScreenLine(final Editor editor) {
return editor.getCaretModel().getVisualPosition().line - getVisualLineAtTopOfScreen(editor) + 1;
}
/**
@ -91,10 +55,8 @@ public class EditorHelper {
* @param editor The editor
* @return The number of characters in the current line
*/
public static int getLineLength(Editor editor) {
int lline = getCurrentLogicalLine(editor);
return getLineLength(editor, lline);
public static int getLineLength(final Editor editor) {
return getLineLength(editor, editor.getCaretModel().getLogicalPosition().line);
}
/**
@ -105,7 +67,7 @@ public class EditorHelper {
* @param lline The logical line within the file
* @return The number of characters in the specified line
*/
public static int getLineLength(Editor editor, int lline) {
public static int getLineLength(final Editor editor, final int lline) {
if (getLineCount(editor) == 0) {
return 0;
}
@ -114,13 +76,6 @@ public class EditorHelper {
}
}
/*
public static int getMaximumLineLength(Editor editor)
{
int width = editor.getScrollingModel().
}
*/
/**
* Gets the number of characters on the specified visual line. This will be different than the number of visual
* characters if there are "real" tabs in the line.
@ -129,9 +84,8 @@ public class EditorHelper {
* @param vline The visual line within the file
* @return The number of characters in the specified line
*/
public static int getVisualLineLength(Editor editor, int vline) {
int lline = visualLineToLogicalLine(editor, vline);
return getLineLength(editor, lline);
public static int getVisualLineLength(final Editor editor, final int vline) {
return getLineLength(editor, visualLineToLogicalLine(editor, vline));
}
/**
@ -141,7 +95,7 @@ public class EditorHelper {
* @param editor The editor
* @return The number of visible lines in the file
*/
public static int getVisualLineCount(Editor editor) {
public static int getVisualLineCount(final Editor editor) {
int count = getLineCount(editor);
return count == 0 ? 0 : logicalLineToVisualLine(editor, count - 1) + 1;
}
@ -152,10 +106,10 @@ public class EditorHelper {
* @param editor The editor
* @return The file line count
*/
public static int getLineCount(Editor editor) {
public static int getLineCount(final Editor editor) {
int len = editor.getDocument().getLineCount();
if (editor.getDocument().getTextLength() > 0 &&
EditorHelper.getDocumentChars(editor).charAt(editor.getDocument().getTextLength() - 1) == '\n') {
editor.getDocument().getCharsSequence().charAt(editor.getDocument().getTextLength() - 1) == '\n') {
len--;
}
@ -168,7 +122,7 @@ public class EditorHelper {
* @param editor The editor
* @return The file's character count
*/
public static int getFileSize(Editor editor) {
public static int getFileSize(final Editor editor) {
return getFileSize(editor, false);
}
@ -176,27 +130,22 @@ public class EditorHelper {
* Gets the actual number of characters in the file
*
* @param editor The editor
* @param incEnd True include newline
* @param includeEndNewLine True include newline
* @return The file's character count
*/
public static int getFileSize(Editor editor, boolean incEnd) {
Document doc = editor.getDocument();
int len = doc.getTextLength();
if (!incEnd && len >= 1 && EditorHelper.getDocumentChars(editor).charAt(len - 1) == '\n') {
len--;
}
return len;
public static int getFileSize(final 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;
}
/**
* Gets the number of lines than can be displayed on the screen at one time. This is rounded down to the
* nearest whole line if there is a parial line visible at the bottom of the screen.
* nearest whole line if there is a partial line visible at the bottom of the screen.
*
* @param editor The editor
* @return The number of screen lines
*/
public static int getScreenHeight(Editor editor) {
public static int getScreenHeight(final Editor editor) {
int lh = editor.getLineHeight();
int height = editor.getScrollingModel().getVisibleArea().y +
editor.getScrollingModel().getVisibleArea().height -
@ -210,7 +159,7 @@ public class EditorHelper {
* @param editor The editor
* @return The number of screen columns
*/
public static int getScreenWidth(Editor editor) {
public static int getScreenWidth(final Editor editor) {
Rectangle rect = editor.getScrollingModel().getVisibleArea();
Point pt = new Point(rect.width, 0);
VisualPosition vp = editor.xyToVisualPosition(pt);
@ -224,7 +173,7 @@ public class EditorHelper {
* @param editor The editor
* @return The number of pixels
*/
public static int getColumnWidth(Editor editor) {
public static int getColumnWidth(final Editor editor) {
Rectangle rect = editor.getScrollingModel().getVisibleArea();
if (rect.width == 0) return 0;
Point pt = new Point(rect.width, 0);
@ -240,7 +189,7 @@ public class EditorHelper {
* @param editor The editor
* @return The column number
*/
public static int getVisualColumnAtLeftOfScreen(Editor editor) {
public static int getVisualColumnAtLeftOfScreen(final Editor editor) {
int cw = getColumnWidth(editor);
if (cw == 0) return 0;
return (editor.getScrollingModel().getHorizontalScrollOffset() + cw - 1) / cw;
@ -253,7 +202,7 @@ public class EditorHelper {
* @param vline The visual line number to convert
* @return The logical line number
*/
public static int visualLineToLogicalLine(Editor editor, int vline) {
public static int visualLineToLogicalLine(final Editor editor, final int vline) {
int lline = editor.visualToLogicalPosition(new VisualPosition(vline, 0)).line;
return normalizeLine(editor, lline);
}
@ -266,7 +215,7 @@ public class EditorHelper {
* @param lline The logical line number to convert
* @return The visual line number
*/
public static int logicalLineToVisualLine(Editor editor, int lline) {
public static int logicalLineToVisualLine(final Editor editor, final int lline) {
return editor.logicalToVisualPosition(new LogicalPosition(lline, 0)).line;
}
@ -277,7 +226,7 @@ public class EditorHelper {
* @param lline The logical line to get the start offset for.
* @return 0 if line is &lt 0, file size of line is bigger than file, else the start offset for the line
*/
public static int getLineStartOffset(Editor editor, int lline) {
public static int getLineStartOffset(final Editor editor, final int lline) {
if (lline < 0) {
return 0;
}
@ -297,7 +246,7 @@ public class EditorHelper {
* @param incEnd True include newline
* @return 0 if line is &lt 0, file size of line is bigger than file, else the end offset for the line
*/
public static int getLineEndOffset(Editor editor, int lline, boolean incEnd) {
public static int getLineEndOffset(final Editor editor, final int lline, final boolean incEnd) {
if (lline < 0) {
return 0;
}
@ -317,10 +266,8 @@ public class EditorHelper {
* @param vline The visual line number to normalize
* @return The normalized visual line number
*/
public static int normalizeVisualLine(Editor editor, int vline) {
vline = Math.max(0, Math.min(vline, getVisualLineCount(editor) - 1));
return vline;
public static int normalizeVisualLine(final Editor editor, final int vline) {
return Math.max(0, Math.min(vline, getVisualLineCount(editor) - 1));
}
/**
@ -331,10 +278,8 @@ public class EditorHelper {
* @param lline The logical line number to normalize
* @return The normalized logical line number
*/
public static int normalizeLine(Editor editor, int lline) {
lline = Math.max(0, Math.min(lline, getLineCount(editor) - 1));
return lline;
public static int normalizeLine(final Editor editor, final int lline) {
return Math.max(0, Math.min(lline, getLineCount(editor) - 1));
}
/**
@ -347,10 +292,8 @@ public class EditorHelper {
* @param allowEnd True if newline allowed
* @return The normalized column number
*/
public static int normalizeVisualColumn(Editor editor, int vline, int col, boolean allowEnd) {
col = Math.max(0, Math.min(col, getVisualLineLength(editor, vline) - (allowEnd ? 0 : 1)));
return col;
public static int normalizeVisualColumn(final Editor editor, final int vline, final int col, final boolean allowEnd) {
return Math.max(0, Math.min(col, getVisualLineLength(editor, vline) - (allowEnd ? 0 : 1)));
}
/**
@ -363,10 +306,8 @@ public class EditorHelper {
* @param allowEnd True if newline allowed
* @return The normalized column number
*/
public static int normalizeColumn(Editor editor, int lline, int col, boolean allowEnd) {
col = Math.min(Math.max(0, getLineLength(editor, lline) - (allowEnd ? 0 : 1)), col);
return col;
public static int normalizeColumn(final Editor editor, final int lline, final int col, final boolean allowEnd) {
return Math.min(Math.max(0, getLineLength(editor, lline) - (allowEnd ? 0 : 1)), col);
}
/**
@ -379,32 +320,30 @@ public class EditorHelper {
* @param allowEnd true if the offset can be one past the last character on the line, false if not
* @return The normalized column number
*/
public static int normalizeOffset(Editor editor, int lline, int offset, boolean allowEnd) {
public static int normalizeOffset(final Editor editor, final int lline, final int offset, final boolean allowEnd) {
if (getFileSize(editor, allowEnd) == 0) {
return 0;
}
int min = getLineStartOffset(editor, lline);
int max = getLineEndOffset(editor, lline, allowEnd);
offset = Math.max(Math.min(offset, max), min);
return offset;
return Math.max(Math.min(offset, max), min);
}
public static int normalizeOffset(Editor editor, int offset, boolean allowEnd) {
public static int normalizeOffset(final Editor editor, final int offset, final boolean allowEnd) {
int lline = editor.offsetToLogicalPosition(offset).line;
return normalizeOffset(editor, lline, offset, allowEnd);
}
public static int getLeadingCharacterOffset(Editor editor, int lline) {
public static int getLeadingCharacterOffset(final Editor editor, final int lline) {
return getLeadingCharacterOffset(editor, lline, 0);
}
public static int getLeadingCharacterOffset(Editor editor, int lline, int col) {
public static int getLeadingCharacterOffset(final Editor editor, final int lline, final int col) {
int start = getLineStartOffset(editor, lline) + col;
int end = getLineEndOffset(editor, lline, true);
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = end;
for (int offset = start; offset < end; offset++) {
if (offset >= chars.length()) {
@ -420,11 +359,11 @@ public class EditorHelper {
return pos;
}
public static String getLeadingWhitespace(Editor editor, int lline) {
public static String getLeadingWhitespace(final Editor editor, final int lline) {
int start = getLineStartOffset(editor, lline);
int end = getLeadingCharacterOffset(editor, lline);
return EditorHelper.getDocumentChars(editor).subSequence(start, end).toString();
return editor.getDocument().getCharsSequence().subSequence(start, end).toString();
}
/**
@ -434,14 +373,19 @@ public class EditorHelper {
* @param file The virtual file get the editor for
* @return The matching editor or null if no match was found
*/
public static Editor getEditor(FileEditorManager manager, VirtualFile file) {
@Nullable
public static Editor getEditor(final FileEditorManager manager, final VirtualFile file) {
if (file == null) {
return null;
}
Document doc = FileDocumentManager.getInstance().getDocument(file);
Editor[] editors = EditorFactory.getInstance().getEditors(doc, manager.getProject());
if (editors != null && editors.length > 0) {
final Document doc = FileDocumentManager.getInstance().getDocument(file);
if (doc == null) {
return null;
}
final Editor[] editors = EditorFactory.getInstance().getEditors(doc, manager.getProject());
if (editors.length > 0) {
return editors[0];
}
@ -455,7 +399,7 @@ public class EditorHelper {
* @param pos The visual position to convert
* @return The file offset of the visual position
*/
public static int visualPostionToOffset(Editor editor, VisualPosition pos) {
public static int visualPositionToOffset(final Editor editor, final VisualPosition pos) {
return editor.logicalPositionToOffset(editor.visualToLogicalPosition(pos));
}
@ -467,16 +411,13 @@ public class EditorHelper {
* @param end The ending offset (exclusive)
* @return The string, never null but empty if start == end
*/
public static String getText(Editor editor, int start, int end) {
// Fix for IOOBE
final CharSequence documentChars = EditorHelper.getDocumentChars(editor);
if (!(0 <= start && start < end && start < documentChars.length() && 0 <= end && end <= documentChars.length())) {
return "";
}
return documentChars.subSequence(start, end).toString();
public static String getText(final Editor editor, final int start, final int end) {
if (start == end) return "";
final CharSequence documentChars = editor.getDocument().getCharsSequence();
return documentChars.subSequence(normalizeOffset(editor, start, true), normalizeOffset(editor, end, true)).toString();
}
public static String getText(Editor editor, TextRange range) {
public static String getText(final Editor editor, final TextRange range) {
int len = range.size();
if (len == 1) {
return getText(editor, range.getStartOffset(), range.getEndOffset());
@ -511,7 +452,7 @@ public class EditorHelper {
* @param offset The offset within the line
* @return The offset of the line start
*/
public static int getLineStartForOffset(Editor editor, int offset) {
public static int getLineStartForOffset(final Editor editor, final int offset) {
LogicalPosition pos = editor.offsetToLogicalPosition(offset);
return editor.getDocument().getLineStartOffset(pos.line);
}
@ -523,13 +464,12 @@ public class EditorHelper {
* @param offset The offset within the line
* @return The offset of the line end
*/
public static int getLineEndForOffset(Editor editor, int offset) {
if (logger.isDebugEnabled()) logger.debug("editor=" + editor);
public static int getLineEndForOffset(final Editor editor, final int offset) {
LogicalPosition pos = editor.offsetToLogicalPosition(offset);
return editor.getDocument().getLineEndOffset(pos.line);
}
public static int getLineCharCount(Editor editor, int lline) {
public static int getLineCharCount(final Editor editor, final int lline) {
return getLineEndOffset(editor, lline, true) - getLineStartOffset(editor, lline);
}
@ -540,28 +480,28 @@ public class EditorHelper {
* @param lline The logical line to get the text for
* @return The requested line
*/
public static String getLineText(Editor editor, int lline) {
public static String getLineText(final Editor editor, final int lline) {
return getText(editor, getLineStartOffset(editor, lline), getLineEndOffset(editor, lline, true));
}
public static CharacterPosition offsetToCharacterPosition(Editor editor, int offset) {
public static CharacterPosition offsetToCharacterPosition(final Editor editor, final int offset) {
int line = editor.getDocument().getLineNumber(offset);
int col = offset - editor.getDocument().getLineStartOffset(line);
return new CharacterPosition(line, col);
}
public static int characterPositionToOffset(Editor editor, CharacterPosition pos) {
public static int characterPositionToOffset(final Editor editor, final CharacterPosition pos) {
return editor.getDocument().getLineStartOffset(pos.line) + pos.column;
}
public static CharBuffer getLineBuffer(Editor editor, int lline) {
public static CharBuffer getLineBuffer(final Editor editor, final int lline) {
int start = getLineStartOffset(editor, lline);
return CharBuffer.wrap(EditorHelper.getDocumentChars(editor), start, start + getLineCharCount(editor, lline));
return CharBuffer.wrap(editor.getDocument().getCharsSequence(), start, start + getLineCharCount(editor, lline));
}
public static boolean isLineEmpty(Editor editor, int lline, boolean allowBlanks) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
public static boolean isLineEmpty(final Editor editor, final int lline, final boolean allowBlanks) {
CharSequence chars = editor.getDocument().getCharsSequence();
int offset = getLineStartOffset(editor, lline);
if (chars.charAt(offset) == '\n') {
return true;
@ -580,7 +520,7 @@ public class EditorHelper {
return false;
}
public static String pad(Editor editor, int lline, int to) {
public static String pad(final Editor editor, int lline, final int to) {
StringBuffer res = new StringBuffer();
int len = getLineLength(editor, lline);
@ -599,15 +539,10 @@ public class EditorHelper {
return res.toString();
}
public static CharSequence getDocumentChars(Editor editor) {
return editor.getDocument().getCharsSequence(); // API change - don't merge
}
public static boolean canEdit(Project project, Editor editor) {
return (editor.getDocument().isWritable() || // API change - don't merge
FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)) && // API change - don't merge
public static boolean canEdit(final Project project, final Editor editor) {
return (editor.getDocument().isWritable() ||
FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)) &&
!EditorData.isConsoleOutput(editor);
}
private static final Logger logger = Logger.getInstance(EditorHelper.class.getName());
}

View File

@ -46,7 +46,7 @@ public class SearchHelper {
end = offset - 1;
}
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
for (int i = start; i <= end; i++) {
if (!Character.isWhitespace(chars.charAt(i))) {
return true;
@ -57,8 +57,8 @@ public class SearchHelper {
}
public static int findSection(Editor editor, char type, int dir, int count) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
int line = EditorHelper.getCurrentLogicalLine(editor) + dir;
CharSequence chars = editor.getDocument().getCharsSequence();
int line = editor.getCaretModel().getLogicalPosition().line + dir;
int maxline = EditorHelper.getLineCount(editor);
int res = -1;
@ -81,7 +81,7 @@ public class SearchHelper {
}
public static int findUnmatchedBlock(Editor editor, char type, int count) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = editor.getCaretModel().getOffset();
int loc = blockChars.indexOf(type);
// What direction should we go now (-1 is backward, 1 is forward)
@ -94,7 +94,7 @@ public class SearchHelper {
}
public static TextRange findBlockRange(Editor editor, char type, int count, boolean isOuter) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = editor.getCaretModel().getOffset();
int start = editor.getSelectionModel().getSelectionStart();
int end = editor.getSelectionModel().getSelectionEnd();
@ -148,9 +148,9 @@ public class SearchHelper {
* were found on the remainder of the current line.
*/
public static int findMatchingPairOnCurrentLine(Editor editor) {
int line = EditorHelper.getCurrentLogicalLine(editor);
int line = editor.getCaretModel().getLogicalPosition().line;
int end = EditorHelper.getLineEndOffset(editor, line, true);
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = editor.getCaretModel().getOffset();
int loc = -1;
// Search the remainder of the current line for one of the candidate characters
@ -241,7 +241,7 @@ public class SearchHelper {
}
public static int findNextCamelStart(Editor editor, int count) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = editor.getCaretModel().getOffset();
int size = EditorHelper.getFileSize(editor);
@ -285,7 +285,7 @@ public class SearchHelper {
}
public static int findNextCamelEnd(Editor editor, int count) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = editor.getCaretModel().getOffset();
int size = EditorHelper.getFileSize(editor);
@ -341,7 +341,7 @@ public class SearchHelper {
* This counts all the words in the file.
*/
public static CountPosition countWords(Editor editor, int start, int end) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int offset = editor.getCaretModel().getOffset();
return countWords(chars, start, end, offset);
@ -391,7 +391,7 @@ public class SearchHelper {
* @return The offset of the match
*/
public static int findNextWord(Editor editor, int count, boolean skipPunc) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = editor.getCaretModel().getOffset();
int size = EditorHelper.getFileSize(editor);
@ -475,7 +475,7 @@ public class SearchHelper {
}
public static TextRange findNumberUnderCursor(final Editor editor, final boolean alpha, final boolean hex, final boolean octal) {
int lline = EditorHelper.getCurrentLogicalLine(editor);
int lline = editor.getCaretModel().getLogicalPosition().line;
String text = EditorHelper.getLineText(editor, lline).toLowerCase();
int offset = EditorHelper.getLineStartOffset(editor, lline);
int pos = editor.getCaretModel().getOffset() - offset;
@ -607,8 +607,8 @@ public class SearchHelper {
* @return The text range of the found word or null if there is no word under/after the cursor on the line
*/
public static TextRange findWordUnderCursor(Editor editor) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
int stop = EditorHelper.getLineEndOffset(editor, EditorHelper.getCurrentLogicalLine(editor), true);
CharSequence chars = editor.getDocument().getCharsSequence();
int stop = EditorHelper.getLineEndOffset(editor, editor.getCaretModel().getLogicalPosition().line, true);
int pos = editor.getCaretModel().getOffset();
int start = pos;
@ -659,7 +659,7 @@ public class SearchHelper {
logger.debug("hasSelection=" + hasSelection);
}
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
//int min = EditorHelper.getLineStartOffset(editor, EditorHelper.getCurrentLogicalLine(editor));
//int max = EditorHelper.getLineEndOffset(editor, EditorHelper.getCurrentLogicalLine(editor), true);
int min = 0;
@ -790,7 +790,7 @@ public class SearchHelper {
* @return The offset of match
*/
public static int findNextWordEnd(Editor editor, int count, boolean skipPunc, boolean stayEnd) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = editor.getCaretModel().getOffset();
int size = EditorHelper.getFileSize(editor);
@ -912,10 +912,10 @@ public class SearchHelper {
* @return The document offset of the matching character match, -1
*/
public static int findNextCharacterOnLine(Editor editor, int count, char ch) {
int line = EditorHelper.getCurrentLogicalLine(editor);
int line = editor.getCaretModel().getLogicalPosition().line;
int start = EditorHelper.getLineStartOffset(editor, line);
int end = EditorHelper.getLineEndOffset(editor, line, true);
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int found = 0;
int step = count >= 0 ? 1 : -1;
int pos = editor.getCaretModel().getOffset() + step;
@ -941,7 +941,7 @@ public class SearchHelper {
int dir = count > 0 ? 1 : -1;
count = Math.abs(count);
int total = count;
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int start = editor.getCaretModel().getOffset();
int max = EditorHelper.getFileSize(editor);
@ -971,7 +971,7 @@ public class SearchHelper {
int dir = count > 0 ? 1 : -1;
count = Math.abs(count);
int total = count;
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int start = editor.getCaretModel().getOffset();
int max = EditorHelper.getFileSize(editor);
@ -1359,7 +1359,7 @@ public class SearchHelper {
}
public static TextRange findSentenceRange(Editor editor, int count, boolean isOuter) {
CharSequence chars = EditorHelper.getDocumentChars(editor);
CharSequence chars = editor.getDocument().getCharsSequence();
int max = EditorHelper.getFileSize(editor);
int offset = editor.getCaretModel().getOffset();
int ssel = editor.getSelectionModel().getSelectionStart();
@ -1423,7 +1423,7 @@ public class SearchHelper {
}
private static int findNextParagraphLine(Editor editor, int count, boolean allowBlanks) {
int line = EditorHelper.getCurrentLogicalLine(editor);
int line = editor.getCaretModel().getLogicalPosition().line;
int maxline = EditorHelper.getLineCount(editor);
int dir = count > 0 ? 1 : -1;
boolean skipLines = count > 1;
@ -1477,7 +1477,7 @@ public class SearchHelper {
}
public static TextRange findParagraphRange(Editor editor, int count, boolean isOuter) {
int line = EditorHelper.getCurrentLogicalLine(editor);
int line = editor.getCaretModel().getLogicalPosition().line;
int maxline = EditorHelper.getLineCount(editor);
if (logger.isDebugEnabled()) logger.debug("starting on line " + line);
int sline;