Skip to content

Commit

Permalink
Hide text selection rect when editor unfocused
Browse files Browse the repository at this point in the history
Fixes #298
  • Loading branch information
Amir-P committed Mar 25, 2024
1 parent a79d6d0 commit 307af5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 6 additions & 10 deletions packages/fleather/lib/src/rendering/editable_text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class RenderEditableTextLine extends RenderEditableBox {
/// manipulation. It's the responsibility of this object's owner
/// to provide selection manipulation affordances.
///
/// This field is used by [selectionEnabled] (which then controls
/// This field is used by [_shouldPaintSelection] (which then controls
/// the accessibility hints mentioned above).
bool get enableInteractiveSelection => _enableInteractiveSelection;
bool _enableInteractiveSelection;
Expand All @@ -122,17 +122,13 @@ class RenderEditableTextLine extends RenderEditableBox {
markNeedsSemanticsUpdate(); // TODO: should probably update semantics on the RenderEditor instead.
}

/// Whether interactive selection are enabled based on the value of
/// [enableInteractiveSelection].
/// Whether selection should be painted based on the value of
/// [enableInteractiveSelection] and [hasFocus].
///
/// If [enableInteractiveSelection] is not set then defaults to `true`.
bool get selectionEnabled {
return enableInteractiveSelection;
}
bool get _shouldPaintSelection => enableInteractiveSelection && hasFocus;

bool get containsSelection {
return intersectsWithSelection(node, _selection);
}
bool get containsSelection => intersectsWithSelection(node, _selection);

// End selection implementation

Expand Down Expand Up @@ -708,7 +704,7 @@ class RenderEditableTextLine extends RenderEditableBox {
_paintTextBackground(context, item, effectiveOffset);
}

if (selectionEnabled && containsSelection) {
if (_shouldPaintSelection && containsSelection) {
final local = localSelection(node, selection);
_selectionRects ??= body!.getBoxesForSelection(local);
_paintSelection(context, effectiveOffset);
Expand Down
6 changes: 3 additions & 3 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,6 @@ class RawEditorState extends EditorState
// Place cursor at the end if the selection is invalid when we receive focus.
// _handleSelectionChanged(TextSelection.collapsed(offset: _value.text.length), renderEditable, null);
// }
setState(() {
// Inform the widget that the value of focus has changed. (so that cursor can repaint appropriately)
});
} else {
WidgetsBinding.instance.removeObserver(this);
// TODO: teach editor about state of the toolbar and whether the user is in the middle of applying styles.
Expand All @@ -1478,6 +1475,9 @@ class RawEditorState extends EditorState
// source: ChangeSource.local);
// _currentPromptRectRange = null;
}
setState(() {
// Inform the widget that the value of focus has changed. (so that cursor can repaint appropriately)
});
updateKeepAlive();
}

Expand Down

0 comments on commit 307af5f

Please sign in to comment.