-
Notifications
You must be signed in to change notification settings - Fork 48
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
Sys - Full documentation #2
Comments
Since flutter-quill closed their issue section, the transition to this package seems even more urgent now 😅 Your documentation seems nice atm (although it is not finished), but I would miss a FAQ section. I am not sure you would accept PR since you are doing a big refactor with the package, so I'll just put my thoughts roughly here. Let's start with the things I managed to do that should be documented. How to add text manually?Devs might want to insert text (or embeds) when something happens outside the VisualEditor / the toolbar. _controller?.document.insert(index + 1, " ") How to insert embeds?final index = _controller!.selection.baseOffset;
setState(() {
_controller!.document
.insert(index, BlockEmbed('specialKey', 'someValue'));
}); Or to replace the current selection instead: final index = _controller!.selection.baseOffset;
final length = _controller!.selection.extentOffset - index;
_controller!.replaceText(index, length,
quill.BlockEmbed(RichTextDetails.userInput, uniqueId), null); I only store an uniqueId and a type in the delta document and I retrieve other related data elsewhere. Then, I use a special embedBuilder to display my custom embed: VisualEditor(
// ...
embedBuilder: customEmbedBuilder,
), Widget customEmbedBuilder(BuildContext context,
EditorController controller, Embed node, bool readOnly) {
switch (node.value.type) {
case RichTextDetails.userInput:
final input = _details.inputs[node.value.data];
if (input is RichTextOptions) {
return SomeCustomWidget(input);
}
}
return Text("Unsupported embed");
} How to detect when an Embed is removed by the user in the VisualEditor?This might be important when one stores data elsewhere than directly in the delta document. _controller = EditorController(
document: doc,
selection: const TextSelection.collapsed(offset: 0),
onReplaceText: (int index, int len, Object? data) {
final leaf = _controller!.document.querySegmentLeafNode(index);
if (leaf.item2 is quill.Embed &&
(data is String && data.isEmpty)) {
final embeddable = (leaf.item2 as quill.Embed).value;
if (embeddable.type == mySpecialTypeKey) {
// Remove associated data, such as the image file if it was stored elsewhere
doStuff();
}
}
return true;
}); How to remove an embed from the VisualEditor manually?If the embed is an image for instance, it could include a delete button in the top right corner. When the users taps on that button, the developer would have to remove manually the embed since it is not removed with the keyboard. Here is a way of doing it: final matches = _controller!.document
.toPlainText()
.allIndexesOf(quill.Embed.kObjectReplacementCharacter);
int? idxUniqueId;
for (var index in matches) {
final leaf = _controller!.document.querySegmentLeafNode(index);
if (leaf.item2 is quill.Embed) {
final embeddable = (leaf.item2 as quill.Embed).value;
if (embeddable.type == mySpecialTypeKey &&
embeddable.data == uniqueId) {
idxUniqueId = index;
break;
}
}
}
if (idxUniqueId != null) {
// replace the special character used for embeds by an empty String
_controller?.replaceText(idxUniqueId, 1, '', null);
} The above method used the below extension on extension StringExtension on String {
List<int> allIndexesOf(String pattern) {
List<int> result = [];
int idx = indexOf(pattern);
while (idx > 0 && idx < length) {
result.add(idx);
idx = indexOf(pattern, idx + 1);
}
return result;
}
} TODOHere is a quick list of the things I would like to be documented but I don't know how to do them. Lose / Give focus manuallyAfter adding an image for instance using a custom workflow, I lose the focus on the VisualEditor or more specifically: the indicator was not displayed anymore until I started typing again. Size of embedsSee #43. Replacement character for EmbedCurrently, VisualEditor renders If it is not recommended, the reason might be explained in the docs. |
Hi @apalala-dev! Nice to see you take such great interest in the project. I'll attempt to answer all your queries.
Thanks for joining the new repo. Your comments are very much welcomed. I'll try to get back to progressing on them as soon as the refactoring effort is complete. I suppose you already joined Discord and subscribed on Youtube Btw, how do you download it if it's not yet published to pub.dev? |
It is public but not published on pub.dev. Since the lib is on a public GitHub, one just needs to either download the project and uses it with a path dependency or use a git dependency like I did: visual_editor:
git: https://github.com/visual-space/visual-editor.git It's very useful for forks 😉 No worries about the other comments: first step is to stabilize the repo with the refactor and the base documentation. People might want to contribute to the project at some point. It could help if you had a kanban (through the projects tabs on GitHub) where you report your progress and what is planned next. |
Cool trick to know. I thought there must be some link. Will help me test it in my production project. |
Latest status update: |
Such great news 👍🏻 Thank you so much for your effort, really appreciated |
I'll be closing this task since the seed of the documentation was started. This is an ever present task. |
This was one of the major pain points when using Flutter Quill. I'm working in parallel with the refactoring work to develop a full set of documentation articles that cover all use cases. Please post here what you think it's missing from the documentation. I'll be happy to receive feedback.
Join on discord to get advice and help or follow us on YouTube Visual Coding to learn more about the architecture of Visual Editor and other Flutter apps.
The text was updated successfully, but these errors were encountered: