fix(dictionary): add full email/URL token to personal dictionary#23
Merged
Conversation
The "Add to dictionary" toolbar key added the whole token only when text was selected; with no selection it fell back to getWordRangeAtCursor, which splits on "." and "@" (word separators) unless URL detection is enabled — off by default. Tapping the key after typing an email therefore added only the trailing fragment (e.g. "xyz" of "newsletter@leinss.xyz"), never the address. Capture the whole whitespace-delimited token straddling the cursor for the no-selection path, trimming only outer word separators while keeping the interior "." / "@" that make it an email or URL. Reads committed text via the InputConnection, so it works regardless of the composing state or input type (native email field, web email field, or generic web text field where only the fragment composes). Learning stays gated per field type; this explicit action writes straight to the system user dictionary. - StringUtils: add pure getWhitespaceDelimitedTokenAtCursor() - RichInputConnection: fetch surrounding text and delegate to it - InputLogic: use it for the no-selection add-to-dictionary path - tests: cover email/URL/bracket/punctuation/whitespace cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The "Add to dictionary" toolbar key (and its long-press-Enter action) added the whole token only when text was selected. With no selection it fell back to
getWordRangeAtCursor, which splits on.and@(word separators) unless URL detection is enabled — and URL detection is off by default. So tapping the key after typing an email address added only the trailing fragment (e.g.xyzofnewsletter@leinss.xyz), never the full address, and there was no obvious way to add the address without first manually selecting it.Changes
StringUtils: add pure, unit-testedgetWhitespaceDelimitedTokenAtCursor()— returns the whitespace-delimited token straddling the cursor, trimming only outer word separators while keeping interior./@/_so a full email or URL is preserved.RichInputConnection: addgetWhitespaceDelimitedTokenAtCursor()that fetches the surrounding text and delegates to the pure helper.InputLogic: the no-selection add-to-dictionary path now uses it instead ofgetWordRangeAtCursor(drops the now-unused script argument).Why this is the minimal fix
Capture reads committed text via the
InputConnection, so it is independent of composing state and input type. It works in a native email field, a web email field, and a generic web text field (where only the fragment composes). No change to the suggestion engine or tokenizer, and automatic learning stays gated per field type — only this explicit user action writes to the system user dictionary.Test plan
make check— unit tests + lint: 350 tests, 0 failures, 7 skipped; lint clean (0 non-baseline errors)textEmailAddress): typednewsletter@leinss.xyz, tapped Add-to-dictionary → toastAdded "newsletter@leinss.xyz" to dictionary(full address)newsl→ full address suggested → tapped suggestion → full address inserted<input type="email">: whole token composes; add works<input type="text">(only thexyzfragment composes — the reported case): Add-to-dictionary still added the fullnewsletter@leinss.xyz