use of com.maddyhome.idea.vim.common.TextRange in project ideavim by JetBrains.
the class SearchGroup method findItOffset.
private int findItOffset(@NotNull Editor editor, int startOffset, int count, int dir, boolean noSmartCase) {
boolean wrap = Options.getInstance().isSet("wrapscan");
TextRange range = findIt(editor, startOffset, count, dir, noSmartCase, wrap, true, true);
if (range == null) {
return -1;
}
//highlightMatch(editor, range.getStartOffset(), range.getEndOffset());
ParsePosition pp = new ParsePosition(0);
int res = range.getStartOffset();
if (lastOffset == null) {
return -1;
}
if (lastOffset.length() == 0) {
return range.getStartOffset();
} else if (Character.isDigit(lastOffset.charAt(0)) || lastOffset.charAt(0) == '+' || lastOffset.charAt(0) == '-') {
int lineOffset = 0;
if (lastOffset.equals("+")) {
lineOffset = 1;
} else if (lastOffset.equals("-")) {
lineOffset = -1;
} else {
if (lastOffset.charAt(0) == '+') {
lastOffset = lastOffset.substring(1);
}
NumberFormat nf = NumberFormat.getIntegerInstance();
pp = new ParsePosition(0);
Number num = nf.parse(lastOffset, pp);
if (num != null) {
lineOffset = num.intValue();
}
}
int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
int newLine = EditorHelper.normalizeLine(editor, line + lineOffset);
res = VimPlugin.getMotion().moveCaretToLineStart(editor, newLine);
} else if ("ebs".indexOf(lastOffset.charAt(0)) != -1) {
int charOffset = 0;
if (lastOffset.length() >= 2) {
if ("+-".indexOf(lastOffset.charAt(1)) != -1) {
charOffset = 1;
}
NumberFormat nf = NumberFormat.getIntegerInstance();
pp = new ParsePosition(lastOffset.charAt(1) == '+' ? 2 : 1);
Number num = nf.parse(lastOffset, pp);
if (num != null) {
charOffset = num.intValue();
}
}
int base = range.getStartOffset();
if (lastOffset.charAt(0) == 'e') {
base = range.getEndOffset() - 1;
}
res = Math.max(0, Math.min(base + charOffset, EditorHelper.getFileSize(editor) - 1));
}
int ppos = pp.getIndex();
if (ppos < lastOffset.length() - 1 && lastOffset.charAt(ppos) == ';') {
int flags;
if (lastOffset.charAt(ppos + 1) == '/') {
flags = Command.FLAG_SEARCH_FWD;
} else if (lastOffset.charAt(ppos + 1) == '?') {
flags = Command.FLAG_SEARCH_REV;
} else {
return res;
}
if (lastOffset.length() - ppos > 2) {
ppos++;
}
res = search(editor, lastOffset.substring(ppos + 1), res, 1, flags);
return res;
} else {
return res;
}
}
Aggregations