Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

export startCompletionEffect and closeCompletionEffect#24

Closed
BrianHung wants to merge 1 commit intocodemirror:mainfrom
BrianHung:export-completion-effects
Closed

export startCompletionEffect and closeCompletionEffect#24
BrianHung wants to merge 1 commit intocodemirror:mainfrom
BrianHung:export-completion-effects

Conversation

@BrianHung
Copy link
Copy Markdown

@BrianHung BrianHung commented Jul 3, 2024

Trying to programmatically open the autocompletion menu when CodeMirror is empty and focused, as opposed to requiring a Ctrl+Space.

Would need to have state effects exported if I want to use https://codemirror.net/docs/ref/#state.EditorState^transactionExtender.

Work-around right now is using updateListener, and calling startCompletion.

EditorView.updateListener.of(
  ({ docChanged, view, state }) => {
    const shouldOpen = (docChanged || view.hasFocus) && !completionStatus(state);
    if (!state.doc.length && shouldOpen) {
      startCompletion(view);
    }
  }
)

This works but requires an additional check that completionState isn't already open to prevent an infinite loop of updates.

But I view this as more similar to the auto language example here https://codemirror.net/examples/config/

@marijnh
Copy link
Copy Markdown
Member

marijnh commented Jul 4, 2024

I think your workaround is decent enough. Exporting these doesn't seem worth it without a more compelling use case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants