Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce amount of unwanted automatic space insertions #576

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,14 @@ public boolean textBeforeCursorLooksLikeURL() {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.graphics.Color;
import android.os.SystemClock;
import android.text.InputType;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
Expand Down Expand Up @@ -2045,11 +2046,26 @@ private void sendKeyCodePoint(final SettingsValues settingsValues, final int cod
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down