mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-01-05 01:42:49 +01:00
Fix StartOfWordMatcher & EndOfWordMatcher
This commit is contained in:
parent
6616b8dc07
commit
6ec712466c
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/regexp/engine/nfa/matcher
@ -10,6 +10,7 @@ package com.maddyhome.idea.vim.regexp.engine.nfa.matcher
|
||||
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.options.helpers.KeywordOptionHelper
|
||||
import com.maddyhome.idea.vim.regexp.match.VimMatchGroupCollection
|
||||
|
||||
/**
|
||||
@ -25,17 +26,10 @@ internal class EndOfWordMatcher : Matcher {
|
||||
): MatcherResult {
|
||||
if (index > editor.text().length || index == 0) return MatcherResult.Failure
|
||||
|
||||
val prevChar = editor.text()[index - 1]
|
||||
val isKeywordAtIndex = KeywordOptionHelper.isKeyword(editor, editor.text()[index])
|
||||
val isKeywordBeforeIndex = editor.text().getOrNull(index - 1)?.let { KeywordOptionHelper.isKeyword(editor, it) } ?: false
|
||||
|
||||
/**
|
||||
* The current index is the end of a word if the previous one
|
||||
* is a keyword character, and the current one isn't.
|
||||
*/
|
||||
return if (
|
||||
(prevChar.isLetterOrDigit() || prevChar == '_') &&
|
||||
(index == editor.text().length || !(editor.text()[index].isLetterOrDigit() || editor.text()[index] == '_'))
|
||||
) MatcherResult.Success(0)
|
||||
else MatcherResult.Failure
|
||||
return if (isKeywordBeforeIndex && !isKeywordAtIndex) MatcherResult.Success(0) else MatcherResult.Failure
|
||||
}
|
||||
|
||||
override fun isEpsilon(): Boolean {
|
||||
|
@ -10,6 +10,7 @@ package com.maddyhome.idea.vim.regexp.engine.nfa.matcher
|
||||
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.options.helpers.KeywordOptionHelper
|
||||
import com.maddyhome.idea.vim.regexp.match.VimMatchGroupCollection
|
||||
|
||||
/**
|
||||
@ -25,17 +26,10 @@ internal class StartOfWordMatcher : Matcher {
|
||||
): MatcherResult {
|
||||
if (index >= editor.text().length) return MatcherResult.Failure
|
||||
|
||||
val char = editor.text()[index]
|
||||
val isKeywordAtIndex = KeywordOptionHelper.isKeyword(editor, editor.text()[index])
|
||||
val isKeywordBeforeIndex = editor.text().getOrNull(index - 1)?.let { KeywordOptionHelper.isKeyword(editor, it) } ?: false
|
||||
|
||||
/**
|
||||
* The current index is the start of a word if it is a keyword character,
|
||||
* and the previous index isn't.
|
||||
*/
|
||||
return if (
|
||||
(char.isLetterOrDigit() || char == '_') &&
|
||||
(index == 0 || !(editor.text()[index - 1].isLetterOrDigit() || editor.text()[index - 1] == '_'))
|
||||
) MatcherResult.Success(0)
|
||||
else MatcherResult.Failure
|
||||
return if (!isKeywordBeforeIndex && isKeywordAtIndex) MatcherResult.Success(0) else MatcherResult.Failure
|
||||
}
|
||||
|
||||
override fun isEpsilon(): Boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user