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

Autocomplete no longer supports overlapping triggers #61919

Open
jakub300 opened this issue May 23, 2024 · 3 comments
Open

Autocomplete no longer supports overlapping triggers #61919

jakub300 opened this issue May 23, 2024 · 3 comments
Labels
Needs Testing Needs further testing to be confirmed. [Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended

Comments

@jakub300
Copy link

jakub300 commented May 23, 2024

Description

We use autocomplete triggers that are overlapping, specifically @ and @@, each triggering different type of suggestions. After one of the recent WP updates this is no longer working.

Issue is most likely related to refactor in #55301. That PR changed logic from finding first matching trigger on the list within distance of the cursor, to finding closest trigger to the cursor. If we take @@hello as an example, beginning of single @ will always be closest to the cursor and @@ trigger will always be ignored. The possible fix is to look at the index after trigger (trigger index + trigger length) rather than trigger index. in such case the index would be the same for both triggers and first of them would be used.

Step-by-step reproduction instructions

  1. use provided snippet to setup autocomplete
  2. try using it with @hello and @@hello

Screenshots, screen recording, code snippet

wp.hooks.addFilter(
  'editor.Autocomplete.completers',
  'some-plugin/some-name-here',
  (completers) => {
    // remove wordpress @ completer
    completers = completers.filter((c) => c.triggerPrefix !== '@');

    completers.push({
      name: 'some-plugin/double-at',
      triggerPrefix: '@@',
      options: ['hello from double at completer'],
      getOptionLabel: (option) => option,
      getOptionCompletion: (option) => option,
    });

    completers.push({
      name: 'some-plugin/at',
      triggerPrefix: '@',
      options: ['hello from at completer'],
      getOptionLabel: (option) => option,
      getOptionCompletion: (option) => option,
    });

    return completers;
  },
);

Environment info

Not working in WP 6.5.3, was working in WP 6.4.3.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@jakub300 jakub300 added the [Type] Bug An existing feature does not function as intended label May 23, 2024
@jordesign jordesign added Needs Testing Needs further testing to be confirmed. [Package] Rich text /packages/rich-text labels May 24, 2024
Copy link

Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Jun 24, 2024
@Mamaduka
Copy link
Member

@WunderBart, have you seen this issue?

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Aug 22, 2024
@WunderBart
Copy link
Member

Thanks for the ping, @Mamaduka. I'll be able to take a look next week unless someone else beats me up to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Testing Needs further testing to be confirmed. [Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

4 participants