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

Not working when i use @jhon.234 (dot) #10

Closed
moinkhan780 opened this issue Aug 4, 2024 · 4 comments
Closed

Not working when i use @jhon.234 (dot) #10

moinkhan780 opened this issue Aug 4, 2024 · 4 comments

Comments

@moinkhan780
Copy link

Please make it possible to use dots, underscores in usernames.

@moinkhan780 moinkhan780 changed the title Not working when i use @jhon.234 Not working when i use @jhon.234 (dot) Aug 4, 2024
@Crazelu
Copy link
Owner

Crazelu commented Aug 4, 2024

@moinkhan780 you should be able to do this. There’s a property of the FlutterTagger constructor called searchRegex that you can specify to allow all kinds of characters. By default the regex is ^[a-zA-Z-]*$ which only matches letters of the English alphabet.

@ganadevprajapathy
Copy link

ganadevprajapathy commented Aug 8, 2024

I tried adding regex for space but it does not seem to have color highlight on tags with space. The tags work, its just the color highlights on tags with space fails.

@Crazelu
Copy link
Owner

Crazelu commented Aug 8, 2024

@ganadevprajapathy apart from the search regex, there's another regex used to match and format tags

pattern ??= RegExp(r'([@#]\w+\#.+?\#)');

You also need to look at the tagTextFormatter.
If you've not provided your own formatting rules via tagTextFormatter and an accompanying regex via FlutterTaggerController.formatTags(), then defaults are used which do not allow spacing in tags.

What to do:

After adding a tag using the controller, call formatTags on the controller, pass it your regex which extracts tag name and ID with space allowed. You may also need to pass it a parser. You can see how that is implemented below for the default format:

void _formatTags([
RegExp? pattern,
List<String> Function(String)? parser,
]) {
_clearCallback?.call();
_text = text;
String newText = text;
pattern ??= RegExp(r'([@#]\w+\#.+?\#)');
parser ??= (value) {
final split = value.split("#");
if (split.length == 4) {
// default hashtag group match (tag and id)
return [split[1].trim(), split[2].trim()];
}
// default user mention group match (name and id)
final id = split.first.trim().replaceFirst("@", "");
return [id, split[split.length - 2].trim()];
};
final matches = pattern.allMatches(text);
int diff = 0;
for (var match in matches) {
try {
final matchValue = match.group(1)!;
final idAndTag = parser(matchValue);
final triggerChar = text.substring(match.start, match.start + 1);
final tag = "$triggerChar${idAndTag.last.trim()}";
final startIndex = match.start;
final endIndex = startIndex + tag.length;
newText = newText.replaceRange(
startIndex - diff,
startIndex + matchValue.length - diff,
tag,
);
final taggedText = TaggedText(
startIndex: startIndex - diff,
endIndex: endIndex - diff,
text: tag,
);
_tags[taggedText] = idAndTag.first;
_trie.insert(taggedText);
diff += matchValue.length - tag.length;
} catch (e) {
debugPrint(e.toString());
}
}
if (newText.isNotEmpty) {
_runDeferedAction(() => text = newText);
_runDeferedAction(
() => selection = TextSelection.fromPosition(
TextPosition(offset: newText.length),
),
);
}
}

@flodaniel
Copy link

I am trying very hard to getting this to work but I can't figure it out. I can't use whitespace in the "name" property of a tag. Is it possible for you to provide a working example?

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

4 participants