Skip to content

fix: use DocumentEvent offset, not caret position, for auto-activation checks - #120

Draft
bobbylight wants to merge 1 commit into
masterfrom
fix/issue-77-auto-activate-offset
Draft

fix: use DocumentEvent offset, not caret position, for auto-activation checks#120
bobbylight wants to merge 1 commit into
masterfrom
fix/issue-77-auto-activate-offset

Conversation

@bobbylight

@bobbylight bobbylight commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary

isAutoActivateOkay() checked the character at the text component's caret position, but the caret is not guaranteed to have been updated yet when the insertUpdate() DocumentListener callback fires, so behavior depended on incidental document-listener ordering.

Fixes #77

Details

CompletionProvider.isAutoActivateOkay(JTextComponent) is now isAutoActivateOkay(JTextComponent, int offs), with the offset sourced from DocumentEvent#getOffset() in AutoCompletion's insertUpdate() listener, which is authoritative regardless of caret/listener timing.

  • CompletionProviderBase.isAutoActivateOkay() now reads the character at the passed-in offs instead of tc.getCaretPosition().
  • LanguageAwareCompletionProvider.isAutoActivateOkay() forwards the new offs param to its delegate provider.
  • This is an API change to CompletionProvider and 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

…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
bobbylight force-pushed the fix/issue-77-auto-activate-offset branch from ac04350 to 99a511f Compare August 9, 2026 14:37
@bobbylight bobbylight self-assigned this Aug 9, 2026
@bobbylight bobbylight added the bug label Aug 9, 2026
@bobbylight bobbylight added this to the 4.0.0 milestone Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isAutoActivateOkay() checks wrong character

1 participant