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

auto toggle toolbar when suggestions are available #674

Merged
merged 17 commits into from
Jun 1, 2024

Conversation

codokie
Copy link
Contributor

@codokie codokie commented Apr 11, 2024

I added a new setting that makes the suggestions appear automatically as they become available without having to touch the expand toolbar key. If there is no character before the cursor (when starting input or after a newline), the main toolbar will be shown. This functionality is present in many other mainstream keyboards. I believe this fixes #449
Here is a short demo

toolbar.mp4

@HoroTW
Copy link

HoroTW commented Apr 23, 2024

I was about to open a feature request for exactly that!
I use voice input a lot (with FUTO Voice - open / local on-device voice input) and so it was annoying to always click an unnecessary button 😅 at least annoying enough for me to go through all the settings multiple times 😂.

Thanks for the PR, I will look through it/test it and give feedback in the next days! 👍🏻

@Helium314
Copy link
Owner

Could you also add a separate settings for just auto-hiding the toolbar when suggestions are available?

When you have pinned keys, they will flash when you type e.g. .... This needs to be fixed.

@Helium314
Copy link
Owner

When there are default suggestions on opening an input field (with next-word-suggestions on), the toolbar shortly shows up, and then disappears once the suggestions arrive.
Selecting text by long pressing on text and moving the marker, the pinned keys flash on every move.
When trying to move through the text using left/right keys on toolbar, you can only do so until the first suggestions appears (auto-hide setting would help here).

@Helium314
Copy link
Owner

sorry about the delay

There is really no need for that, here I'm much worse...

Could u please check if this is still an issue, my device may render it too fast for me to notice the flicker

Yes, it still happens

@Helium314
Copy link
Owner

It was added in e337f74.
So it doesn't need to be set to gone, but at least that should be an option (that's what I mentioned with "happens curently" in #449 (comment))

@Helium314
Copy link
Owner

Flickering looks mostly good now. There are a few more cases where it happens, like when the toolbar was showing, you close the keyboard, and then tap inside some text field where toolbar should not show. But that's more obscure, and not necessary to fix.
(with next word suggestions on, when set to off the toolbar is not auto-showing at all)

One think I noticed when re-reading:
This does not show the tool bar when opening an input field and there are suggestions, which is requested in #449.
Could be done by adding something like

                boolean suppressResume = currentSettingsValues.mAutoShowToolbar
                        && mInputLogic.mConnection.getTextAfterCursor(1, 0).length() == 0
                        && mInputLogic.mConnection.getCodePointBeforeCursor() == Constants.NOT_A_CODE;
                if (!suppressResume)
                    mHandler.postResumeSuggestions(true /* shouldDelay */);

right above the first needToCallLoadKeyboardLater = false;, i.e. don't try getting suggestions when the input field is empty and mAutoShowToolbar is on.

@Helium314
Copy link
Owner

I can add the provided code, but then personalized predictions won't be suggested when the input starts.

I think it makes sense to also show it in this case, because (at least for me) those initial suggestions are rarely something I actually want to type.
But no matter which way we do it, it's simple to switch.

it seems like it might not be right to depend on the return values of functions that use the position of a "lying" cursor

The code above essentially checks whether the text field is empty, which does not depend on the cursor position. (maybe that could be checked more efficiently)

@Helium314
Copy link
Owner

A summary when the toolbar shows automatically, depending on other settings (auto-show and auto-hide enabled)

  • next word & personalized suggestions enabled
    • in non-text input fields
    • after enter in multi-line field, except when having pressed delete right before (because suggestions show up inconsistently)
    • when clicking to a place where suggestions for empty previous word are shown, and then entering e.g. .
      • not when entering e.g. and / or . when initially touching a word (suggestions are shown after , but go away after .)
  • next word suggestions enabled, personalized suggestions disabled
    • in non-text input fields
    • when text input field is empty
    • after enter in multi-line field
    • when clicking to a place where no suggestions are shown, and then after entering e.g. or .
      • not when entering e.g. or . after a word (no suggestions are shown though)
  • next word suggestions disabled or suggestions disabled
    • never

@Helium314
Copy link
Owner

Thanks for the detailed summary. I assume it is an observation of the current behavior? because I don't think that all of it is intended.

I wasn't sure whether everything was working as you intended, that's why I wrote the summary.

  1. It's the beginning of a line and only neutral suggestions are available

👍

  1. Input starts, even if the input field is not empty, as long as cursor does not touch word

Not sure about the "even if the input field is not empty" part, but at least some uses will want this.

  1. All suggestions were manually removed

This seems to be a very specific and rare situation. It should only be considered if it doesn't introduce much complexity.

  1. Text is selected

👍

The toolbar should be auto-hidden when actual suggestions are available (including inline suggestions)

I think hiding words properly already, didn't test inline suggestions though.

On a side note, it seems like a waste of screen estate that setNeutralSuggestions() sets empty suggestions if next-word suggestions are disabled. Do you think it would be possible to show the top 3 dictionary words with highest frequency instead?

Possible yes, but it might not be particularly useful (and then the app is showing next-word suggestions despite the setting being disabled).

@@ -1144,7 +1154,7 @@ public void onExtractedCursorMovement(final int dx, final int dy) {

@Override
public void hideWindow() {
if (mSuggestionStripView != null)
if (mSuggestionStripView != null && !mSettings.getCurrent().mAutoShowToolbar)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some comment to the code on why hiding the toolbar depends on the auto-show setting? When reading just the code here, and not the entire PR one could easily assume it's a mistake.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove it? I just would have liked a comment in the code to avoid confusion, but now I am confused with this change...

// Auto hide the toolbar if dictionary suggestions are available
if (currentSettingsValues.mAutoHideToolbar
&& !noSuggestionsFromDictionaries
&& !suggestedWords.isPrediction()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't hide if it's a prediction?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to know why you added it like this, it was not a criticism or request for change.

Now you changed it to (!suggestedWords.isPrediction() || !currentSettingsValues.mAutoShowToolbar)) {, but I'm still not sure I understand why. (and really, this is not a request to change it, just for clarification)

codokie referenced this pull request in codokie/HeliBoard May 31, 2024
@Helium314 Helium314 merged commit b9451e4 into Helium314:main Jun 1, 2024
1 check passed
Copy link
Contributor Author

@codokie codokie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Helium314 feee2f2 is 100% going to cause a flicker on input start every time..
if you really think this is needed then you might to implement this function:

@Override
    public void showWindow(boolean showInput) {
        if (mSuggestionStripView != null && mSettings.getCurrent().mAutoShowToolbar)
            mSuggestionStripView.setToolbarVisibility(true);
        super.showWindow(showInput);
    }

so that the toolbar visibility will be set ASAP, likely before the someone could notice it

@BlackyHawky
Copy link
Contributor

Wouldn't it be better to have these settings in the new "Toolbar" page? 🤔

@Helium314
Copy link
Owner

Helium314 commented Jun 1, 2024

Wow. Sorry @codokie, GitHub didn't show me any of your comments from the past 2 days, only the pushes. So I was really confused first and then annoyed as it looked like you just pushed changes instead of answering my questions.
I'll look at it again...

Wouldn't it be better to have these settings in the new "Toolbar" page? 🤔

The toolbar settings don't exist in https://github.com/codokie/HeliBoard/tree/autotoggle-toolbar, but the plan to move the settings should be somewhere in here.

@Helium314
Copy link
Owner

feee2f2 is 100% going to cause a flicker on input start every time..

Under which conditions? I tried a quite a few different things, but never managed to get that flicker..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants