void (@NotNull TextRange range, @NotNull Editor editor, @NotNull FindModel findModel, @NotNull List<? super FindResult> results) { VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument()); // Document can change even while we're holding read lock (example case - console), so we're taking an immutable snapshot of text here CharSequence charSequence = editor.getDocument().getImmutableCharSequence(); int offset = range.getStartOffset(); int maxOffset = Math.min(range.getEndOffset(), charSequence.length()); FindManager findManager = FindManager.getInstance(getProject()); while (offset < maxOffset) { FindResult result; try { CharSequence bombedCharSequence = StringUtil.newBombedCharSequence(charSequence, 3000); result = findManager.findString(bombedCharSequence, offset, findModel, virtualFile); ((StringUtil.BombedCharSequence)bombedCharSequence).defuse(); } catch(PatternSyntaxException | ProcessCanceledException e) { result = null; } if (result == null || !result.isStringFound()) break; int newOffset = result.getEndOffset(); if (newOffset > maxOffset) break; if (offset == newOffset) { offset++; // skip zero-width result } else { offset = newOffset; } results.add(result); } }