mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-21 14:49:10 +00:00
reduce amount of unwanted automatic space insertions
This commit is contained in:
parent
b96732ea22
commit
0b15fe0a1e
3 changed files with 26 additions and 1 deletions
|
@ -896,6 +896,14 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
||||||
return StringUtils.lastPartLooksLikeURL(mCommittedTextBeforeComposingText);
|
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.
|
* Looks at the text just before the cursor to find out if we are inside a double quote.
|
||||||
*
|
*
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.dslul.openboard.inputmethod.latin.inputlogic;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.text.InputType;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
@ -2045,11 +2046,26 @@ public final class InputLogic {
|
||||||
private void insertAutomaticSpaceIfOptionsAndTextAllow(final SettingsValues settingsValues) {
|
private void insertAutomaticSpaceIfOptionsAndTextAllow(final SettingsValues settingsValues) {
|
||||||
if (settingsValues.shouldInsertSpacesAutomatically()
|
if (settingsValues.shouldInsertSpacesAutomatically()
|
||||||
&& settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
|
&& settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
|
||||||
&& !mConnection.textBeforeCursorLooksLikeURL()) {
|
&& !textBeforeCursorMayBeURL()
|
||||||
|
&& !(mConnection.getCodePointBeforeCursor() == Constants.CODE_PERIOD && mConnection.wordBeforeCursorMayBeEmail())) {
|
||||||
sendKeyCodePoint(settingsValues, Constants.CODE_SPACE);
|
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.
|
* 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.
|
* @param settingsValues the current values of the settings.
|
||||||
|
|
|
@ -31,6 +31,7 @@ public final class InputTypeUtils implements InputType {
|
||||||
private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
|
private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
|
||||||
TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
|
TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
|
||||||
private static final int[] SUPPRESSING_AUTO_SPACES_FIELD_VARIATION = {
|
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_EMAIL_ADDRESS,
|
||||||
InputType.TYPE_TEXT_VARIATION_PASSWORD,
|
InputType.TYPE_TEXT_VARIATION_PASSWORD,
|
||||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
|
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
|
||||||
|
|
Loading…
Add table
Reference in a new issue