Skip to content

Commit

Permalink
Fix #581: Overzealous Mark Occurrences for single characters
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbylight committed Nov 21, 2024
1 parent 294a830 commit 0e9d8d3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ public Token getTokenToMark(RSyntaxTextArea textArea) {
RSyntaxUtilities.isNonWordChar(t)) {
// Try to the "left" of the caret.
dot--;
t = null; // Clear in case it's a non-word char
try {
if (dot>=textArea.getLineStartOffset(line)) {
t = RSyntaxUtilities.getTokenAtOffset(tokenList, dot);
if (t != null && RSyntaxUtilities.isNonWordChar(t)) {
t = null;
}
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Never happens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,42 @@ void testGetTokenToMark_endOfWord() {
}


@Test
void testGetTokenToMark_none_atEndOfLineAfterNonWordChar() {

String origContent = "foo\n.";
RSyntaxTextArea textArea = createTextArea(SyntaxConstants.SYNTAX_STYLE_JAVA, origContent);
textArea.setCaretPosition(origContent.indexOf('.') + 1); // End of document

DefaultOccurrenceMarker marker = new DefaultOccurrenceMarker();
Assertions.assertNull(marker.getTokenToMark(textArea));
}


@Test
void testGetTokenToMark_none_betweenTwoNonWordChars() {

String origContent = "..";
RSyntaxTextArea textArea = createTextArea(SyntaxConstants.SYNTAX_STYLE_JAVA, origContent);
textArea.setCaretPosition(1); // Between the two periods

DefaultOccurrenceMarker marker = new DefaultOccurrenceMarker();
Assertions.assertNull(marker.getTokenToMark(textArea));
}


@Test
void testGetTokenToMark_none_atStartOfLinePrecedingNonWordChar() {

String origContent = "foo\n.";
RSyntaxTextArea textArea = createTextArea(SyntaxConstants.SYNTAX_STYLE_JAVA, origContent);
textArea.setCaretPosition(origContent.indexOf('.')); // Start of line before the period

DefaultOccurrenceMarker marker = new DefaultOccurrenceMarker();
Assertions.assertNull(marker.getTokenToMark(textArea));
}


@Test
void testIsValidType_validType() {

Expand Down

0 comments on commit 0e9d8d3

Please sign in to comment.