Skip to content

Fix Tab-to-accept crashing for user-defined function completions - #4273

Open
NisargJasani0602 wants to merge 1 commit into
processing:developfrom
NisargJasani0602:fix/4272-tab-autocomplete
Open

Fix Tab-to-accept crashing for user-defined function completions#4273
NisargJasani0602 wants to merge 1 commit into
processing:developfrom
NisargJasani0602:fix/4272-tab-autocomplete

Conversation

@NisargJasani0602

Copy link
Copy Markdown
Contributor

Fixes #4272

Issue:

buildVarOrFunctionOption() in contextAwareHinter.js expects state and pos as separate positional arguments (matching its sibling builders, buildMethodOption and buildGlobalHintOption), but its call site was bundling
them as properties inside the options object instead. Since the function's destructuring pattern doesn't include state/pos, both silently ended up undefined inside the function.

That undefined state got captured in the completion's apply closure. When accepting a user-defined function completion via Tab, state.doc.lineAt(pos) threw TypeError: Cannot read properties of undefined (reading 'doc'). The Tab
keymap handler treats a failed accept as "unhandled" and falls through to the next binding, so nothing got inserted — matching the reported bug.

This only affected completions for user-defined functions/variables from the app's custom hinter; built-in p5 keywords and CodeMirror's own local-scope suggestions were unaffected (which is why the popup could show two entries for
the same identifier — one broken, one fine).

Changes:

  • Fixed the buildVarOrFunctionOption() call site in client/utils/contextAwareHinter.js to pass state and pos as separate trailing arguments instead of bundling them inside the options object.

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • has no typecheck errors (npm run typecheck)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123
  • meets the standards outlined in the accessibility guidelines

buildVarOrFunctionOption() expects state and pos as separate
positional arguments (matching its sibling builders), but its call
site was bundling them inside the options object instead, leaving
both undefined. The resulting apply() closure then threw
"Cannot read properties of undefined (reading 'doc')" when accepting
a user-defined function completion via Tab, which the Tab keymap
handler swallowed as "unhandled" and fell through without inserting
anything.

Fixes processing#4272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keyword Autocomplete Bug

1 participant