From 1b1ddd67c71063a4b4f521b1ae250bbbb43cf18f Mon Sep 17 00:00:00 2001 From: Corentin Bazin Date: Thu, 6 Jun 2024 14:51:57 +0200 Subject: [PATCH 1/5] try to integrate: remove FillInComposingSlackTagRequest handler, make it possible to change tagIndex value, make removeSlackComposingTokenAttribution public (cherry picked from commit f73b177c79b7869f8fdd9a83a9393b08ef0ce1e7) --- .../lib/src/clones/slack/slack_tags.dart | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/super_editor/lib/src/clones/slack/slack_tags.dart b/super_editor/lib/src/clones/slack/slack_tags.dart index e3f466b545..7f3a40fec2 100644 --- a/super_editor/lib/src/clones/slack/slack_tags.dart +++ b/super_editor/lib/src/clones/slack/slack_tags.dart @@ -35,8 +35,8 @@ class SlackTagPlugin extends SuperEditorPlugin { SlackTagPlugin() : tagIndex = SlackTagIndex() { _requestHandlers = [ - (request) => - request is FillInComposingSlackTagRequest ? FillInComposingSlackTagCommand(_trigger, request.tag) : null, + // (request) => + // request is FillInComposingSlackTagRequest ? FillInComposingSlackTagCommand(_trigger, request.tag) : null, (request) => request is CancelComposingSlackTagRequest // ? const CancelComposingSlackTagCommand() : null, @@ -45,7 +45,7 @@ class SlackTagPlugin extends SuperEditorPlugin { _reactions = [ SlackTagReaction( trigger: _trigger, - onUpdateComposingTag: tagIndex._onComposingTagFound, + onUpdateComposingTag: tagIndex.setTag, ), const AdjustSelectionAroundSlackTagReaction(_trigger), ]; @@ -145,7 +145,7 @@ class FillInComposingSlackTagCommand implements EditCommand { } // Remove the composing attribution from the text. - final removeComposingAttributionCommand = _removeSlackComposingTokenAttribution(document, tagIndex); + final removeComposingAttributionCommand = removeSlackComposingTokenAttribution(document, tagIndex); // Insert the final text and apply a stable tag attribution. final tag = tagIndex.composingSlackTag.value!; @@ -240,7 +240,7 @@ class CancelComposingSlackTagCommand implements EditCommand { final document = context.find(Editor.documentKey); // Remove the composing attribution from the text. - final removeComposingAttributionCommand = _removeSlackComposingTokenAttribution(document, tagIndex); + final removeComposingAttributionCommand = removeSlackComposingTokenAttribution(document, tagIndex); // Reset the tag index. final tag = tagIndex.composingSlackTag.value!; @@ -269,7 +269,7 @@ class CancelComposingSlackTagCommand implements EditCommand { } } -EditCommand? _removeSlackComposingTokenAttribution(Document document, SlackTagIndex tagIndex) { +EditCommand? removeSlackComposingTokenAttribution(Document document, SlackTagIndex tagIndex) { print("REMOVING COMPOSING ATTRIBUTION"); // Remove any composing attribution for the previous state of the tag. // It's possible that the previous composing region disappeared, e.g., due to a deletion. @@ -788,7 +788,7 @@ class SlackTagIndex with ChangeNotifier implements Editable { ValueListenable get composingSlackTag => _composingSlackTag; final _composingSlackTag = ValueNotifier(null); - void _onComposingTagFound(ComposingSlackTag? tag) { + void setTag(ComposingSlackTag? tag) { _composingSlackTag.value = tag; } @@ -1097,10 +1097,10 @@ class AdjustSelectionAroundSlackTagReaction implements EditReaction { case SelectionChangeType.placeCaret: case SelectionChangeType.pushCaret: case SelectionChangeType.collapseSelection: - throw AssertionError( - "An expanded selection reported a SelectionChangeType for a collapsed selection: ${selectionChangeEvent.changeType}\n${selectionChangeEvent.newSelection}"); + // throw AssertionError( + // "An expanded selection reported a SelectionChangeType for a collapsed selection: ${selectionChangeEvent.changeType}\n${selectionChangeEvent.newSelection}"); case SelectionChangeType.clearSelection: - throw AssertionError("Expected a collapsed selection but there was no selection."); + // throw AssertionError("Expected a collapsed selection but there was no selection."); } } From 4f9cb96f3131ce78198c9edb48d43fdc4f8afcdf Mon Sep 17 00:00:00 2001 From: Corentin Bazin Date: Sat, 8 Jun 2024 15:27:21 +0200 Subject: [PATCH 2/5] allow for custom handlers (cherry picked from commit aedb1a926a16ce679774fbb0ef4c355a5abe583d) --- super_editor/lib/src/clones/slack/slack_tags.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/super_editor/lib/src/clones/slack/slack_tags.dart b/super_editor/lib/src/clones/slack/slack_tags.dart index 7f3a40fec2..3a06f66ba1 100644 --- a/super_editor/lib/src/clones/slack/slack_tags.dart +++ b/super_editor/lib/src/clones/slack/slack_tags.dart @@ -33,13 +33,14 @@ class SlackTagPlugin extends SuperEditorPlugin { static const _trigger = "@"; - SlackTagPlugin() : tagIndex = SlackTagIndex() { + SlackTagPlugin({List customRequestHandlers = const []}) : tagIndex = SlackTagIndex() { _requestHandlers = [ - // (request) => - // request is FillInComposingSlackTagRequest ? FillInComposingSlackTagCommand(_trigger, request.tag) : null, + (request) => + request is FillInComposingSlackTagRequest ? FillInComposingSlackTagCommand(_trigger, request.tag) : null, (request) => request is CancelComposingSlackTagRequest // ? const CancelComposingSlackTagCommand() : null, + ...customRequestHandlers, ]; _reactions = [ From a7fd6f85e5ed1fcc6168c503c21bd70fb3910526 Mon Sep 17 00:00:00 2001 From: Corentin Bazin Date: Sat, 8 Jun 2024 16:36:08 +0200 Subject: [PATCH 3/5] add trigger parameter to constructor (cherry picked from commit 7029e10af67929054ce7e5f309f1e8c9d75f8e89) --- .../lib/src/clones/slack/slack_tags.dart | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/super_editor/lib/src/clones/slack/slack_tags.dart b/super_editor/lib/src/clones/slack/slack_tags.dart index 3a06f66ba1..6335f5dc6c 100644 --- a/super_editor/lib/src/clones/slack/slack_tags.dart +++ b/super_editor/lib/src/clones/slack/slack_tags.dart @@ -31,12 +31,13 @@ class SlackTagPlugin extends SuperEditorPlugin { /// The key used to access the [SlackTagIndex] in an attached [Editor]. static const slackTagIndexKey = "slackTagIndex"; - static const _trigger = "@"; - - SlackTagPlugin({List customRequestHandlers = const []}) : tagIndex = SlackTagIndex() { + SlackTagPlugin({ + List customRequestHandlers = const [], + this.trigger = "@", + }) : tagIndex = SlackTagIndex() { _requestHandlers = [ (request) => - request is FillInComposingSlackTagRequest ? FillInComposingSlackTagCommand(_trigger, request.tag) : null, + request is FillInComposingSlackTagRequest ? FillInComposingSlackTagCommand(trigger, request.tag) : null, (request) => request is CancelComposingSlackTagRequest // ? const CancelComposingSlackTagCommand() : null, @@ -45,13 +46,16 @@ class SlackTagPlugin extends SuperEditorPlugin { _reactions = [ SlackTagReaction( - trigger: _trigger, + trigger: trigger, onUpdateComposingTag: tagIndex.setTag, ), - const AdjustSelectionAroundSlackTagReaction(_trigger), + AdjustSelectionAroundSlackTagReaction(trigger), ]; } + /// The character that triggers a tag. Default is "@". + final String trigger; + /// Index of all slack tags in the document, which changes as the user adds and removes tags. final SlackTagIndex tagIndex; @@ -129,11 +133,11 @@ class FillInComposingSlackTagRequest implements EditRequest { class FillInComposingSlackTagCommand implements EditCommand { const FillInComposingSlackTagCommand( - this._trigger, + this.trigger, this._tag, ); - final String _trigger; + final String trigger; final String _tag; @override @@ -182,7 +186,7 @@ class FillInComposingSlackTagCommand implements EditCommand { InsertAttributedTextCommand( documentPosition: textNode.positionAt(startOfToken), textToInsert: AttributedText( - "$_trigger$_tag ", + "$trigger$_tag ", AttributedSpans( attributions: [ SpanMarker(attribution: slackTagAttribution, offset: 0, markerType: SpanMarkerType.start), From f8128d0fe5c5a6a1bbd9e0fa49f24ec6a8f002b3 Mon Sep 17 00:00:00 2001 From: Corentin Bazin Date: Fri, 5 Jul 2024 15:37:29 +0200 Subject: [PATCH 4/5] replace prints with logs --- .../lib/src/clones/slack/slack_tags.dart | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/super_editor/lib/src/clones/slack/slack_tags.dart b/super_editor/lib/src/clones/slack/slack_tags.dart index 6335f5dc6c..ab63825406 100644 --- a/super_editor/lib/src/clones/slack/slack_tags.dart +++ b/super_editor/lib/src/clones/slack/slack_tags.dart @@ -212,8 +212,8 @@ class FillInComposingSlackTagCommand implements EditCommand { // FIXME: Use a transaction to bundle these changes so order doesn't matter. if (removeComposingAttributionCommand != null) { executor.executeCommand(removeComposingAttributionCommand); - print("Attributions immediately after removing composing attribution:"); - print("${textNode.text.getAttributionSpansByFilter((a) => true)}"); + editorSlackTagsLog.info("Attributions immediately after removing composing attribution:"); + editorSlackTagsLog.info("${textNode.text.getAttributionSpansByFilter((a) => true)}"); } // Reset the tag index so that we're no longer composing a tag. @@ -275,14 +275,14 @@ class CancelComposingSlackTagCommand implements EditCommand { } EditCommand? removeSlackComposingTokenAttribution(Document document, SlackTagIndex tagIndex) { - print("REMOVING COMPOSING ATTRIBUTION"); + editorSlackTagsLog.info("REMOVING COMPOSING ATTRIBUTION"); // Remove any composing attribution for the previous state of the tag. // It's possible that the previous composing region disappeared, e.g., due to a deletion. final previousTag = tagIndex._composingSlackTag.value!; final previousTagNode = document.getNodeById(previousTag.contentBounds.start.nodeId); // We assume tags don't cross node boundaries. if (previousTagNode == null || previousTagNode is! TextNode) { - print("Couldn't find composing attribution. Fizzling."); + editorSlackTagsLog.info("Couldn't find composing attribution. Fizzling."); return null; } @@ -344,7 +344,7 @@ class SlackTagReaction implements EditReaction { editorSlackTagsLog.info("Is already composing a tag? ${tagIndex.isComposing}"); if (changeList.length == 1 && changeList.first is SelectionChangeEvent) { - print("Selection change event: ${(changeList.first as SelectionChangeEvent).changeType}"); + editorSlackTagsLog.info("Selection change event: ${(changeList.first as SelectionChangeEvent).changeType}"); } // Update the current tag composition. @@ -425,7 +425,7 @@ class SlackTagReaction implements EditReaction { onUpdateComposingTag?.call(newTag); // Add composing attribution for the updated tag bounds. - print("Updating composing attribution with bounds: ${newTag.contentBounds}"); + editorSlackTagsLog.info("Updating composing attribution with bounds: ${newTag.contentBounds}"); requestDispatcher.execute([ AddTextAttributionsRequest( documentRange: newTag.contentBounds, @@ -974,7 +974,7 @@ class AdjustSelectionAroundSlackTagReaction implements EditReaction { ); } - print( + editorSlackTagsLog.fine( "Selection after adjusting for tag: ${editContext.find(Editor.composerKey).selection?.extent.nodePosition}"); } @@ -1241,7 +1241,7 @@ class AdjustSelectionAroundSlackTagReaction implements EditReaction { case TextAffinity.downstream: // Move to ending edge. textOffset = tagAroundCaret.indexedTag.endOffset; - print("Pushing to text offset: $textOffset"); + editorSlackTagsLog.fine("Pushing to text offset: $textOffset"); break; } @@ -1264,7 +1264,7 @@ class AdjustSelectionAroundSlackTagReaction implements EditReaction { ), ); - print("Setting selection to: $newSelection"); + editorSlackTagsLog.fine("Setting selection to: $newSelection"); requestDispatcher.execute([ ChangeSelectionRequest( From 207454e5843360efd0003be8bf57d88eceb1fe5f Mon Sep 17 00:00:00 2001 From: Corentin Bazin Date: Fri, 5 Jul 2024 16:41:23 +0200 Subject: [PATCH 5/5] remove commented code --- super_editor/lib/src/clones/slack/slack_tags.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/super_editor/lib/src/clones/slack/slack_tags.dart b/super_editor/lib/src/clones/slack/slack_tags.dart index ab63825406..70d445aace 100644 --- a/super_editor/lib/src/clones/slack/slack_tags.dart +++ b/super_editor/lib/src/clones/slack/slack_tags.dart @@ -1102,10 +1102,7 @@ class AdjustSelectionAroundSlackTagReaction implements EditReaction { case SelectionChangeType.placeCaret: case SelectionChangeType.pushCaret: case SelectionChangeType.collapseSelection: - // throw AssertionError( - // "An expanded selection reported a SelectionChangeType for a collapsed selection: ${selectionChangeEvent.changeType}\n${selectionChangeEvent.newSelection}"); case SelectionChangeType.clearSelection: - // throw AssertionError("Expected a collapsed selection but there was no selection."); } }