Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close overlay if view is destroyed #181

Open
mstijak opened this issue Dec 7, 2022 · 1 comment
Open

Close overlay if view is destroyed #181

mstijak opened this issue Dec 7, 2022 · 1 comment

Comments

@mstijak
Copy link

mstijak commented Dec 7, 2022

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.

@mstijak
Copy link
Author

mstijak commented Dec 9, 2022

I added this part too.

handleDOMEvents: {
  blur: (view) => {
     closeAutocomplete(view);
  },
},

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

No branches or pull requests

1 participant