Skip to content

Commit

Permalink
Chore: convert _isNodeInline into a function in a extension for Node …
Browse files Browse the repository at this point in the history
…objects
  • Loading branch information
CatHood0 committed Nov 28, 2024
1 parent 8429efa commit 6bb3a13
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 10 additions & 0 deletions lib/src/common/extensions/nodes_ext.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import '../../document/nodes/node.dart';

extension NodesCheckingExtension on Node {
bool isNodeInline(){
for (final attr in style.attributes.values) {
if (!attr.isInline) return false;
}
return true;
}
}
12 changes: 2 additions & 10 deletions lib/src/editor/widgets/cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';
import 'package:flutter/widgets.dart';

import '../../common/utils/platform.dart';
import '../../document/nodes/line.dart';
import 'box.dart';
import 'cursor_configuration/cursor_configuration.dart';

Expand Down Expand Up @@ -264,7 +263,7 @@ class CursorPainter {
Offset offset,
TextPosition position,
bool lineHasEmbed,
Line node,
bool isNodeValid,
CursorPlaceholderConfig? cursorPlaceholderConfig,
TextDirection textDirection,
) {
Expand Down Expand Up @@ -335,7 +334,7 @@ class CursorPainter {
if (cursorPlaceholderConfig != null &&
cursorPlaceholderConfig.show &&
cursorPlaceholderConfig.text.trim().isNotEmpty) {
if (_isNodeInline(node) && node.isEmpty) {
if (isNodeValid) {
final localOffset = cursorPlaceholderConfig.offset;
if (localOffset == null) return;
placeholderPainter ??= TextPainter(
Expand All @@ -352,13 +351,6 @@ class CursorPainter {
}
}

bool _isNodeInline(Line node) {
for (final attr in node.style.attributes.values) {
if (!attr.isInline) return false;
}
return true;
}

Offset _getPixelPerfectCursorOffset(
Rect caretRect,
) {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/editor/widgets/text/text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher_string.dart' show launchUrlString;

import '../../../../flutter_quill.dart';
import '../../../common/extensions/nodes_ext.dart';
import '../../../common/utils/color.dart';
import '../../../common/utils/font.dart';
import '../../../common/utils/platform.dart';
Expand Down Expand Up @@ -1444,12 +1445,13 @@ class RenderEditableTextLine extends RenderEditableBox {
offset: textSelection.extentOffset - line.documentOffset,
affinity: textSelection.base.affinity,
);
final isNodeValid = line.isNodeInline() && line.isEmpty;
_cursorPainter.paint(
context.canvas,
effectiveOffset,
position,
lineHasEmbed,
line,
isNodeValid,
cursorPlaceholderConfig,
textDirection,
);
Expand Down

0 comments on commit 6bb3a13

Please sign in to comment.