-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Have you checked for an existing issue?
- I have searched the existing issues
Use case
Custom inline embeds (e.g. @mentions, #tags) always count as 1 character in the document model, regardless of their displayed text length. This breaks TextCapitalization.sentences because
the OS keyboard receives a text buffer where a mention like @John Doe is represented as a single \uFFFC character.
Example:
The user types: Hello @JohnDoe. then starts typing the next word.
- Displayed text:
Hello @JohnDoe. w(17 chars) - Document model:
Hello(6) + embed (1) +. w(3) = 10 chars - Platform text buffer:
Hello \uFFFC. w
The OS keyboard sees \uFFFC. and may not correctly identify the sentence boundary, causing auto-capitalization to trigger at wrong positions or fail entirely. The mismatch between document positions
and displayed text length is the root cause.
Proposal
Allow EmbedBuilder (or CustomBlockEmbed) to declare a custom length that reflects the embed's text representation, rather than always being 1.
Something like:
class MentionEmbedBuilder extends EmbedBuilder {
@override
String get key => 'mention';
@override
bool get expanded => false;
/// Return the character length this embed should occupy in the document.
/// Defaults to 1 for backward compatibility.
@override
int length(Embed node) {
final data = parseData(node.value.data);
final value = data['value'] as String? ?? '';
final denotationChar = data['denotationChar'] as String? ?? '@';
return '$denotationChar$value'.length;
}
@override
String toPlainText(Embed node) {
// ...
}
}This way, the text buffer sent to the platform TextInputConnection would align with the displayed content, and OS-level features like TextCapitalization.sentences, autocorrect context, and cursor
word-boundary detection would all work correctly.
Current Workaround
Set TextCapitalization.none on the editor and implement custom sentence capitalization by intercepting document changes and manually uppercasing characters at sentence boundaries. This works but
loses other platform keyboard intelligence (e.g. autocorrect context awareness).
Impact
This affects any app using inline custom embeds (mentions, tags, hashtags, variables, etc.) combined with:
TextCapitalization.sentencesor.words- Keyboard autocorrect / prediction
- Accessibility tools that rely on text buffer positions
- Cursor navigation (word-by-word jumping)
Environment
flutter_quill: ^11.5.0- Flutter 3.8+
- Affects both iOS and Android"