Skip to content

Commit

Permalink
PR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre committed Nov 23, 2024
1 parent a71cb04 commit 329b24e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
35 changes: 12 additions & 23 deletions super_editor/lib/src/default_editor/super_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class SuperEditor extends StatefulWidget {
this.documentLayoutKey,
Stylesheet? stylesheet,
this.customStylePhases = const [],
this.appendedStylePhases = const [],
List<ComponentBuilder>? componentBuilders,
SelectionStyles? selectionStyle,
this.selectionPolicies = const SuperEditorSelectionPolicies(),
Expand Down Expand Up @@ -237,17 +236,6 @@ class SuperEditor extends StatefulWidget {
/// knows how to interpret and apply table styles for your visual table component.
final List<SingleColumnLayoutStylePhase> customStylePhases;

/// Custom style phases that are added to the very end of the style phases.
///
/// Typically, apps should use [customStylePhases]. However, the selection
/// styles are always applied after [customStylePhases]. If you need to
/// change the selection color, add the style phase that changes the selection
/// color here.
///
/// For example, a spellchecker might want to override the selection color
/// for misspelled words.
final List<SingleColumnLayoutStylePhase> appendedStylePhases;

/// The `SuperEditor` input source, e.g., keyboard or Input Method Engine.
final TextInputSource? inputSource;

Expand Down Expand Up @@ -624,7 +612,8 @@ class SuperEditorState extends State<SuperEditor> {
// just before the phases that the apps want to be at the end
// to minimize view model recalculations.
_docLayoutSelectionStyler,
...widget.appendedStylePhases,
for (final plugin in widget.plugins) //
...plugin.appendedStylePhases,
],
);

Expand Down Expand Up @@ -885,9 +874,8 @@ class SuperEditorState extends State<SuperEditor> {
selectionNotifier: editContext.composer.selectionNotifier,
contentTapHandlers: [
..._contentTapHandlers ?? [],
for (final plugin in widget.plugins)
if (plugin.contentTapDelegate != null) //
plugin.contentTapDelegate!,
for (final plugin in widget.plugins) //
...plugin.contentTapHandlers,
],
autoScroller: _autoScrollController,
fillViewport: fillViewport,
Expand All @@ -904,9 +892,8 @@ class SuperEditorState extends State<SuperEditor> {
openSoftwareKeyboard: _openSoftareKeyboard,
contentTapHandlers: [
..._contentTapHandlers ?? [],
for (final plugin in widget.plugins)
if (plugin.contentTapDelegate != null) //
plugin.contentTapDelegate!,
for (final plugin in widget.plugins) //
...plugin.contentTapHandlers,
],
scrollController: _scrollController,
dragHandleAutoScroller: _dragHandleAutoScroller,
Expand All @@ -924,9 +911,8 @@ class SuperEditorState extends State<SuperEditor> {
openSoftwareKeyboard: _openSoftareKeyboard,
contentTapHandlers: [
..._contentTapHandlers ?? [],
for (final plugin in widget.plugins)
if (plugin.contentTapDelegate != null) //
plugin.contentTapDelegate!,
for (final plugin in widget.plugins) //
...plugin.contentTapHandlers,
],
scrollController: _scrollController,
dragHandleAutoScroller: _dragHandleAutoScroller,
Expand Down Expand Up @@ -1188,7 +1174,10 @@ abstract class SuperEditorPlugin {

/// Optional handler that responds to taps on content, e.g., opening
/// a link when the user taps on text with a link attribution.
ContentTapDelegate? get contentTapDelegate => null;
List<ContentTapDelegate> get contentTapHandlers => const [];

/// Custom style phases that are added to the very end of the [SuperEditor] style phases.
List<SingleColumnLayoutStylePhase> get appendedStylePhases => const [];
}

/// A collection of policies that dictate how a [SuperEditor]'s selection will change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ class AndroidControlsDocumentLayerState
}

void _onSelectionHandlesAllowedChange() {
// The controller went from allowing selection handles to disallowing them, or vis-a-versa.
// Rebuild this widget to show/hide the handles.
setState(() {
//
});
Expand All @@ -328,7 +330,7 @@ class AndroidControlsDocumentLayerState
return null;
}

if (_controlsController!.areSelectionHandlesAllowed.value == false) {
if (!_controlsController!.areSelectionHandlesAllowed.value) {
// We don't want to show any selection handles.
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ class _SuperEditorSpellcheckScreenState extends State<_SuperEditorSpellcheckScre
child: SuperEditor(
autofocus: true,
editor: _editor,
appendedStylePhases: [
_spellingAndGrammarPlugin.styler,
],
stylesheet: defaultStylesheet.copyWith(
addRulesAfter: [
if (Theme.of(context).brightness == Brightness.dark) ..._darkModeStyles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ class SpellingAndGrammarPlugin extends SuperEditorPlugin {
late final List<SuperEditorLayerBuilder> documentOverlayBuilders;

@override
ContentTapDelegate? get contentTapDelegate => _contentTapDelegate;
List<ContentTapDelegate> get contentTapHandlers => _contentTapDelegate != null //
? [_contentTapDelegate!]
: const [];
late final _SpellCheckerContentTapDelegate? _contentTapDelegate;

@override
List<SingleColumnLayoutStylePhase> get appendedStylePhases => [_styler];

@override
void attach(Editor editor) {
editor.context.put(spellingErrorSuggestionsKey, _spellingErrorSuggestions);
Expand Down Expand Up @@ -483,11 +488,16 @@ class _SuperEditorIosSpellCheckerTapHandler extends _SpellCheckerContentTapDeleg
final SpellingAndGrammarStyler styler;

@override
TapHandlingInstruction onTap(DocumentPosition tapPosition) {
TapHandlingInstruction onTap(DocumentTapDetails details) {
if (editor == null) {
return TapHandlingInstruction.continueHandling;
}

final tapPosition = details.documentLayout.getDocumentPositionNearestToOffset(details.layoutOffset);
if (tapPosition == null) {
return TapHandlingInstruction.continueHandling;
}

final spelling = popoverController.findSuggestionsForWordAt(DocumentSelection.collapsed(position: tapPosition));
if (spelling == null || spelling.suggestions.isEmpty) {
_hideSpellCheckerPopover();
Expand Down Expand Up @@ -526,7 +536,12 @@ class _SuperEditorIosSpellCheckerTapHandler extends _SpellCheckerContentTapDeleg
}

@override
TapHandlingInstruction onDoubleTap(DocumentPosition tapPosition) {
TapHandlingInstruction onDoubleTap(DocumentTapDetails details) {
final tapPosition = details.documentLayout.getDocumentPositionNearestToOffset(details.layoutOffset);
if (tapPosition == null) {
return TapHandlingInstruction.continueHandling;
}

_hideSpellCheckerPopover();
return TapHandlingInstruction.continueHandling;
}
Expand Down Expand Up @@ -555,11 +570,16 @@ class _SuperEditorAndroidSpellCheckerTapHandler extends _SpellCheckerContentTapD
final SpellingAndGrammarStyler styler;

@override
TapHandlingInstruction onTap(DocumentPosition tapPosition) {
TapHandlingInstruction onTap(DocumentTapDetails details) {
if (editor == null) {
return TapHandlingInstruction.continueHandling;
}

final tapPosition = details.documentLayout.getDocumentPositionNearestToOffset(details.layoutOffset);
if (tapPosition == null) {
return TapHandlingInstruction.continueHandling;
}

final spelling = popoverController.findSuggestionsForWordAt(DocumentSelection.collapsed(position: tapPosition));
if (spelling == null || spelling.suggestions.isEmpty) {
_hideSpellCheckerPopover();
Expand Down Expand Up @@ -604,7 +624,7 @@ class _SuperEditorAndroidSpellCheckerTapHandler extends _SpellCheckerContentTapD
}

@override
TapHandlingInstruction onDoubleTap(DocumentPosition tapPosition) {
TapHandlingInstruction onDoubleTap(DocumentTapDetails details) {
_hideSpellCheckerPopover();
return TapHandlingInstruction.continueHandling;
}
Expand All @@ -626,11 +646,16 @@ class _SuperEditorDesktopSpellCheckerTapHandler extends _SpellCheckerContentTapD
final SpellCheckerPopoverController popoverController;

@override
TapHandlingInstruction onTap(DocumentPosition tapPosition) {
TapHandlingInstruction onTap(DocumentTapDetails details) {
if (editor == null) {
return TapHandlingInstruction.continueHandling;
}

final tapPosition = details.documentLayout.getDocumentPositionNearestToOffset(details.layoutOffset);
if (tapPosition == null) {
return TapHandlingInstruction.continueHandling;
}

final spelling = popoverController.findSuggestionsForWordAt(DocumentSelection.collapsed(position: tapPosition));
if (spelling == null || spelling.suggestions.isEmpty) {
_hideSpellCheckerPopover();
Expand All @@ -651,7 +676,7 @@ class _SuperEditorDesktopSpellCheckerTapHandler extends _SpellCheckerContentTapD
}

@override
TapHandlingInstruction onDoubleTap(DocumentPosition tapPosition) {
TapHandlingInstruction onDoubleTap(DocumentTapDetails details) {
_hideSpellCheckerPopover();
return TapHandlingInstruction.continueHandling;
}
Expand Down

0 comments on commit 329b24e

Please sign in to comment.