feat: disable scroll when showing popuplist

This commit is contained in:
Lucas.Xu 2022-08-08 18:40:09 +08:00
parent 6e71ec23a1
commit 27ea5a11a9
3 changed files with 29 additions and 10 deletions

View File

@ -106,13 +106,19 @@ void showPopupList(
.removeListener(clearPopupList); .removeListener(clearPopupList);
editorState.service.selectionService.currentSelection editorState.service.selectionService.currentSelection
.addListener(clearPopupList); .addListener(clearPopupList);
editorState.service.scrollService?.disable();
} }
void clearPopupList() { void clearPopupList() {
if (_popupListOverlay == null || _editorState == null) {
return;
}
_popupListOverlay?.remove(); _popupListOverlay?.remove();
_popupListOverlay = null; _popupListOverlay = null;
_editorState?.service.keyboardService?.enable(); _editorState?.service.keyboardService?.enable();
_editorState?.service.scrollService?.enable();
_editorState = null; _editorState = null;
} }
@ -215,11 +221,13 @@ class _PopupListWidgetState extends State<PopupListWidget> {
widget.items[selectedIndex].handler(widget.editorState); widget.items[selectedIndex].handler(widget.editorState);
return KeyEventResult.handled; return KeyEventResult.handled;
} }
} } else if (event.logicalKey == LogicalKeyboardKey.escape) {
if (event.logicalKey == LogicalKeyboardKey.escape) {
clearPopupList(); clearPopupList();
return KeyEventResult.handled; return KeyEventResult.handled;
} else if (event.logicalKey == LogicalKeyboardKey.backspace) {
clearPopupList();
_deleteSlash();
return KeyEventResult.handled;
} }
var newSelectedIndex = selectedIndex; var newSelectedIndex = selectedIndex;

View File

@ -6,7 +6,8 @@ mixin FlowyScrollService<T extends StatefulWidget> on State<T> {
void scrollTo(double dy); void scrollTo(double dy);
RenderObject? scrollRenderObject(); void enable();
void disable();
} }
class FlowyScroll extends StatefulWidget { class FlowyScroll extends StatefulWidget {
@ -25,6 +26,8 @@ class _FlowyScrollState extends State<FlowyScroll> with FlowyScrollService {
final _scrollController = ScrollController(); final _scrollController = ScrollController();
final _scrollViewKey = GlobalKey(); final _scrollViewKey = GlobalKey();
bool _scrollEnabled = true;
@override @override
double get dy => _scrollController.position.pixels; double get dy => _scrollController.position.pixels;
@ -51,15 +54,22 @@ class _FlowyScrollState extends State<FlowyScroll> with FlowyScrollService {
); );
} }
@override
void disable() {
_scrollEnabled = false;
debugPrint('[scroll] $_scrollEnabled');
}
@override
void enable() {
_scrollEnabled = true;
debugPrint('[scroll] $_scrollEnabled');
}
void _onPointerSignal(PointerSignalEvent event) { void _onPointerSignal(PointerSignalEvent event) {
if (event is PointerScrollEvent) { if (event is PointerScrollEvent && _scrollEnabled) {
final dy = (_scrollController.position.pixels + event.scrollDelta.dy); final dy = (_scrollController.position.pixels + event.scrollDelta.dy);
scrollTo(dy); scrollTo(dy);
} }
} }
@override
RenderObject? scrollRenderObject() {
return _scrollViewKey.currentContext?.findRenderObject();
}
} }

View File

@ -267,6 +267,7 @@ class _FlowySelectionState extends State<FlowySelection>
editorState.updateCursorSelection(selection); editorState.updateCursorSelection(selection);
editorState.service.keyboardService?.enable(); editorState.service.keyboardService?.enable();
editorState.service.scrollService?.enable();
} }
@override @override