Trigger mention suggestions without leading space
See original GitHub issueUse-case/Problem
The existing regex for initiating the suggestion dropdown requires that the mentionTrigger is the first character or is preceded by a space.
See: (\\s|^)${escapeRegExp(trigger)}${regExp}
https://github.com/draft-js-plugins/draft-js-plugins/blob/master/draft-js-mention-plugin/src/mentionSuggestionsStrategy.js#L8
In my use case I wanted to the user to be able to wrap the mention in characters that provide other meaning for our application such as:
Hi @Matt [@John]
The mention for @Matt will work because it is preceded by a space, but the @John will not work because it is preceded by a [
I thought I could edit the mentionRegExp
to overcome this, but found out that it only affects the portion after the trigger.
I feel like this variable should allow over riding the whole regex, but for backwards compatibility we could add new option such as mentionTriggerRegExp
or something that would replace the entire thing and could default to the current implementation. (Although this name is less generic even though it has more responsibility)
Some questions: 1. Is there anything in the plugin that requires the leading space? It seems odd to not allow this specific part of the regex to be over written. Perhaps this is by design and there was a requirement for the space in order to reliably get search text or selection of entity since it was known to be bounded by spaces? Is there any reason this plugin couldn’t support this scenario?
2. Is there anyway to configure the plugin to support this? Based on information I found, the answer is no. I would either have to fork the plugin or write my own custom implementation to get around the hard coded regex in mentionSuggestionStrategy. Although maybe I am wrong and some expert has already developed work-around.
3. If the answer to the above 2 is true, what would you suggest the best approach is? I feel like I am starting to hit the limits of what the plugin is designed for and perhaps custom implementation would be better in the long run, but there is a whole bunch of cursor / content selection logic and work arounds in here that seem like the average person would not know unless they hit the issue and I thought re-using this work would be faster.
For example I also would like to be able to customize behavior of adding space after entity is added. (Disabling it) and don’t think this is possible.
TL;DR;
I would like to be able to have the mentionTrigger not required to be preceded by a space to allow my editor to support optional entities wrapped in brackets like: [@John]
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:13 (1 by maintainers)
Top GitHub Comments
Any update on this?
Commenting to re-open this issue - neither #1301 nor #2165 were merged 😦