Skip to content

Close overlay if view is destroyed #181

Description

@mstijak

Sometimes the autocomplete overlay remains open even if the parent view is destroyed.

I managed to resolve that by adding the destroy callback in decoration.ts, but it doesn't seem like the right way to do it.

destroy: () => {
   reducer({ kind: ActionKind.close, view: null, trigger: null, range: null, filter: null, type: null });
},
update: (view, prevState) => {
   const prev = plugin.getState(prevState) as ActiveAutocompleteState;
   const next = plugin.getState(view.state) as ActiveAutocompleteState;

   const started = !prev.active && next.active;
   const stopped = prev.active && !next.active;
   const changed = next.active && !started && !stopped && prev.filter !== next.filter;

   const action: Omit<AutocompleteAction, 'kind'> = {
      view,
      trigger: next.trigger ?? (prev.trigger as string),
      filter: next.filter ?? prev.filter,
      range: next.range ?? (prev.range as FromTo),
      type: next.type ?? prev.type,
   };
   if (started) reducer({ ...action, kind: ActionKind.open });
   if (changed) reducer({ ...action, kind: ActionKind.filter });
   if (stopped) reducer({ ...action, kind: ActionKind.close });
}

If this does seem ok, I'll create a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions