Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
realtime spellcheck: make the brace pattern checking much more robust
  • Loading branch information
adamconroy committed Aug 21, 2019
1 parent 97af003 commit 8099b5e
Showing 1 changed file with 17 additions and 5 deletions.
Expand Up @@ -33,6 +33,7 @@
import org.rstudio.core.client.StringUtil; import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.jsonrpc.RequestLog; import org.rstudio.core.client.jsonrpc.RequestLog;
import org.rstudio.core.client.jsonrpc.RequestLogEntry; import org.rstudio.core.client.jsonrpc.RequestLogEntry;
import org.rstudio.core.client.regex.Match;
import org.rstudio.core.client.regex.Pattern; import org.rstudio.core.client.regex.Pattern;
import org.rstudio.studio.client.RStudioGinjector; import org.rstudio.studio.client.RStudioGinjector;
import org.rstudio.studio.client.common.spelling.model.SpellCheckerResult; import org.rstudio.studio.client.common.spelling.model.SpellCheckerResult;
Expand Down Expand Up @@ -376,12 +377,23 @@ public boolean shouldCheckSpelling(DocDisplay dd, Range r)
if (s.isYaml()) if (s.isYaml())
return false; return false;


// This will capture all blocked text in a way that the highlight rules // This will capture all braced text in a way that the
// don't and shouldn't // highlight rules don't and shouldn't.
int start = r.getStart().getColumn();
int end = start + word.length();
String line = dd.getLine(r.getStart().getRow()); String line = dd.getLine(r.getStart().getRow());
Pattern p = Pattern.create("\\{.*" + word + ".*\\}"); Pattern p = Pattern.create("\\{[^\\{\\}]*" + word + "[^\\{\\}]*\\}");
if (p.test(line)) Match m = p.match(line, 0);
return false; 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; return true;
} }
Expand Down

0 comments on commit 8099b5e

Please sign in to comment.