Skip to content

Commit

Permalink
Fix spelling not formatting words with punctuation.
Browse files Browse the repository at this point in the history
i.e. missing because the "word" didn't match the misspelled one detected by jazzy.
  • Loading branch information
mattmess1221 committed Nov 11, 2015
1 parent fba3100 commit 37b550f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
17 changes: 10 additions & 7 deletions src/main/java/mnm/mods/tabbychat/extra/spell/Spellcheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Set;
import java.util.Iterator;
import java.util.List;

import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.Closeables;
import com.swabunga.spell.engine.SpellDictionary;
import com.swabunga.spell.engine.SpellDictionaryHashMap;
Expand All @@ -18,12 +20,12 @@

import mnm.mods.tabbychat.TabbyChat;

public class Spellcheck {
public class Spellcheck implements Iterable<SpellCheckEvent> {

private SpellChecker spellCheck;
private LangDict language;
private SpellDictionary userDict;
private Set<String> errors = Sets.newHashSet();
private List<SpellCheckEvent> errors = Lists.newArrayList();

public Spellcheck(File userDict) {
try {
Expand Down Expand Up @@ -54,7 +56,7 @@ public void loadLanguage(LangDict lang) throws IOException {
spellCheck.addSpellCheckListener(new SpellCheckListener() {
@Override
public synchronized void spellingError(SpellCheckEvent event) {
errors.add(event.getInvalidWord());
errors.add(event);
}
});
} finally {
Expand All @@ -74,8 +76,9 @@ public void checkSpelling(String string) {
}
}

public boolean isCorrect(String word) {
return !errors.contains(word);
@Override
public Iterator<SpellCheckEvent> iterator() {
return ImmutableList.copyOf(errors).iterator();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mnm.mods.tabbychat.extra.spell;

import com.google.common.base.Function;
import com.swabunga.spell.event.SpellCheckEvent;

import mnm.mods.tabbychat.TabbyChat;
import mnm.mods.util.ChatBuilder;
Expand All @@ -20,16 +21,18 @@ public SpellingFormatter(Spellcheck sp) {
public IChatComponent apply(String text) {
if (!TabbyChat.getInstance().settings.general.spelling.enabled.getValue())
return new ChatComponentText(text);
String[] split = text.split(" ");
ChatBuilder b = new ChatBuilder();
for (String word : split) {
b.text(word);
if (!spelling.isCorrect(word)) {
b.underline(Color.RED);
}
b.text(" ");
int prev = 0;
for (SpellCheckEvent event : spelling) {
int start = event.getWordContextPosition();
int end = event.getWordContextPosition() + event.getInvalidWord().length();

b.text(text.substring(prev, start));
b.text(text.substring(start, end)).underline(Color.RED);

prev = end;
}
return b.build();
return b.text(text.substring(prev)).build();
}

}

0 comments on commit 37b550f

Please sign in to comment.