mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-10 07:28:46 +00:00
fix: double cursor show in title and doc sometimes (#6437)
This commit is contained in:
parent
70e72d843e
commit
eca495ce63
@ -3,6 +3,7 @@ import 'package:appflowy/plugins/document/application/document_appearance_cubit.
|
|||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
|
||||||
import 'package:appflowy/workspace/application/appearance_defaults.dart';
|
import 'package:appflowy/workspace/application/appearance_defaults.dart';
|
||||||
import 'package:appflowy/workspace/application/view/view_bloc.dart';
|
import 'package:appflowy/workspace/application/view/view_bloc.dart';
|
||||||
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
@ -50,6 +51,7 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {
|
|||||||
final titleFocusNode = FocusNode();
|
final titleFocusNode = FocusNode();
|
||||||
late final editorContext = context.read<SharedEditorContext>();
|
late final editorContext = context.read<SharedEditorContext>();
|
||||||
late final editorState = context.read<EditorState>();
|
late final editorState = context.read<EditorState>();
|
||||||
|
bool isTitleFocused = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -59,7 +61,18 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {
|
|||||||
titleTextController.addListener(_onViewNameChanged);
|
titleTextController.addListener(_onViewNameChanged);
|
||||||
titleFocusNode.onKeyEvent = _onKeyEvent;
|
titleFocusNode.onKeyEvent = _onKeyEvent;
|
||||||
titleFocusNode.addListener(() {
|
titleFocusNode.addListener(() {
|
||||||
|
isTitleFocused = titleFocusNode.hasFocus;
|
||||||
|
|
||||||
if (titleFocusNode.hasFocus && editorState.selection != null) {
|
if (titleFocusNode.hasFocus && editorState.selection != null) {
|
||||||
|
Log.info('cover title got focus, clear the editor selection');
|
||||||
|
editorState.selection = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
editorState.selectionNotifier.addListener(() {
|
||||||
|
// if title is focused and the selection is not null, clear the selection
|
||||||
|
if (editorState.selection != null && isTitleFocused) {
|
||||||
|
Log.info('title is focused, clear the editor selection');
|
||||||
editorState.selection = null;
|
editorState.selection = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -217,19 +230,23 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {
|
|||||||
|
|
||||||
titleFocusNode.unfocus();
|
titleFocusNode.unfocus();
|
||||||
|
|
||||||
int offset = 0;
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||||
if (key == LogicalKeyboardKey.arrowDown) {
|
// delay the update selection to wait for the title to unfocus
|
||||||
offset = node.delta?.length ?? 0;
|
int offset = 0;
|
||||||
} else if (key == LogicalKeyboardKey.arrowRight) {
|
if (key == LogicalKeyboardKey.arrowDown) {
|
||||||
offset = 0;
|
offset = node.delta?.length ?? 0;
|
||||||
}
|
} else if (key == LogicalKeyboardKey.arrowRight) {
|
||||||
editorState.updateSelectionWithReason(
|
offset = 0;
|
||||||
Selection.collapsed(
|
}
|
||||||
Position(path: [0], offset: offset),
|
editorState.updateSelectionWithReason(
|
||||||
),
|
Selection.collapsed(
|
||||||
// trigger the keyboard service.
|
Position(path: [0], offset: offset),
|
||||||
reason: SelectionUpdateReason.uiEvent,
|
),
|
||||||
);
|
// trigger the keyboard service.
|
||||||
|
reason: SelectionUpdateReason.uiEvent,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return KeyEventResult.handled;
|
return KeyEventResult.handled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user