Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex #725

Merged
merged 259 commits into from
Feb 5, 2024
Merged

Regex #725

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
259 commits
Select commit Hold shift + click to select a range
312787b
adding comments to parser grammar
emanuelgestosa Jul 26, 2023
7daee88
regex very magic and very nomagic modes
emanuelgestosa Jul 27, 2023
e22db74
lexer support for unicode characters
emanuelgestosa Jul 27, 2023
1c9b76c
unicode chars in all lexer modes
emanuelgestosa Jul 27, 2023
918c564
support unicode in collections
emanuelgestosa Jul 27, 2023
8e12b9e
lexer fixing what chars are taken literally
emanuelgestosa Jul 27, 2023
5ee2e24
adding some zero-width tokens
emanuelgestosa Jul 28, 2023
2487e54
initial nfa definition
emanuelgestosa Aug 1, 2023
b7583bc
initial nfa
emanuelgestosa Aug 2, 2023
e36ee0b
nfa simulation uses VimEditor instead of String
emanuelgestosa Aug 2, 2023
697b648
skeleton for NFA testing
emanuelgestosa Aug 2, 2023
60988d0
implementing quantifiers
emanuelgestosa Aug 3, 2023
978a1d0
updating comments
emanuelgestosa Aug 3, 2023
e64c68c
add nfa test for escaped character
emanuelgestosa Aug 3, 2023
6cfed73
implementing grouping
emanuelgestosa Aug 3, 2023
a320ca2
add test for empty group
emanuelgestosa Aug 3, 2023
b93b7e5
use IntRange for match range
emanuelgestosa Aug 3, 2023
b777112
VimMatchResult stores matched string value
emanuelgestosa Aug 3, 2023
3fd311f
capture group submatch
emanuelgestosa Aug 4, 2023
20183c0
add test for updating capture group
emanuelgestosa Aug 4, 2023
06e8c40
fixing quantifiers
emanuelgestosa Aug 4, 2023
839ec05
more correct way of handling quantifiers
emanuelgestosa Aug 7, 2023
dc13db1
fix nfa looping in epsilon transitions
emanuelgestosa Aug 7, 2023
276709c
adding comments
emanuelgestosa Aug 7, 2023
4ef04e1
containsMatchIn API function
emanuelgestosa Aug 7, 2023
d154b0a
find API function
emanuelgestosa Aug 7, 2023
4ee268e
findAll API function
emanuelgestosa Aug 7, 2023
b18e6c3
commenting findAll
emanuelgestosa Aug 7, 2023
1d3f0c9
implementing dot
emanuelgestosa Aug 7, 2023
988ac7d
dot with and without newline
emanuelgestosa Aug 7, 2023
2c5d9cb
implementing cursor and using mockito to mock editor
emanuelgestosa Aug 7, 2023
6ab8964
char classes and collections base code
emanuelgestosa Aug 7, 2023
d97800c
ascii character classes
emanuelgestosa Aug 8, 2023
c93cea4
implementing custom collections
emanuelgestosa Aug 8, 2023
dc510b6
add test for collection with not special escaped character
emanuelgestosa Aug 8, 2023
46c2611
support unicode escape sequence in collections
emanuelgestosa Aug 8, 2023
9866acd
set match start and end \zs \ze
emanuelgestosa Aug 9, 2023
d4981f3
all named character classes
emanuelgestosa Aug 9, 2023
4355d5a
parsing lazy quantifiers
emanuelgestosa Aug 9, 2023
69fdeeb
implementing and testing lazy quantifiers
emanuelgestosa Aug 9, 2023
0ec71ac
refactor Matcher to return number of consumed characters
emanuelgestosa Aug 9, 2023
ccd21fa
parsing backreferences
emanuelgestosa Aug 9, 2023
405cb42
testing and implementing backreferences
emanuelgestosa Aug 9, 2023
a2e94c2
parsing character classes with new line
emanuelgestosa Aug 9, 2023
2979feb
implementing character classes with EOL
emanuelgestosa Aug 9, 2023
ba39c4d
matchAt API function
emanuelgestosa Aug 9, 2023
5973af8
adding comments to Matchers
emanuelgestosa Aug 10, 2023
02ded82
adding failing backreferences test
emanuelgestosa Aug 10, 2023
3466653
fix capturing groups not updating properly
emanuelgestosa Aug 10, 2023
f58610f
cleaning adding transitions to states
emanuelgestosa Aug 10, 2023
8b427d1
fix quantified capture groups not updating properly
emanuelgestosa Aug 10, 2023
5818f7d
matchEntire API function
emanuelgestosa Aug 10, 2023
091b2bb
matches API function
emanuelgestosa Aug 10, 2023
e9d1a73
matchesAt API function
emanuelgestosa Aug 10, 2023
2671d27
ignore case tokens
emanuelgestosa Aug 11, 2023
a04af5d
add test for case insensitive matching
emanuelgestosa Aug 11, 2023
951f9c3
character classes never ignore case
emanuelgestosa Aug 11, 2023
4741052
start and end of file
emanuelgestosa Aug 11, 2023
78da673
collection matcher uses set instead of list
emanuelgestosa Aug 11, 2023
e7a8a52
adding comments on new Matchers
emanuelgestosa Aug 11, 2023
eef98ec
adding tests for empty editors
emanuelgestosa Aug 11, 2023
757e3d9
start and end of line anchors
emanuelgestosa Aug 14, 2023
897810b
parsing start and end line anywhere in pattern
emanuelgestosa Aug 14, 2023
a644afc
implement and test start and end of line anywhere in pattern
emanuelgestosa Aug 14, 2023
e004896
parsing atomic groups
emanuelgestosa Aug 14, 2023
779b023
adding tests for atomic groups
emanuelgestosa Aug 14, 2023
b971fbf
refactoring visitors to prepare for different types of multis
emanuelgestosa Aug 14, 2023
d751c1a
rename MultiBoundary to RangeBoundary
emanuelgestosa Aug 14, 2023
3f70197
placeholder for atomic groups
emanuelgestosa Aug 14, 2023
9454c36
implementing atomic groups
emanuelgestosa Aug 16, 2023
04e44d3
adding explanatory comment on wierd atomic group test
emanuelgestosa Aug 16, 2023
c81a1de
commenting new atomic groups code
emanuelgestosa Aug 16, 2023
79e945d
parsing start and end of word tokens
emanuelgestosa Aug 16, 2023
179d5fc
implementing and testing start and end of word tokens
emanuelgestosa Aug 16, 2023
08bb359
implementing collections with EOL \_[]
emanuelgestosa Aug 16, 2023
f158751
allow character codes inside collections \d \o \x \u \U
emanuelgestosa Aug 16, 2023
18486c8
allow special escape characters in collections \e \t \r \b \n
emanuelgestosa Aug 16, 2023
5f5aba3
dealing with atomic groups in a different way
emanuelgestosa Aug 16, 2023
498b2a6
parsing positive lookahead
emanuelgestosa Aug 16, 2023
2c96309
implementing positive lookahead
emanuelgestosa Aug 16, 2023
095b1ad
parsing negative lookahead
emanuelgestosa Aug 17, 2023
f4e7d94
add tests for negative lookahead
emanuelgestosa Aug 17, 2023
dc5694d
implementing negative lookahead
emanuelgestosa Aug 17, 2023
8889b59
add more lookahead tests
emanuelgestosa Aug 17, 2023
37be618
extract methods refactor in nfa simulation code
emanuelgestosa Aug 17, 2023
c5e27fd
refactoring inappropriate intimacy between nfa and nfaassertion classes
emanuelgestosa Aug 17, 2023
853521c
adding comments and small cleanups
emanuelgestosa Aug 17, 2023
c00f736
adding tests for nested lookahead tokens
emanuelgestosa Aug 17, 2023
b208ae0
add more failing lookahead tests
emanuelgestosa Aug 18, 2023
d511a86
moving all parsing logic to VimRegexParser class
emanuelgestosa Aug 18, 2023
bd94e51
refactoring temporary field out of parser class
emanuelgestosa Aug 18, 2023
b21fbbf
parser class is now a singleton
emanuelgestosa Aug 18, 2023
c906af2
pattern visitor is now a singleton
emanuelgestosa Aug 21, 2023
036bc70
making nested lookahead tests pass
emanuelgestosa Aug 21, 2023
69ff84d
add more lookahead tests
emanuelgestosa Aug 21, 2023
67f328f
documenting regex code
emanuelgestosa Aug 21, 2023
e5b217a
parsing ~ token
emanuelgestosa Aug 21, 2023
4b2d85d
parsing lookbehind tokens
emanuelgestosa Aug 21, 2023
a144ef9
parse visual \%V token
emanuelgestosa Aug 21, 2023
43826ab
parsing collection char class expressions
emanuelgestosa Aug 22, 2023
f5f30e0
adding new parser tests for collection char classes
emanuelgestosa Aug 22, 2023
ef28b79
adding nfa tests for collection char classes expressions
emanuelgestosa Aug 22, 2023
43bd3f8
base code for char classes expressions
emanuelgestosa Aug 22, 2023
94c558a
alpha class visitor
emanuelgestosa Aug 22, 2023
4100a79
alnum class visitor
emanuelgestosa Aug 22, 2023
8fa53b9
blank class visitor
emanuelgestosa Aug 22, 2023
c705544
cntrl class visitor
emanuelgestosa Aug 22, 2023
ad0768f
digit class visitor
emanuelgestosa Aug 22, 2023
8235ebb
graph class visitor
emanuelgestosa Aug 22, 2023
b360b36
lower class visitor
emanuelgestosa Aug 22, 2023
27ffdb1
print class visitor
emanuelgestosa Aug 22, 2023
2578fcb
punct class visitor
emanuelgestosa Aug 22, 2023
8bcfa9e
space class visitor
emanuelgestosa Aug 22, 2023
f5998e0
upper class visitor
emanuelgestosa Aug 22, 2023
79e19cc
xdigit class
emanuelgestosa Aug 22, 2023
9fe742c
return, tab, escape, backspace class visitors
emanuelgestosa Aug 22, 2023
877bb0d
ident class visitor
emanuelgestosa Aug 22, 2023
2804b8c
keyword class visitor
emanuelgestosa Aug 22, 2023
b9c9d96
fname class visitor
emanuelgestosa Aug 22, 2023
709fd30
fixing collections with only char class expressions
emanuelgestosa Aug 22, 2023
9e2c782
allow for a state to have multiple assertitions
emanuelgestosa Aug 22, 2023
ec24c05
adding nfa tests for \& operator
emanuelgestosa Aug 23, 2023
e9b7cab
implementing \& operator
emanuelgestosa Aug 23, 2023
686e6d6
add more complex \& tests
emanuelgestosa Aug 23, 2023
7f9527c
reworking nfa to ignore input until first match
emanuelgestosa Aug 24, 2023
f1a62a2
adding tests for positive lookbehind
emanuelgestosa Aug 24, 2023
72e44c3
visitor for positive lookbehind
emanuelgestosa Aug 24, 2023
f18de95
implementing positive lookbehind
emanuelgestosa Aug 24, 2023
1871f0b
add tests for negative lookbehind
emanuelgestosa Aug 24, 2023
23205c8
implementing negative lookbehind
emanuelgestosa Aug 24, 2023
9c7deac
parsing limited lookbehinds
emanuelgestosa Aug 24, 2023
c568286
implement limit lookbehinds
emanuelgestosa Aug 24, 2023
e0dacf8
adding tests for limited lookbehinds
emanuelgestosa Aug 24, 2023
3e4be59
fix lookbehinds matches not ending where they were supposed to
emanuelgestosa Aug 24, 2023
0312ef9
visitor for negative limited lookbehind
emanuelgestosa Aug 25, 2023
821f728
adding comments
emanuelgestosa Aug 25, 2023
20bbe3d
using TextRange instead of IntRange
emanuelgestosa Aug 28, 2023
449e4b8
fixing rebase problems
emanuelgestosa Aug 31, 2023
1d68009
parsing match character by code
emanuelgestosa Aug 31, 2023
3d9a04d
visitors for character codes
emanuelgestosa Aug 31, 2023
8895233
tests for match character by code
emanuelgestosa Aug 31, 2023
1d4aba4
fixing mixing % in match character by code tokens
emanuelgestosa Aug 31, 2023
e0bf04a
fixing octal codes larger than 0o377
emanuelgestosa Aug 31, 2023
ddfc5dc
allow larger decimal codes inside collections
emanuelgestosa Sep 1, 2023
231e0d3
parsing line related tokens
emanuelgestosa Sep 4, 2023
7772175
parsing column related tokens
emanuelgestosa Sep 4, 2023
930df31
tests for line and column tokens
emanuelgestosa Sep 4, 2023
1c16b9a
matchers for line and column tokens
emanuelgestosa Sep 4, 2023
cc7205a
visitors for line and column tokens
emanuelgestosa Sep 4, 2023
09f3763
mocking VimEditor.offsetToBuffer position and fixing visitors
emanuelgestosa Sep 4, 2023
9e068be
parsing cursor line tokens
emanuelgestosa Sep 6, 2023
188d1e0
parsing cursor column tokens
emanuelgestosa Sep 6, 2023
0db5431
matchers for cursor line anc column tokens
emanuelgestosa Sep 6, 2023
c4ed20a
nfa tests for cursor line and column tokens
emanuelgestosa Sep 6, 2023
fd3ec17
visitors for cursor line and column tokens
emanuelgestosa Sep 6, 2023
016fcd6
fixing cursor line and column matchers
emanuelgestosa Sep 6, 2023
bd815c8
tests receive caret indexes in the text
emanuelgestosa Sep 7, 2023
0306372
refactoring editor mock methods
emanuelgestosa Sep 7, 2023
5ba4616
cleaning multiline strings in tests
emanuelgestosa Sep 7, 2023
9c988f5
new NFA doTest method
emanuelgestosa Sep 7, 2023
641c028
using multi line strings in VimRegexTest
emanuelgestosa Sep 7, 2023
c56b80f
dividing regex tests into internal and public api tests
emanuelgestosa Sep 7, 2023
c4c9cdf
dividing regex api tests into seperate classes
emanuelgestosa Sep 7, 2023
fb46666
new doTest method for VimRegexTest
emanuelgestosa Sep 7, 2023
ca644a1
parsing optionally matched atoms tokens
emanuelgestosa Sep 8, 2023
46a69ad
tests for optionally matched sequence
emanuelgestosa Sep 8, 2023
77fc0ce
visitor for optionally matched sequence
emanuelgestosa Sep 8, 2023
381ce47
fixing parsing of optionally matched sequence
emanuelgestosa Sep 8, 2023
fb31704
visual columns matching
emanuelgestosa Sep 8, 2023
b049e9a
mock visual selection
emanuelgestosa Sep 11, 2023
787b7d1
nfa tests for matching inside visual area
emanuelgestosa Sep 11, 2023
f81ce2f
visual area matcher
emanuelgestosa Sep 11, 2023
e456bfb
visitor for visual area token
emanuelgestosa Sep 11, 2023
9937276
fix tests not detecting visual area selection properly
emanuelgestosa Sep 11, 2023
7a8cab1
parsing mark related tokens
emanuelgestosa Sep 11, 2023
e24eb42
parsing more mark registers
emanuelgestosa Sep 11, 2023
a604be7
matchers for mark related tokens
emanuelgestosa Sep 11, 2023
8fb9a38
mock mark related methods for regex testing
emanuelgestosa Sep 13, 2023
63a3539
tests for mark related tokens
emanuelgestosa Sep 13, 2023
20ec90e
visitors for mark related tokens
emanuelgestosa Sep 13, 2023
bd17363
test for tokens belonging to the same cursor
emanuelgestosa Sep 13, 2023
5535eaf
assuring that all cursor and mark tokens belong to the same cursor
emanuelgestosa Sep 13, 2023
27afd5f
assuring that visual selection tokens belong to the same cursor
emanuelgestosa Sep 13, 2023
49a820a
test for pattern with multiple cursors
emanuelgestosa Sep 13, 2023
0885eec
assuring that cursor line and column tokens belong to the same cursor
emanuelgestosa Sep 13, 2023
011f70b
clearing some TODOS in VimRegex
emanuelgestosa Sep 14, 2023
80402f1
trying to get antlr to report vim errors
emanuelgestosa Sep 14, 2023
5a90fb3
changing find to findNext
emanuelgestosa Sep 14, 2023
a17274e
new findPrevious API method
emanuelgestosa Sep 14, 2023
714ece1
cleaning comments
emanuelgestosa Sep 15, 2023
e9b3703
refactoring nfa simulation logic to its own class
emanuelgestosa Sep 15, 2023
4c05825
commenting new classes
emanuelgestosa Sep 15, 2023
b067f07
rename NFATest to VimRegexEngineTest
emanuelgestosa Sep 15, 2023
1ba1c52
findAll returns List instead of Sequence
emanuelgestosa Sep 15, 2023
5b85a85
stop using non-exact start nfas
emanuelgestosa Sep 15, 2023
e89b6f9
getting rid of handleTransition method
emanuelgestosa Sep 18, 2023
ed2f27d
use explicit stack instead of recursion for backtracking
emanuelgestosa Sep 18, 2023
4cab861
adding useNewEngine option
emanuelgestosa Sep 18, 2023
93a1ad5
integrating findNext and findPrevious
emanuelgestosa Sep 19, 2023
3dcd20a
fix findPrevious not finding matches that start at end-of-line
emanuelgestosa Sep 19, 2023
d0c76e6
fix findNext getting stuck at line ends
emanuelgestosa Sep 19, 2023
d1d2ce0
integrating findAll
emanuelgestosa Sep 19, 2023
7b24a3b
using useNewRegex option
emanuelgestosa Sep 19, 2023
f64c397
use non-exact nfas for slightly faster matches
emanuelgestosa Sep 19, 2023
a2d0b00
throwing and catching VimRegexException
emanuelgestosa Sep 19, 2023
643cd8f
showing pattern not found error
emanuelgestosa Sep 19, 2023
144c12a
fixing patterns with single ^ or $
emanuelgestosa Sep 19, 2023
7f54a33
fixing patterns with just a AND operator
emanuelgestosa Sep 19, 2023
d4842fb
using the count parameter in find()
emanuelgestosa Sep 19, 2023
3d9a3bb
fixing findPrevious not wraping around in some cases
emanuelgestosa Sep 19, 2023
972d6a8
show pattern not found error message
emanuelgestosa Sep 19, 2023
324b7c7
allow findAll to have a max index
emanuelgestosa Sep 19, 2023
3e35fa5
adding usenewregex option to set command tests
emanuelgestosa Sep 20, 2023
b77ce58
VimRegex methods now receive options
emanuelgestosa Sep 20, 2023
d743f8e
testing VimRegex with smartcase set
emanuelgestosa Sep 20, 2023
69e8c1e
using options in findPrevious
emanuelgestosa Sep 20, 2023
3b71378
integrating options into the main module
emanuelgestosa Sep 20, 2023
e27b8c2
VimRegex uses wrapscan option
emanuelgestosa Sep 20, 2023
657b612
working on implicit DFA algorithm optimization
emanuelgestosa Sep 27, 2023
4b21339
test for \c token always taking priority
emanuelgestosa Sep 27, 2023
08d2f9d
\c token can't get overrided by \C
emanuelgestosa Sep 27, 2023
cfe2dee
integrating new regex into global command
emanuelgestosa Sep 27, 2023
9e84307
substitute command working with new engine
emanuelgestosa Oct 4, 2023
46663cd
deprecating SearchHelper find and findAll
emanuelgestosa Oct 6, 2023
362b262
use injector for IjVimSearchHelper calls
emanuelgestosa Oct 6, 2023
eed2fc1
deprecating most of SearchHelper
emanuelgestosa Oct 6, 2023
5890dfb
working on processSearchCommand
emanuelgestosa Oct 10, 2023
b005eee
working on kotlin implementation of SearchGroup class
emanuelgestosa Oct 11, 2023
2a80a52
creating new IjVimSearchGroup class
emanuelgestosa Oct 12, 2023
597decd
moving seach methods back to VimSearchGroup base
emanuelgestosa Oct 13, 2023
871d28e
fixing nohlsearch command
emanuelgestosa Oct 15, 2023
6fe85c5
fixing some error messages
emanuelgestosa Oct 15, 2023
4207fe0
marking classes as deprecated
emanuelgestosa Oct 15, 2023
1db848e
getting rid of usages of deprecated classes
emanuelgestosa Oct 15, 2023
0f05b52
adding comments and small refactors
emanuelgestosa Oct 16, 2023
9ed2c34
removing print
emanuelgestosa Oct 16, 2023
42b13d7
Hide method and add Deprecated annotation
lippfi Dec 8, 2023
ed8c496
Simplify MarkMatchers
lippfi Dec 8, 2023
21f8a11
Fix StartOfWordMatcher & EndOfWordMatcher
lippfi Dec 8, 2023
ff8deb9
Fix Keyword token
lippfi Dec 8, 2023
778c5fa
Fix tests
lippfi Dec 8, 2023
071df35
Fix visual matching
lippfi Dec 8, 2023
0a314cd
Remove deprecated code
lippfi Dec 8, 2023
e66624b
Better SelectionInfo implementation
lippfi Dec 9, 2023
0177eb2
Minor improvements
lippfi Dec 9, 2023
853cbbc
Fix VisualAreaMatcher & TextRange
lippfi Dec 9, 2023
ab65ded
Move more tests to src
lippfi Dec 9, 2023
1292723
Fix compilation
lippfi Dec 9, 2023
a54e90c
Enable new regex engine by default
lippfi Dec 9, 2023
eeb4e85
Support e flag for search
lippfi Dec 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

