properly remove capitalized suggestions, fixes #170

This commit is contained in:
Helium314 2023-09-20 20:07:17 +02:00
parent 32fe3a1d90
commit 82d0d46ca3
2 changed files with 29 additions and 20 deletions

View file

@ -977,27 +977,38 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
}
final ExpandableBinaryDictionary contactsDict = group.getSubDict(Dictionary.TYPE_CONTACTS);
final boolean isInContacts;
if (contactsDict != null) {
isInContacts = contactsDict.isInDictionary(word);
if (isInContacts)
if (contactsDict.isInDictionary(word)) {
contactsDict.removeUnigramEntryDynamically(word); // will be gone until next reload of dict
} else isInContacts = false;
// add to blacklist if in main or contacts dictionaries
if ((isInContacts || (group.hasDict(Dictionary.TYPE_MAIN, null) && group.getDict(Dictionary.TYPE_MAIN).isValidWord(word)))
&& group.blacklist.add(word)) {
// write to file if word wasn't already in blacklist
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(() -> {
try {
FileOutputStream fos = new FileOutputStream(group.blacklistFileName, true);
fos.write((word + "\n").getBytes(StandardCharsets.UTF_8));
fos.close();
} catch (IOException e) {
Log.e(TAG, "Exception while trying to write blacklist", e);
}
});
addToBlacklist(word, group);
return;
}
}
if (!group.hasDict(Dictionary.TYPE_MAIN, null))
return;
if (group.getDict(Dictionary.TYPE_MAIN).isValidWord(word)) {
addToBlacklist(word, group);
return;
}
final String lowercase = word.toLowerCase(group.mLocale);
if (group.getDict(Dictionary.TYPE_MAIN).isValidWord(lowercase)) {
addToBlacklist(lowercase, group);
}
}
private void addToBlacklist(final String word, final DictionaryGroup group) {
if (!group.blacklist.add(word))
return;
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(() -> {
try {
Log.i("test1", "adding to blacklist file" + group.blacklistFileName);
FileOutputStream fos = new FileOutputStream(group.blacklistFileName, true);
fos.write((word + "\n").getBytes(StandardCharsets.UTF_8));
fos.close();
} catch (IOException e) {
Log.e(TAG, "Exception while trying to write blacklist", e);
}
});
}
private ArrayList<String> readBlacklistFile(final String filename) {

View file

@ -839,7 +839,6 @@ public final class InputLogic {
)
)
) {
Log.i("test1", "separator");
handleSeparatorEvent(event, inputTransaction, handler);
} else {
if (SpaceState.PHANTOM == inputTransaction.getMSpaceState()) {
@ -854,7 +853,6 @@ public final class InputLogic {
commitTyped(sv, LastComposedWord.NOT_A_SEPARATOR);
}
}
Log.i("test1", "nonseparator");
handleNonSeparatorEvent(event, sv, inputTransaction);
}
}