question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trigger mention suggestions without leading space

See original GitHub issue

Use-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:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
riddhi-24commented, Aug 23, 2022

Any update on this?

1reaction
timustercommented, Oct 9, 2021

Commenting to re-open this issue - neither #1301 nor #2165 were merged 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create fast trigger which removes trailing spaces
How to create fast trigger which removes trailing spaces ; ' ' is not required. It is by default. If when clause is...
Read more >
[GA4] Modify and create events via the user interface
Change events and create new events based on existing events without changing site or app codeYou can create and modify events in two...
Read more >
Common IRS Audit Triggers - Bloomberg Tax
Learn the characteristics of a tax return that triggers audits by the IRS – then how to avoid them with a comprehensive guide....
Read more >
Record-Triggered Automation | Salesforce Architects
Guide Overview. This guide provides tools recommendations for various triggered automation use cases along with the rationale for those recommendations.
Read more >
An Introduction to Content Warnings and Trigger Warnings
The inclusion of content warnings is neither restrictive (it does not label anything as off-limits to teach) nor coddling ( it does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found