Fix potential crash related to fullContext

This commit is contained in:
Aleksandras Kostarevas 2024-03-12 11:44:33 -05:00
parent b13e04d3f1
commit a294d9c4ca

View File

@ -686,11 +686,15 @@ public final class RichInputConnection implements PrivateCommandPerformer {
NgramContext ngramContext = NgramContextUtils.getNgramContextFromNthPreviousWord( NgramContext ngramContext = NgramContextUtils.getNgramContextFromNthPreviousWord(
prev, spacingAndPunctuations, n); prev, spacingAndPunctuations, n);
ngramContext.fullContext = getTextBeforeCursor(4096, 0).toString(); CharSequence seq = getTextBeforeCursor(4096, 0);
if(seq != null) {
if(ngramContext.fullContext.length() == 4096) { ngramContext.fullContext = seq.toString();
ngramContext.fullContext = String.join(" ",ngramContext.fullContext.split(" ")).substring(ngramContext.fullContext.split(" ")[0].length()+1);
if (ngramContext.fullContext.length() == 4096) {
ngramContext.fullContext = String.join(" ", ngramContext.fullContext.split(" ")).substring(ngramContext.fullContext.split(" ")[0].length() + 1);
}
} else {
ngramContext.fullContext = "";
} }
return ngramContext; return ngramContext;