WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.18k forks source link

Autocomplete no longer supports overlapping triggers #61919

Open jakub300 opened 5 months ago

jakub300 commented 5 months ago

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

github-actions[bot] commented 4 months ago

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.

Mamaduka commented 2 months ago

@WunderBart, have you seen this issue?

WunderBart commented 2 months ago

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