Skip to content

Commit

Permalink
Merge branch 'superlistapp:main' into header-alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
lamnhan066 authored Sep 21, 2023
2 parents 4fed0ae + f471c24 commit 170259c
Show file tree
Hide file tree
Showing 26 changed files with 843 additions and 102 deletions.
2 changes: 1 addition & 1 deletion attributed_text/lib/src/attributed_spans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class AttributedSpans {
return _markers //
.reversed // search from the end so its the nearest start marker
.where((marker) {
return attribution == null || (marker.attribution.id == attribution.id);
return attribution == null || (marker.attribution == attribution);
}).firstWhereOrNull((marker) => marker.isStart && marker.offset <= offset);
}

Expand Down
42 changes: 29 additions & 13 deletions super_editor/example/lib/demos/example_editor/_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,23 @@ class _EditorToolbarState extends State<EditorToolbar> {
late FollowerBoundary _screenBoundary;

bool _showUrlField = false;
late FocusNode _popoverFocusNode;
late FocusNode _urlFocusNode;
AttributedTextEditingController? _urlController;
ImeAttributedTextEditingController? _urlController;

@override
void initState() {
super.initState();

_toolbarAligner = CupertinoPopoverToolbarAligner(widget.editorViewportKey);

_popoverFocusNode = FocusNode();

_urlFocusNode = FocusNode();
_urlController = SingleLineAttributedTextEditingController(_applyLink) //
..text = AttributedText("https://");
_urlController =
ImeAttributedTextEditingController(controller: SingleLineAttributedTextEditingController(_applyLink)) //
..onPerformActionPressed = _onPerformAction
..text = AttributedText("https://");
}

@override
Expand All @@ -94,6 +99,7 @@ class _EditorToolbarState extends State<EditorToolbar> {
void dispose() {
_urlFocusNode.dispose();
_urlController!.dispose();
_popoverFocusNode.dispose();
super.dispose();
}

Expand Down Expand Up @@ -457,6 +463,12 @@ class _EditorToolbarState extends State<EditorToolbar> {
}
}

void _onPerformAction(TextInputAction action) {
if (action == TextInputAction.done) {
_applyLink();
}
}

@override
Widget build(BuildContext context) {
return BuildInOrder(
Expand All @@ -477,15 +489,19 @@ class _EditorToolbarState extends State<EditorToolbar> {
}

Widget _buildToolbars() {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildToolbar(),
if (_showUrlField) ...[
const SizedBox(height: 8),
_buildUrlField(),
return SuperEditorPopover(
popoverFocusNode: _popoverFocusNode,
editorFocusNode: widget.editorFocusNode,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildToolbar(),
if (_showUrlField) ...[
const SizedBox(height: 8),
_buildUrlField(),
],
],
],
),
);
}

Expand Down Expand Up @@ -619,9 +635,9 @@ class _EditorToolbarState extends State<EditorToolbar> {
child: Row(
children: [
Expanded(
child: FocusWithCustomParent(
child: Focus(
focusNode: _urlFocusNode,
parentFocusNode: widget.editorFocusNode,
parentNode: _popoverFocusNode,
// We use a SuperTextField instead of a TextField because TextField
// automatically re-parents its FocusNode, which causes #609. Flutter
// #106923 tracks the TextField issue.
Expand Down
12 changes: 6 additions & 6 deletions super_editor/example/lib/demos/in_the_lab/popover_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ class _PopoverListState extends State<PopoverList> {

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => !_focusNode.hasPrimaryFocus ? _focusNode.requestFocus() : null,
child: Focus(
focusNode: _focusNode,
parentNode: widget.editorFocusNode,
onKeyEvent: _onKeyEvent,
return SuperEditorPopover(
popoverFocusNode: _focusNode,
editorFocusNode: widget.editorFocusNode,
onKeyEvent: _onKeyEvent,
child: GestureDetector(
onTap: () => !_focusNode.hasPrimaryFocus ? _focusNode.requestFocus() : null,
child: ListenableBuilder(
listenable: _focusNode,
builder: (context, child) {
Expand Down
4 changes: 0 additions & 4 deletions super_editor/lib/src/core/edit_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class SuperEditorContext {
required DocumentLayout Function() getDocumentLayout,
required this.composer,
required this.scroller,
required this.hasPrimaryFocus,
required this.commonOps,
}) : _getDocumentLayout = getDocumentLayout;

Expand All @@ -49,9 +48,6 @@ class SuperEditorContext {
/// scrolling.
final DocumentScroller scroller;

/// Whether `SuperEditor` currently has primary focus.
final ValueListenable<bool> hasPrimaryFocus;

/// Common operations that can be executed to apply common, complex changes to
/// the document.
final CommonEditorOperations commonOps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ class _AndroidDocumentTouchInteractorState extends State<AndroidDocumentTouchInt
void dispose() {
WidgetsBinding.instance.removeObserver(this);

// TODO: I commented this out because the scroll position is already
// disposed by the time this runs and it causes an error.
// _activeScrollPosition?.removeListener(_onScrollChange);
_activeScrollPosition?.removeListener(_onScrollChange);

// We dispose the EditingController on the next frame because
// the ListenableBuilder that uses it throws an error if we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class _IOSDocumentTouchInteractorState extends State<IOSDocumentTouchInteractor>
_removeEditingOverlayControls();

_teardownScrollController();
_activeScrollPosition?.removeListener(_onScrollChange);

_handleAutoScrolling.dispose();

Expand Down Expand Up @@ -895,9 +896,13 @@ class _IOSDocumentTouchInteractorState extends State<IOSDocumentTouchInteractor>
if (scrollPosition is ScrollPositionWithSingleContext) {
(scrollPosition as ScrollPositionWithSingleContext).goBallistic(-details.velocity.pixelsPerSecond.dy);

// We add the scroll change listener again, because going ballistic
// seems to switch out the scroll position.
scrollPosition.addListener(_onScrollChange);
if (_activeScrollPosition != scrollPosition) {
// We add the scroll change listener again, because going ballistic
// seems to switch out the scroll position.
_activeScrollPosition?.removeListener(_onScrollChange);
_activeScrollPosition = scrollPosition;
scrollPosition.addListener(_onScrollChange);
}
}
} else {
// The user was dragging a handle. Stop any auto-scrolling that may have started.
Expand Down Expand Up @@ -1260,6 +1265,8 @@ class _IOSDocumentTouchInteractorState extends State<IOSDocumentTouchInteractor>
scheduleBuildAfterBuild();
} else {
if (scrollPosition != _activeScrollPosition) {
_activeScrollPosition?.removeListener(_onScrollChange);

_activeScrollPosition = scrollPosition;
_activeScrollPosition?.addListener(_onScrollChange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,6 @@ ExecutionInstruction sendKeyEventToMacOs({
// For the full list of selectors handled by SuperEditor, see the MacOsSelectors class.
//
// This is needed for the interaction with the accent panel to work.

if (!editContext.hasPrimaryFocus.value) {
// SuperEditor has focus, but not primary focus. This can happen, for example,
// when an app displays a popover that takes primary focus. In this case, because
// SuperEditor no longer has primary focus, Flutter might intercept keys and do
// things we don't want, like move focus around when the user presses arrow keys.
// To prevent Flutter from doing things we don't want, in this case we run the
// standard key handlers instead of sending the signal to the OS.
return ExecutionInstruction.continueExecution;
}

return ExecutionInstruction.blocked;
}

Expand Down Expand Up @@ -517,6 +506,15 @@ ExecutionInstruction moveUpAndDownWithArrowKeys({
return ExecutionInstruction.continueExecution;
}

if (isWeb && (editContext.composer.composingRegion.value != null)) {
// We are composing a character on web. It's possible that a native element is being displayed,
// like an emoji picker or a character selection panel.
// We need to let the OS handle the key so the user can navigate
// on the list of possible characters.
// TODO: update this after https://github.com/flutter/flutter/issues/134268 is resolved.
return ExecutionInstruction.blocked;
}

if (defaultTargetPlatform == TargetPlatform.windows && keyEvent.isAltPressed) {
return ExecutionInstruction.continueExecution;
}
Expand Down Expand Up @@ -569,6 +567,15 @@ ExecutionInstruction moveLeftAndRightWithArrowKeys({
return ExecutionInstruction.continueExecution;
}

if (isWeb && (editContext.composer.composingRegion.value != null)) {
// We are composing a character on web. It's possible that a native element is being displayed,
// like an emoji picker or a character selection panel.
// We need to let the OS handle the key so the user can navigate
// on the list of possible characters.
// TODO: update this after https://github.com/flutter/flutter/issues/134268 is resolved.
return ExecutionInstruction.blocked;
}

if (defaultTargetPlatform == TargetPlatform.windows && keyEvent.isAltPressed) {
return ExecutionInstruction.continueExecution;
}
Expand Down
Loading

0 comments on commit 170259c

Please sign in to comment.