diff --git a/doc/code_introduction.md b/doc/code_introduction.md index 62db155cc..9c9820793 100644 --- a/doc/code_introduction.md +++ b/doc/code_introduction.md @@ -200,7 +200,8 @@ RawEditorStateTextInputClientMixin - CompositedTransformTarget - Hooks the custom widget into the mechanics of layout rendering and calculation of dimensions (Flutter). - Why CompositedTransformTarget? - Because Quill uses a custom renderer to render the document (for performance reasons) - - If not expanded (meaning scrollable) it wraps the _editor with BaselineProxy QuillSingleChildScrollView and CompositedTransformTarget + - If not expanded (meaning scrollable) it wraps the _editor with BaselineProxy, SingleChildScrollView and CompositedTransformTarget. + [CompositedTransformTarget] is needed to allow selection handle overlays to track the selected text. Since [SingleChildScrollView] does not implement `computeDistanceToActualBaseline` it prevents the editor from providing its baseline metrics. To address this issue we wrap the scroll view with [BaselineProxy] which mimics the editor's baseline. This implies that the first line has no styles applied to it. diff --git a/lib/src/editor/raw_editor/raw_editor_state.dart b/lib/src/editor/raw_editor/raw_editor_state.dart index bec089581..ef9fed206 100644 --- a/lib/src/editor/raw_editor/raw_editor_state.dart +++ b/lib/src/editor/raw_editor/raw_editor_state.dart @@ -435,39 +435,44 @@ class QuillRawEditorState extends EditorState final baselinePadding = EdgeInsets.only(top: _styles!.paragraph!.verticalSpacing.top); child = BaselineProxy( - textStyle: _styles!.paragraph!.style, - padding: baselinePadding, - child: _scribbleFocusable( - SingleChildScrollView( - controller: _scrollController, - physics: widget.configurations.scrollPhysics, - child: MouseRegion( - cursor: widget.configurations.readOnly - ? widget.configurations.readOnlyMouseCursor - : SystemMouseCursors.text, - child: QuillRawEditorMultiChildRenderObject( - key: _editorKey, - document: doc, - selection: controller.selection, - hasFocus: _hasFocus, - scrollable: widget.configurations.scrollable, - textDirection: _textDirection, - startHandleLayerLink: _startHandleLayerLink, - endHandleLayerLink: _endHandleLayerLink, - onSelectionChanged: _handleSelectionChanged, - onSelectionCompleted: _handleSelectionCompleted, - scrollBottomInset: widget.configurations.scrollBottomInset, - padding: widget.configurations.padding, - maxContentWidth: widget.configurations.maxContentWidth, - cursorController: _cursorCont, - floatingCursorDisabled: - widget.configurations.floatingCursorDisabled, - children: _buildChildren(doc, context), + textStyle: _styles!.paragraph!.style, + padding: baselinePadding, + child: _scribbleFocusable( + SingleChildScrollView( + controller: _scrollController, + physics: widget.configurations.scrollPhysics, + child: CompositedTransformTarget( + link: _toolbarLayerLink, + child: MouseRegion( + cursor: widget.configurations.readOnly + ? widget.configurations.readOnlyMouseCursor + : SystemMouseCursors.text, + child: QuillRawEditorMultiChildRenderObject( + key: _editorKey, + offset: _scrollController.hasClients + ? _scrollController.position + : null, + document: doc, + selection: controller.selection, + hasFocus: _hasFocus, + scrollable: widget.configurations.scrollable, + textDirection: _textDirection, + startHandleLayerLink: _startHandleLayerLink, + endHandleLayerLink: _endHandleLayerLink, + onSelectionChanged: _handleSelectionChanged, + onSelectionCompleted: _handleSelectionCompleted, + scrollBottomInset: widget.configurations.scrollBottomInset, + padding: widget.configurations.padding, + maxContentWidth: widget.configurations.maxContentWidth, + cursorController: _cursorCont, + floatingCursorDisabled: + widget.configurations.floatingCursorDisabled, + children: _buildChildren(doc, context), + ), + ), ), ), - ), - ), - ); + )); } else { child = _scribbleFocusable( CompositedTransformTarget( @@ -501,7 +506,6 @@ class QuillRawEditorState extends EditorState ), ); } - final constraints = widget.configurations.expands ? const BoxConstraints.expand() : BoxConstraints(