# Generated by gradle task "generateGrammarSource"
src/main/java/com/maddyhome/idea/vim/vimscript/parser/generated
vim-engine/src/main/java/com/maddyhome/idea/vim/regexp/parser/generated
# Generated JSONs for lazy classloading
/vim-engine/src/main/resources/ksp-generated
/src/main/resources/ksp-generated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ internal class VimMultipleCursorsExtension : VimExtension {

// Note that ignoreCase is not overridden by the `\C` in the pattern
val pattern = makePattern(text, whole)
val matches = SearchHelper.findAll(editor, pattern, 0, -1, false)
val matches = injector.searchHelper.findAll(IjVimEditor(editor), pattern, 0, -1, false)
for (match in matches) {
if (match.contains(primaryCaret.offset)) {
primaryCaret.vim.moveToOffset(match.startOffset)
Expand Down Expand Up @@ -322,7 +322,7 @@ internal class VimMultipleCursorsExtension : VimExtension {
searchOptions.add(SearchOptions.WRAP)
}

return SearchHelper.findPattern(editor, makePattern(text, whole), startOffset, 1, searchOptions)?.startOffset ?: -1
return injector.searchHelper.findPattern(IjVimEditor(editor), makePattern(text, whole), startOffset, 1, searchOptions)?.startOffset ?: -1
}

private fun makePattern(text: String, whole: Boolean): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public open class GlobalIjOptions(scope: OptionAccessScope) : OptionsPropertiesB
public var oldundo: Boolean by optionProperty(IjOptions.oldundo)
public var unifyjumps: Boolean by optionProperty(IjOptions.unifyjumps)
public var exCommandAnnotation: Boolean by optionProperty(IjOptions.exCommandAnnotation)
public var vimscriptFunctionAnnotation: Boolean by optionProperty(IjOptions.vimscriptFunctionAnnotation)
public var commandOrMotionAnnotation: Boolean by optionProperty(IjOptions.commandOrMotionAnnotation)
public var useNewRegex: Boolean by optionProperty(IjOptions.useNewRegex)
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/group/IjOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public object IjOptions {
public val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true))
public val visualdelay: UnsignedNumberOption = addOption(UnsignedNumberOption("visualdelay", GLOBAL, "visualdelay", 100))
public val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", false, isTemporary = true))
public val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true, isTemporary = true))
public val commandOrMotionAnnotation: ToggleOption = addOption(ToggleOption("commandormotionannotation", GLOBAL, "commandormotionannotation", true, isTemporary = true))
public val showmodewidget: ToggleOption = addOption(ToggleOption("showmodewidget", GLOBAL, "showmodewidget", false, isTemporary = true))
public val useNewRegex: ToggleOption = addOption(ToggleOption("usenewregex", GLOBAL, "usenewregex", true, isTemporary = true))

