How to avoid a caret stop at punctuation when it is not a word boundary?
In LaTeX we have constructs like \command for which it makes sense to handle them as one entity, so selection will select all of the \command in one go.
For this we have implemented a WordBoundaryFilter, which will return false when between a backslash and a command token.
However, the EditorActionUtil which handles the caret jumps, will stop between the backslash and command anyway, because the backslash is a punctuation character, and I don't see any way in which we could stop this.
For example, suppose we have <caret>\command and do ctrl + ->, then we would want to end up with \command<caret>, but the actual result is \<caret>command.
Specifically, in EditorActionUtil.java line 229, the code says if (wordStop.isAtEnd()) return isLexemeBoundary && !isWordStart(text, offset, isCamel) || isWordEnd(text, offset, isCamel); where wordStop.isAtEnd() is true.
Because we implemented the WordBoundaryFilter, isLexemeBoundary is false. However, then isWordEnd is checked, which will return true because in the isWordBoundary function at line 905 it says if (isPunctuation(word) && !isPunctuation(neighbor)) return true; for word = '\\' and neighbour = 'c', so this will return true.
I suppose isWordEnd is still being checked, when isLexemeBoundary clearly indicates we shouldn't stop here, because there might be punctuation in text or something at which you would want to stop, however it is inconvenient that this cannot be overridden.
Is there perhaps a way in which we could indicate that the \ in \command is not punctuation? But isJavaIdentifierPart('\\') of course returns false.
Previously, we had \command as one token, but in that case the EditorActionUtil would still stop in the middle of the token because of the punctuation.
Please sign in to leave a comment.
This is not possible using current API, unless you take full control of all actions like "Move Caret to Next Word" which seems very brittle approach. You may file a feature request.
I will do so, thanks for the comment!
[edit] submitted: https://youtrack.jetbrains.com/issue/IDEA-241360