Reduce amount of unwanted automatic space insertions

This commit is contained in:
Helium314 2023-06-26 15:24:34 +02:00
parent cfa27dbb7f
commit 7b743db65a
4 changed files with 28 additions and 2 deletions

View file

@ -13,7 +13,7 @@ Plan / to do:
* ~make additional dictionaries available for download (from OpenBoard PRs)~
* multi-lingual typing, https://github.com/openboard-team/openboard/pull/593
* ~suggestion fixes, https://github.com/openboard-team/openboard/pull/694, https://github.com/openboard-team/openboard/issues/795, https://github.com/openboard-team/openboard/issues/660~
* improve auto-space insertion, https://github.com/openboard-team/openboard/pull/576
* ~improve auto-space insertion, https://github.com/openboard-team/openboard/pull/576~
* emoji prediction/search, either https://github.com/openboard-team/openboard/pull/749 or use dictionaries
* theming, https://github.com/openboard-team/openboard/issues/124
* delete suggestions, https://github.com/openboard-team/openboard/issues/106
@ -32,6 +32,7 @@ Changes:
* add Galician dictionary for download, from https://github.com/chavaone/openboard/blob/master/dictionaries/es_GL_wordlist.combined.gz / https://github.com/openboard-team/openboard/pull/291
* fix suggestions after some characters, https://github.com/openboard-team/openboard/pull/694, https://github.com/openboard-team/openboard/issues/795
* fix suggestions sometimes not being shown, https://github.com/openboard-team/openboard/pull/709
* Reduce amount of unwanted automatic space insertions, https://github.com/openboard-team/openboard/pull/576
-----

View file

@ -896,6 +896,14 @@ public final class RichInputConnection implements PrivateCommandPerformer {
return StringUtils.lastPartLooksLikeURL(mCommittedTextBeforeComposingText);
}
public boolean spaceBeforeCursor() {
return mCommittedTextBeforeComposingText.indexOf(" ") != -1;
}
public boolean wordBeforeCursorMayBeEmail() {
return mCommittedTextBeforeComposingText.lastIndexOf(" ") < mCommittedTextBeforeComposingText.lastIndexOf("@");
}
/**
* Looks at the text just before the cursor to find out if we are inside a double quote.
*

View file

@ -18,6 +18,7 @@ package org.dslul.openboard.inputmethod.latin.inputlogic;
import android.graphics.Color;
import android.os.SystemClock;
import android.text.InputType;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
@ -2045,11 +2046,26 @@ public final class InputLogic {
private void insertAutomaticSpaceIfOptionsAndTextAllow(final SettingsValues settingsValues) {
if (settingsValues.shouldInsertSpacesAutomatically()
&& settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
&& !mConnection.textBeforeCursorLooksLikeURL()) {
&& !textBeforeCursorMayBeURL()
&& !(mConnection.getCodePointBeforeCursor() == Constants.CODE_PERIOD && mConnection.wordBeforeCursorMayBeEmail())) {
sendKeyCodePoint(settingsValues, Constants.CODE_SPACE);
}
}
private boolean textBeforeCursorMayBeURL() {
if (mConnection.textBeforeCursorLooksLikeURL()) return true;
// doesn't look like URL, but we may be in URL field and user may want to enter example.com
if (mConnection.getCodePointBeforeCursor() != Constants.CODE_PERIOD && mConnection.getCodePointBeforeCursor() != ':')
return false;
final EditorInfo ei = getCurrentInputEditorInfo();
if (ei == null) return false;
int inputType = ei.inputType;
if ((inputType & InputType.TYPE_TEXT_VARIATION_URI) != 0)
return !mConnection.spaceBeforeCursor();
else
return false;
}
/**
* Do the final processing after a batch input has ended. This commits the word to the editor.
* @param settingsValues the current values of the settings.

View file

@ -31,6 +31,7 @@ public final class InputTypeUtils implements InputType {
private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
private static final int[] SUPPRESSING_AUTO_SPACES_FIELD_VARIATION = {
InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS,
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS,
InputType.TYPE_TEXT_VARIATION_PASSWORD,
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,