Skip to content
Permalink
Browse files

realtime spellcheck: make the brace pattern checking much more robust

  • Loading branch information...
adamconroy committed Aug 21, 2019
1 parent 97af003 commit 8099b5e3cec8bb7fc9f8c2efbbe66bad0bac3310
Showing with 17 additions and 5 deletions.
  1. +17 −5 src/gwt/src/org/rstudio/studio/client/common/spelling/TypoSpellChecker.java
@@ -33,6 +33,7 @@
import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.jsonrpc.RequestLog;
import org.rstudio.core.client.jsonrpc.RequestLogEntry;
import org.rstudio.core.client.regex.Match;
import org.rstudio.core.client.regex.Pattern;
import org.rstudio.studio.client.RStudioGinjector;
import org.rstudio.studio.client.common.spelling.model.SpellCheckerResult;
@@ -376,12 +377,23 @@ public boolean shouldCheckSpelling(DocDisplay dd, Range r)
if (s.isYaml())
return false;

// This will capture all blocked text in a way that the highlight rules
// don't and shouldn't
// This will capture all braced text in a way that the
// highlight rules don't and shouldn't.
int start = r.getStart().getColumn();
int end = start + word.length();
String line = dd.getLine(r.getStart().getRow());
Pattern p = Pattern.create("\\{.*" + word + ".*\\}");
if (p.test(line))
return false;
Pattern p = Pattern.create("\\{[^\\{\\}]*" + word + "[^\\{\\}]*\\}");
Match m = p.match(line, 0);
while (m != null)
{
// ensure that the match is the specific word we're looking
// at to fix edge cases such as {asdf}asdf
if (m.getIndex() < start &&
(m.getIndex() + m.getValue().length()) > end)
return false;

m = m.nextMatch();
}

return true;
}

0 comments on commit 8099b5e

Please sign in to comment.
You can’t perform that action at this time.