// This needs to be Option<out VimDataType> so that it can work with derived option types, such as NumberOption, which
// derives from Option<VimInt>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import javax.swing.SwingUtilities
public class ProcessGroup : VimProcessGroupBase() {
override var lastCommand: String? = null
private set
override var isCommandProcessing: Boolean = false
override var modeBeforeCommandProcessing: Mode? = null

public override fun startSearchCommand(editor: VimEditor, context: ExecutionContext, count: Int, leader: Char) {
// Don't allow searching in one line editors
Expand Down Expand Up @@ -79,6 +81,8 @@ public class ProcessGroup : VimProcessGroupBase() {
"Cannot enable cmd mode from current mode $currentMode"
}

isCommandProcessing = true
modeBeforeCommandProcessing = currentMode
val initText = getRange(editor, cmd)
injector.markService.setVisualSelectionMarks(editor)
editor.vimStateMachine.mode = Mode.CMD_LINE(currentMode)
Expand Down Expand Up @@ -134,6 +138,9 @@ public class ProcessGroup : VimProcessGroupBase() {
logger.error(bad)
VimPlugin.indicateError()
res = false
} finally {
isCommandProcessing = false
modeBeforeCommandProcessing = null
}

return res
Expand Down
170 changes: 114 additions & 56 deletions src/main/java/com/maddyhome/idea/vim/group/SearchGroup.java

Large diffs are not rendered by default.

60 changes: 55 additions & 5 deletions src/main/java/com/maddyhome/idea/vim/helper/SearchHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.EngineEditorHelperKt;
import com.maddyhome.idea.vim.api.VimEditor;
import com.maddyhome.idea.vim.regexp.*;
import com.maddyhome.idea.vim.regexp.match.VimMatchResult;
import com.maddyhome.idea.vim.state.mode.Mode;
import com.maddyhome.idea.vim.state.VimStateMachine;
import com.maddyhome.idea.vim.common.CharacterPosition;
import com.maddyhome.idea.vim.common.Direction;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.newapi.IjVimCaret;
import com.maddyhome.idea.vim.newapi.IjVimEditor;
import com.maddyhome.idea.vim.regexp.CharPointer;
import com.maddyhome.idea.vim.regexp.RegExp;
import kotlin.Pair;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand All @@ -42,10 +42,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
import static com.maddyhome.idea.vim.api.VimInjectorKt.options;
import static com.maddyhome.idea.vim.api.VimInjectorKt.*;
import static com.maddyhome.idea.vim.helper.SearchHelperKtKt.checkInString;
import static com.maddyhome.idea.vim.helper.SearchHelperKtKt.shouldIgnoreCase;
import static com.maddyhome.idea.vim.newapi.IjVimInjectorKt.globalIjOptions;

/**
* Helper methods for searching text
Expand All @@ -59,6 +59,8 @@ public static String makeSearchPattern(String pattern, Boolean whole) {
/**
* Find text matching the given pattern.
*
* @deprecated Use IjVimSearchHelper.findPattern instead
*
* <p>See search.c:searchit</p>
*
* @param editor The editor to search in
Expand All @@ -69,12 +71,13 @@ public static String makeSearchPattern(String pattern, Boolean whole) {
* @return A TextRange representing the result, or null
*/
@Nullable
@Deprecated
public static TextRange findPattern(@NotNull Editor editor,
@Nullable String pattern,
int startOffset,
int count,
EnumSet<SearchOptions> searchOptions) {
if (pattern == null || pattern.length() == 0) {
if (pattern == null || pattern.isEmpty()) {
logger.warn("Pattern is null or empty. Cannot perform search");
return null;
}
Expand Down Expand Up @@ -347,19 +350,42 @@ else if (lnum <= 0) {
/**
* Find all occurrences of the pattern.
*
* @deprecated Use IjVimSearchHelper.findall instead
*
* @param editor The editor to search in
* @param pattern The pattern to search for
* @param startLine The start line of the range to search for
* @param endLine The end line of the range to search for, or -1 for the whole document
* @param ignoreCase Case sensitive or insensitive searching
* @return A list of TextRange objects representing the results
*/
@Deprecated
public static @NotNull List<TextRange> findAll(@NotNull Editor editor,
@NotNull String pattern,
int startLine,
int endLine,
boolean ignoreCase) {
final List<TextRange> results = Lists.newArrayList();

if (globalIjOptions(injector).getUseNewRegex()) {
final List<VimRegexOptions> options = new ArrayList<>();
if (globalOptions(injector).getSmartcase()) options.add(VimRegexOptions.SMART_CASE);
if (globalOptions(injector).getIgnorecase()) options.add(VimRegexOptions.IGNORE_CASE);
VimEditor vimEditor = new IjVimEditor(editor);
try {
// TODO: we shouldn't care about the ignoreCase argument, and instead just look into the editor options.
// It would require a refactor, so for now prepend \c or \C to "force" ignoreCase
String newPattern = (ignoreCase ? "\\c" : "\\C") + pattern;
VimRegex regex = new VimRegex(newPattern);
List<VimMatchResult.Success> foundMatches = regex.findAll(vimEditor, vimEditor.getLineStartOffset(startLine), vimEditor.getLineEndOffset(endLine == -1 ? vimEditor.lineCount() - 1 : endLine) + 1, options);
for (VimMatchResult.Success match : foundMatches) results.add(match.getRange());
return results;
} catch (VimRegexException e) {
injector.getMessages().showStatusBarMessage(vimEditor, e.getMessage());
return results;
}
}

final int lineCount = new IjVimEditor(editor).lineCount();
final int actualEndLine = endLine == -1 ? lineCount - 1 : endLine;

Expand Down Expand Up @@ -402,6 +428,10 @@ else if (lnum <= 0) {
return results;
}

/**
* @deprecated Use IjVimSearchHelper.findSection instead
*/
@Deprecated
public static int findSection(@NotNull Editor editor, @NotNull Caret caret, char type, int dir, int count) {
CharSequence chars = editor.getDocument().getCharsSequence();
int line = caret.getLogicalPosition().line + dir;
Expand All @@ -428,6 +458,10 @@ public static int findSection(@NotNull Editor editor, @NotNull Caret caret, char
return res;
}

/**
* @deprecated Use IjVimSearchHelper.findUnmatchedBlock instead
*/
@Deprecated
public static int findUnmatchedBlock(@NotNull Editor editor, @NotNull Caret caret, char type, int count) {
CharSequence chars = editor.getDocument().getCharsSequence();
int pos = caret.getOffset();
Expand All @@ -447,6 +481,8 @@ public static int findUnmatchedBlock(@NotNull Editor editor, @NotNull Caret care
/**
* Find block enclosing the caret
*
* @deprecated Use IjVimSearchHelper.findBlockRange instead
*
* @param editor The editor to search in
* @param caret The caret currently at
* @param type The type of block, e.g. (, [, {, <
Expand Down Expand Up @@ -798,6 +834,10 @@ private static int ignoreWhitespaceAtLineStart(CharSequence seq, int lineStart,
}


/**
* @deprecated Use IjVimSearchHelper.findBlockTagRange instead
*/
@Deprecated
public static @Nullable TextRange findBlockTagRange(@NotNull Editor editor,
@NotNull Caret caret,
int count,
Expand Down Expand Up @@ -1330,6 +1370,10 @@ else if (hex && ((ch >= '0' && ch <= '9') || "abcdefABCDEF".indexOf(ch) >= 0)) {
return new TextRange(start, end);
}

/**
* @deprecated Use IjVimSearchHelper.findWordUnderCursor instead
*/
@Deprecated
@Contract("_, _, _, _, _, _, _ -> new")
public static @NotNull TextRange findWordUnderCursor(@NotNull Editor editor,
@NotNull Caret caret,
Expand Down Expand Up @@ -1515,10 +1559,16 @@ public static int findNextCharacterOnLine(@NotNull Editor editor, @NotNull Caret
}
}

/**
* @deprecated Use IjVimSearchHelper.findMethodStart instead
*/
public static int findMethodStart(@NotNull Editor editor, @NotNull Caret caret, int count) {
return PsiHelper.findMethodStart(editor, caret.getOffset(), count);
}

/**
* @deprecated Use IjVimSearchHelper.findMethodEnd instead
*/
public static int findMethodEnd(@NotNull Editor editor, @NotNull Caret caret, int count) {
return PsiHelper.findMethodEnd(editor, caret.getOffset(), count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.api.options
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.ex.ranges.LineRange
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.annotations.Contract
import java.awt.Color
Expand Down Expand Up @@ -105,7 +106,7 @@ private fun updateSearchHighlights(
val startLine = searchRange?.startLine ?: 0
val endLine = searchRange?.endLine ?: -1
val results =
SearchHelper.findAll(editor, pattern, startLine, endLine, shouldIgnoreCase(pattern, shouldIgnoreSmartCase))
injector.searchHelper.findAll(IjVimEditor(editor), pattern, startLine, endLine, shouldIgnoreCase(pattern, shouldIgnoreSmartCase))
if (results.isNotEmpty()) {
currentMatchOffset = findClosestMatch(editor, results, initialOffset, forwards)
highlightSearchResults(editor, pattern, results, currentMatchOffset)
Expand All @@ -119,7 +120,7 @@ private fun updateSearchHighlights(
}
if (shouldIgnoreSmartCase) searchOptions.add(SearchOptions.IGNORE_SMARTCASE)
if (!forwards) searchOptions.add(SearchOptions.BACKWARDS)
val result = SearchHelper.findPattern(editor, pattern, initialOffset, 1, searchOptions)
val result = injector.searchHelper.findPattern(IjVimEditor(editor), pattern, initialOffset, 1, searchOptions)
if (result != null) {
currentMatchOffset = result.startOffset
val results = listOf(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ internal object VimListenerManager {
if (VimPlugin.isNotEnabled()) return
MotionGroup.fileEditorManagerSelectionChangedCallback(event)
FileGroup.fileEditorManagerSelectionChangedCallback(event)
SearchGroup.fileEditorManagerSelectionChangedCallback(event)
VimPlugin.getSearch().fileEditorManagerSelectionChangedCallback(event)
OptionGroup.fileEditorManagerSelectionChangedCallback(event)
}
}
Expand Down
Loading
Loading