mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 23:12:47 +00:00
fix some issues with url detection, add tests for some more issues to be fixed
This commit is contained in:
parent
cf261bf5ef
commit
bc1557cc69
6 changed files with 137 additions and 50 deletions
|
@ -745,7 +745,6 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
}
|
||||
|
||||
// Going backward, find the first breaking point (separator)
|
||||
// todo: break if there are 2 consecutive sometimesWordConnectors (more complicated once again, great...)
|
||||
int startIndexInBefore = before.length();
|
||||
int endIndexInAfter = -1;
|
||||
while (startIndexInBefore > 0) {
|
||||
|
@ -758,9 +757,9 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
final char c = before.charAt(i);
|
||||
if (spacingAndPunctuations.isSometimesWordConnector(c)) {
|
||||
// if yes -> whitespace is the index
|
||||
startIndexInBefore = Math.max(StringUtils.charIndexOfLastWhitespace(before), 0);;
|
||||
startIndexInBefore = Math.max(StringUtils.charIndexOfLastWhitespace(before), 0);
|
||||
final int firstSpaceAfter = StringUtils.charIndexOfFirstWhitespace(after);
|
||||
endIndexInAfter = firstSpaceAfter == -1 ? (after.length() - 1) : firstSpaceAfter -1;
|
||||
endIndexInAfter = firstSpaceAfter == -1 ? after.length() : firstSpaceAfter -1;
|
||||
break;
|
||||
} else if (Character.isWhitespace(c)) {
|
||||
// if no, just break normally
|
||||
|
@ -789,7 +788,7 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
// if yes -> whitespace is next to the index
|
||||
startIndexInBefore = Math.max(StringUtils.charIndexOfLastWhitespace(before), 0);;
|
||||
final int firstSpaceAfter = StringUtils.charIndexOfFirstWhitespace(after);
|
||||
endIndexInAfter = firstSpaceAfter == -1 ? (after.length() - 1) : firstSpaceAfter - 1;
|
||||
endIndexInAfter = firstSpaceAfter == -1 ? after.length() : firstSpaceAfter - 1;
|
||||
break;
|
||||
} else if (Character.isWhitespace(c)) {
|
||||
// if no, just break normally
|
||||
|
@ -804,6 +803,12 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
}
|
||||
}
|
||||
|
||||
// strip stuff before "//" (i.e. ignore http and other protocols)
|
||||
final String beforeConsideringStart = before.subSequence(startIndexInBefore, before.length()).toString();
|
||||
final int protocolEnd = beforeConsideringStart.lastIndexOf("//");
|
||||
if (protocolEnd != -1)
|
||||
startIndexInBefore += protocolEnd + 1;
|
||||
|
||||
// we don't want the end characters to be word separators
|
||||
while (endIndexInAfter > 0 && spacingAndPunctuations.isWordSeparator(after.charAt(endIndexInAfter - 1))) {
|
||||
--endIndexInAfter;
|
||||
|
@ -1004,16 +1009,26 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
return mCommittedTextBeforeComposingText.lastIndexOf(" ") < mCommittedTextBeforeComposingText.lastIndexOf("@");
|
||||
}
|
||||
|
||||
public CharSequence textBeforeCursorUntilLastWhitespace() {
|
||||
int afterLastSpace = 0;
|
||||
public CharSequence textBeforeCursorUntilLastWhitespaceOrDoubleSlash() {
|
||||
int startIndex = 0;
|
||||
boolean previousWasSlash = false;
|
||||
for (int i = mCommittedTextBeforeComposingText.length() - 1; i >= 0; i--) {
|
||||
final char c = mCommittedTextBeforeComposingText.charAt(i);
|
||||
if (Character.isWhitespace(c)) {
|
||||
afterLastSpace = i + 1;
|
||||
startIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
if (c == '/') {
|
||||
if (previousWasSlash) {
|
||||
startIndex = i + 2;
|
||||
break;
|
||||
}
|
||||
previousWasSlash = true;
|
||||
} else {
|
||||
previousWasSlash = false;
|
||||
}
|
||||
}
|
||||
return mCommittedTextBeforeComposingText.subSequence(afterLastSpace, mCommittedTextBeforeComposingText.length());
|
||||
return mCommittedTextBeforeComposingText.subSequence(startIndex, mCommittedTextBeforeComposingText.length());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -895,7 +895,7 @@ public final class InputLogic {
|
|||
// but not if there are two consecutive sometimesWordConnectors (e.g. "...bla")
|
||||
&& !settingsValues.mSpacingAndPunctuations.isSometimesWordConnector(mConnection.getCharBeforeBeforeCursor())
|
||||
) {
|
||||
final CharSequence text = mConnection.textBeforeCursorUntilLastWhitespace();
|
||||
final CharSequence text = mConnection.textBeforeCursorUntilLastWhitespaceOrDoubleSlash();
|
||||
final TextRange range = new TextRange(text, 0, text.length(), text.length(), false);
|
||||
isComposingWord = true;
|
||||
restartSuggestions(range, mConnection.mExpectedSelStart);
|
||||
|
|
|
@ -138,8 +138,6 @@ public class SettingsValues {
|
|||
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
|
||||
@NonNull final InputAttributes inputAttributes) {
|
||||
mLocale = res.getConfiguration().locale;
|
||||
// Get the resources
|
||||
mSpacingAndPunctuations = new SpacingAndPunctuations(res);
|
||||
|
||||
// Store the input attributes
|
||||
mInputAttributes = inputAttributes;
|
||||
|
@ -221,7 +219,6 @@ public class SettingsValues {
|
|||
final InputMethodSubtype selectedSubtype = SubtypeSettingsKt.getSelectedSubtype(prefs);
|
||||
mSecondaryLocales = Settings.getSecondaryLocales(prefs, selectedSubtype.getLocale());
|
||||
mShowAllMoreKeys = selectedSubtype.isAsciiCapable() && prefs.getBoolean(Settings.PREF_SHOW_ALL_MORE_KEYS, false);
|
||||
|
||||
mColors = Settings.getColorsForCurrentTheme(context, prefs);
|
||||
|
||||
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
|
||||
|
@ -234,6 +231,7 @@ public class SettingsValues {
|
|||
);
|
||||
mUrlDetectionEnabled = prefs.getBoolean(Settings.PREF_URL_DETECTION, false);
|
||||
mPinnedKeys = Settings.readPinnedKeys(prefs);
|
||||
mSpacingAndPunctuations = new SpacingAndPunctuations(res, mUrlDetectionEnabled);
|
||||
}
|
||||
|
||||
public boolean isApplicationSpecifiedCompletionsOn() {
|
||||
|
|
|
@ -44,7 +44,7 @@ public final class SpacingAndPunctuations {
|
|||
public final boolean mUsesAmericanTypography;
|
||||
public final boolean mUsesGermanRules;
|
||||
|
||||
public SpacingAndPunctuations(final Resources res) {
|
||||
public SpacingAndPunctuations(final Resources res, final Boolean urlDetection) {
|
||||
// To be able to binary search the code point. See {@link #isUsuallyPrecededBySpace(int)}.
|
||||
mSortedSymbolsPrecededBySpace = StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_preceded_by_space));
|
||||
// To be able to binary search the code point. See {@link #isUsuallyFollowedBySpace(int)}.
|
||||
|
@ -60,7 +60,7 @@ public final class SpacingAndPunctuations {
|
|||
mSentenceSeparator, Constants.CODE_SPACE }, 0, 2);
|
||||
mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces);
|
||||
// make it empty if language doesn't have spaces, to avoid weird glitches
|
||||
mSortedSometimesWordConnectors = mCurrentLanguageHasSpaces ? StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_sometimes_word_connectors)) : new int[0];
|
||||
mSortedSometimesWordConnectors = (urlDetection && mCurrentLanguageHasSpaces) ? StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_sometimes_word_connectors)) : new int[0];
|
||||
final Locale locale = res.getConfiguration().locale;
|
||||
// Heuristic: we use American Typography rules because it's the most common rules for all
|
||||
// English variants. German rules (not "German typography") also have small gotchas.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.dslul.openboard.inputmethod.latin.spellcheck;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.view.textservice.SentenceSuggestionsInfo;
|
||||
|
@ -26,6 +27,7 @@ import android.view.textservice.TextInfo;
|
|||
import org.dslul.openboard.inputmethod.compat.TextInfoCompatUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
||||
import org.dslul.openboard.inputmethod.latin.settings.SpacingAndPunctuations;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.RunInLocale;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -82,7 +84,7 @@ public class SentenceLevelAdapter {
|
|||
new RunInLocale<SpacingAndPunctuations>() {
|
||||
@Override
|
||||
protected SpacingAndPunctuations job(final Resources r) {
|
||||
return new SpacingAndPunctuations(r);
|
||||
return new SpacingAndPunctuations(r, false);
|
||||
}
|
||||
};
|
||||
mSpacingAndPunctuations = job.runInLocale(res, locale);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue