fix: use DocumentEvent offset, not caret position, for auto-activation checks - #120
Draft
bobbylight wants to merge 1 commit into
Draft
fix: use DocumentEvent offset, not caret position, for auto-activation checks#120bobbylight wants to merge 1 commit into
bobbylight wants to merge 1 commit into
Conversation
…n checks isAutoActivateOkay() relied on JTextComponent#getCaretPosition() to find the just-typed character, but the caret is not guaranteed to be updated yet when the insertUpdate() DocumentListener callback fires. This made auto-activation depend on incidental document listener ordering, breaking when a component's Document was swapped (e.g. via TextEditorPane.load()), as reported in #77. isAutoActivateOkay() now takes the inserted character's offset explicitly, sourced from DocumentEvent#getOffset() in AutoCompletion's insertUpdate() listener, which is authoritative regardless of listener order. Also adds the PR template. Fixes #77
bobbylight
force-pushed
the
fix/issue-77-auto-activate-offset
branch
from
August 9, 2026 14:37
ac04350 to
99a511f
Compare
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
isAutoActivateOkay()checked the character at the text component's caret position, but the caret is not guaranteed to have been updated yet when theinsertUpdate()DocumentListenercallback fires, so behavior depended on incidental document-listener ordering.Fixes #77
Details
CompletionProvider.isAutoActivateOkay(JTextComponent)is nowisAutoActivateOkay(JTextComponent, int offs), with the offset sourced fromDocumentEvent#getOffset()inAutoCompletion'sinsertUpdate()listener, which is authoritative regardless of caret/listener timing.CompletionProviderBase.isAutoActivateOkay()now reads the character at the passed-inoffsinstead oftc.getCaretPosition().LanguageAwareCompletionProvider.isAutoActivateOkay()forwards the newoffsparam to its delegate provider.CompletionProviderand its implementations, acceptable per the maintainer for a major version bump.Test plan
./gradlew :AutoComplete:test— all existing tests pass (3 classes, 4 tests, 0 failures)./gradlew :AutoComplete:compileJava— compiles cleanly