Skip to content

Commit

Permalink
Support e flag for search
Browse files Browse the repository at this point in the history
  • Loading branch information
lippfi committed Feb 5, 2024
1 parent 7062d9b commit 63995e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public abstract class VimSearchHelperBase : VimSearchHelper {
if (injector.globalOptions().smartcase && !searchOptions.contains(SearchOptions.IGNORE_SMARTCASE)) options.add(VimRegexOptions.SMART_CASE)
if (injector.globalOptions().ignorecase) options.add(VimRegexOptions.IGNORE_CASE)
if (injector.globalOptions().wrapscan) options.add(VimRegexOptions.WRAP_SCAN)
if (searchOptions.contains(SearchOptions.WANT_ENDPOS)) options.add(VimRegexOptions.WANT_END_POSITION)

val regex = try {
VimRegex(pattern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ public class VimRegex(pattern: String) {
): VimMatchResult {
var index = editor.getLineStartOffset(line)
var prevResult: VimMatchResult = VimMatchResult.Failure(VimRegexErrors.E486)
val returnEndPosition = options.contains(VimRegexOptions.WANT_END_POSITION)
while (index <= maxIndex) {
val result = simulateNonExactNFA(editor, index, options)
when (result) {
// no more matches in this line, break out of the loop
is VimMatchResult.Failure -> break
is VimMatchResult.Success -> {
// no more relevant matches in this line, break out of the loop
if (result.range.startOffset > maxIndex) break
if ((!returnEndPosition && result.range.startOffset > maxIndex) || (returnEndPosition && result.range.endOffset > maxIndex)) break

// match found, try to find more after it
prevResult = result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ package com.maddyhome.idea.vim.regexp
public enum class VimRegexOptions {
IGNORE_CASE,
SMART_CASE,
WRAP_SCAN
WRAP_SCAN,
WANT_END_POSITION,
}

0 comments on commit 63995e8

Please sign in to comment.