Skip to content

Comments

Issue 2715#2716

Open
yashas-hm wants to merge 2 commits intosingerdmx:masterfrom
yashas-hm-os:issue-2715
Open

Issue 2715#2716
yashas-hm wants to merge 2 commits intosingerdmx:masterfrom
yashas-hm-os:issue-2715

Conversation

@yashas-hm
Copy link

Description

Adds support for custom inline embeds (mentions, hashtags, etc.) to declare their character length for the platform keyboard, fixing TextCapitalization.sentences and word/sentence boundary detection
around embeds.

Problem: All embeds are sent to the platform as a single \uFFFC character. The OS keyboard cannot detect sentence endings (e.g. @JohnDoe. Next sentence) because it only sees \uFFFC. --> not
enough context for capitalization or word boundaries.

Solution:

  • Added int get length property to EmbedBuilder (defaults to 1, fully backward compatible)
  • Added internal OffsetMapping layer at the platform text-input boundary that translates between document offsets (embeds = length 1) and expanded-text offsets (embeds = toPlainText().length)
  • The Delta/OT layer is unchanged --> embeds remain length 1 internally

Usage: Override toPlainText() and length on your EmbedBuilder:

class MentionBuilder extends EmbedBuilder {
  @override
  String get key => 'mention';

  @override
  bool get expanded => false;

  @override
  String toPlainText(Embed node) => '@${node.value.data}';

  @override
  int get length => toPlainText(...).length;
}

Files changed:
- lib/src/editor/embed/embed_editor_builder.dart --> added int get length => 1;
- lib/src/editor/raw_editor/offset_mapping.dart --> new internal OffsetMapping utility
- lib/src/controller/quill_controller.dart --> cached offsetMapping + expandedTextEditingValue
- lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart --> use expanded text for platform I/O
- test/editor/offset_mapping_test.dart --> 17 unit tests
- CHANGELOG.md --> added entry under [Unreleased]


## Related Issues
Fixes #2715 
Closes #2715 

## Type of Change

<!---
Check the boxes that apply with x and leave the others empty. For example:
- [x] ✨ **New feature:** Adds new functionality without breaking existing features.
- [ ] 🛠️ **Bug fix:** Resolves an issue without changing current behavior.
-->

- [x] ✨ **Feature:** New functionality without breaking existing features.
- [ ] 🛠️ **Bug fix:** Resolves an issue without altering current behavior.
- [ ] 🧹 **Refactor:** Code reorganization, no behavior change.
- [ ] ❌ **Breaking:** Alters existing functionality and requires updates.
- [x] 🧪 **Tests:** New or modified tests
- [ ] 📝 **Documentation:** Updates or additions to documentation.
- [ ] 🗑️ **Chore:** Routine tasks, or maintenance.
- [ ] ✅ **Build configuration change:** Build/configuration changes.

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

Successfully merging this pull request may close these issues.

1 participant