1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-03-07 21:32:52 +01:00

Reformat SearchGroup file

This commit is contained in:
Alex Plate 2019-06-10 15:39:04 +03:00
parent b7c7b268d4
commit b795c62ab7
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
3 changed files with 38 additions and 32 deletions

View File

@ -44,6 +44,7 @@ class RegisterActions {
registerCommandLineActions();
registerVariousModesActions();
}
private static void registerVimCommandActions() {
final ActionManagerEx manager = ActionManagerEx.getInstanceEx();
for (String actionId : manager.getPluginActions(VimPlugin.getPluginId())) {

View File

@ -1351,7 +1351,7 @@ public class MotionGroup {
return lastFTChar;
}
public int selectNextSearch(Editor editor, int count, boolean forwards) {
public int selectNextSearch(@NotNull Editor editor, int count, boolean forwards) {
TextRange nextRange = SearchGroup.findCurrentOrNextSearch(editor, count, forwards);
if (nextRange == null) {
return -1;
@ -1376,7 +1376,7 @@ public class MotionGroup {
return endOffset;
}
private boolean atEdgeOfRange(TextRange nextRange, Editor editor, boolean forwards) {
private boolean atEdgeOfRange(@NotNull TextRange nextRange, @NotNull Editor editor, boolean forwards) {
int currentPosition = editor.getCaretModel().getOffset();
if (forwards) {
return nextRange.getEndOffset() - 1 == currentPosition;

View File

@ -619,7 +619,7 @@ public class SearchGroup {
}
}
public static Optional<TextRange> findCurrent(@NotNull Editor editor, @NotNull String pattern, final int offset) {
private static Optional<TextRange> findCurrent(@NotNull Editor editor, @NotNull String pattern, final int offset) {
return findAll(editor, pattern, 0, -1, shouldIgnoreCase(pattern, false))
.stream()
.filter(range -> range.contains(offset))
@ -627,23 +627,31 @@ public class SearchGroup {
}
@Nullable
public static TextRange findNext(@NotNull Editor editor, @NotNull String pattern, final int offset, boolean ignoreCase,
final boolean forwards) {
public static TextRange findNext(@NotNull Editor editor,
@NotNull String pattern,
final int offset,
boolean ignoreCase,
final boolean forwards) {
return findNext(editor, pattern, offset, ignoreCase, forwards, 1);
}
@Nullable
public static TextRange findNext(@NotNull Editor editor, @NotNull String pattern, final int offset, boolean ignoreCase,
final boolean forwards, final int count) {
public static TextRange findNext(@NotNull Editor editor,
@NotNull String pattern,
final int offset,
boolean ignoreCase,
final boolean forwards,
final int count) {
if (count <= 0) {
return null;
}
final List<TextRange> results = new ArrayList(findAll(editor, pattern, 0, -1, shouldIgnoreCase(pattern, ignoreCase)));
final List<TextRange> results =
new ArrayList<>(findAll(editor, pattern, 0, -1, shouldIgnoreCase(pattern, ignoreCase)));
if (results.isEmpty()) {
return null;
}
final int size = EditorHelper.getFileSize(editor);
Collections.sort(results, (r1, r2) -> {
results.sort((r1, r2) -> {
final int d1 = distance(r1, offset, forwards, size);
final int d2 = distance(r2, offset, forwards, size);
if (d1 < 0 && d2 >= 0) {
@ -651,7 +659,7 @@ public class SearchGroup {
}
return d1 - d2;
});
TextRange nThClosest = results.get((count-1) % results.size());
TextRange nThClosest = results.get((count - 1) % results.size());
if (!Options.getInstance().isSet("wrapscan")) {
final int start = nThClosest.getStartOffset();
if (forwards && start < offset) {
@ -665,50 +673,47 @@ public class SearchGroup {
}
@Nullable
public static TextRange findNextSearch(Editor editor, int count, boolean forwards) {
public static TextRange findNextSearch(@NotNull Editor editor, int count, boolean forwards) {
String lastSearch = VimPlugin.getSearch().getLastSearch();
if (lastSearch == null) {
return null;
}
if (lastSearch == null) return null;
int currentPos = editor.getCaretModel().getOffset();
TextRange nextRange = new TextRange(currentPos, currentPos);
int startOffset = nextRange.getStartOffset();
nextRange = findNext(editor, lastSearch, startOffset-1, false, forwards);
nextRange = findNext(editor, lastSearch, startOffset - 1, false, forwards);
if (nextRange == null) {
return null;
}
return findNext(editor, lastSearch, nextRange, forwards, count - 1);
}
@Nullable
public static TextRange findCurrentOrNextSearch(Editor editor, int count, boolean forwards) {
public static TextRange findCurrentOrNextSearch(@NotNull Editor editor, int count, boolean forwards) {
String lastSearch = VimPlugin.getSearch().getLastSearch();
if (lastSearch == null) {
return null;
}
if (lastSearch == null) return null;
int currentPos = editor.getCaretModel().getOffset();
TextRange nextRange = new TextRange(currentPos, currentPos);
int startOffset = nextRange.getStartOffset();
nextRange = findCurrent(editor, lastSearch, startOffset)
.orElse(findNext(editor, lastSearch, startOffset, false, forwards));
if (nextRange == null) {
return null;
}
return findNext(editor, lastSearch, nextRange, forwards, count - 1);
int startOffset = nextRange.getStartOffset();
nextRange =
findCurrent(editor, lastSearch, startOffset).orElse(findNext(editor, lastSearch, startOffset, false, forwards));
if (nextRange == null) {
return null;
}
return findNext(editor, lastSearch, nextRange, forwards, count - 1);
}
@Nullable
private static TextRange findNext(Editor editor,
String lastSearch,
TextRange nextRange,
private static TextRange findNext(@NotNull Editor editor,
@NotNull String lastSearch,
@NotNull TextRange nextRange,
boolean forwards,
int count) {
if (count <= 0) {
return nextRange;
}
return findNext(editor, lastSearch, Math.max(nextRange.getStartOffset() - (forwards?0:1),0), false, forwards, count);
return findNext(editor, lastSearch, Math.max(nextRange.getStartOffset() - (forwards ? 0 : 1), 0), false, forwards,
count);
}
private static int distance(@NotNull TextRange range, int pos, boolean forwards, int size) {