export startCompletionEffect and closeCompletionEffect #24

Closed
BrianHung wants to merge 1 commit from export-completion-effects into main
BrianHung commented 2024-07-04 00:52:52 +02:00 (Migrated from github.com)

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/

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. ```ts 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 commented 2024-07-04 09:45:57 +02:00 (Migrated from github.com)

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

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

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/autocomplete!24
No description provided.