bug修复

This commit is contained in:
DelLevin-Home
2026-07-16 04:27:13 +08:00
parent 10ecf57fa7
commit a07256a683
4 changed files with 28 additions and 2 deletions

View File

@@ -148,6 +148,10 @@
cursor.scrollIntoView({ block: 'center', behavior: 'smooth' });
}
}
function requestHeightUpdate() {
requestAnimationFrame(notifyHeight);
}
</script>
</body>
</html>

View File

@@ -318,7 +318,17 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
theme: light,
darkTheme: dark,
themeMode: provider.themeMode,
builder: (ctx, nav) => AppShell(child: nav!),
builder: (ctx, nav) {
Widget shell = AppShell(child: nav!);
// Android: 点击空白区域收起键盘
if (Platform.isAndroid) {
shell = GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: shell,
);
}
return shell;
},
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

View File

@@ -64,6 +64,7 @@ class _NoteFormPageState extends State<NoteFormPage> {
void dispose() {
_autoSaveTimer?.cancel();
_saveStatusTimer?.cancel();
_scrollController.dispose();
_titleController.dispose();
_contentController.dispose();
super.dispose();

View File

@@ -153,6 +153,14 @@ class VditorEditorState extends State<VditorEditor> {
} catch (_) {}
}
Future<void> _requestHeightUpdate() async {
if (_controller == null || !_isReady) return;
try {
await Future.delayed(const Duration(milliseconds: 300));
await _controller!.evaluateJavascript(source: 'requestHeightUpdate()');
} catch (_) {}
}
void _onVditorReady() {
if (_isReady) return;
_fallbackTimer?.cancel();
@@ -276,10 +284,13 @@ class VditorEditorState extends State<VditorEditor> {
}
debugPrint('[VditorEditor] loading: $initialUrl');
// 键盘弹出时,滚动到光标位置
// 键盘弹出时,滚动到光标位置;键盘收起时,重新通知高度
final keyboardH = MediaQuery.of(context).viewInsets.bottom;
if (keyboardH > 0 && _lastKeyboardH == 0 && _isReady) {
Future.microtask(() => _scrollToCursor());
} else if (keyboardH == 0 && _lastKeyboardH > 0 && _isReady) {
// 键盘收起,请求 JS 端重新计算高度
Future.microtask(() => _requestHeightUpdate());
}
_lastKeyboardH = keyboardH;