Fix the double escape bug
This commit is contained in:
155
lib/main.dart
155
lib/main.dart
@@ -38,6 +38,9 @@ void main() async {
|
||||
class JournalerApp extends StatelessWidget {
|
||||
const JournalerApp({super.key});
|
||||
|
||||
static final GlobalKey<MainPageState> _mainPageKey =
|
||||
GlobalKey<MainPageState>();
|
||||
|
||||
static final TextTheme _baseTextTheme = const TextTheme(
|
||||
bodyMedium: TextStyle(fontSize: 24),
|
||||
);
|
||||
@@ -111,7 +114,30 @@ class JournalerApp extends StatelessWidget {
|
||||
theme: lightTheme,
|
||||
darkTheme: darkTheme,
|
||||
themeMode: ThemeMode.system,
|
||||
home: const MainPage(),
|
||||
home: Focus(
|
||||
// Using RawKeyboardListener despite deprecation because KeyboardListener
|
||||
// and Shortcuts/Actions didn't reliably capture the Escape key press
|
||||
// before the TextField handled it for unfocusing, requiring two presses.
|
||||
// RawKeyboardListener intercepts the event earlier.
|
||||
child: RawKeyboardListener(
|
||||
// Revert to RawKeyboardListener
|
||||
focusNode: FocusNode(),
|
||||
onKey: (RawKeyEvent event) {
|
||||
// Revert to onKey and RawKeyEvent
|
||||
if (event is RawKeyDownEvent && // Revert to RawKeyDownEvent
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
debugPrint("Escape pressed (RawKeyboardListener - Workaround)");
|
||||
final state = _mainPageKey.currentState;
|
||||
if (state != null) {
|
||||
// Re-add unfocus, as it seemed necessary with Raw listener
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
state.onWindowClose();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: MainPage(key: _mainPageKey),
|
||||
),
|
||||
),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
@@ -121,10 +147,10 @@ class MainPage extends StatefulWidget {
|
||||
const MainPage({super.key});
|
||||
|
||||
@override
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
State<MainPage> createState() => MainPageState();
|
||||
}
|
||||
|
||||
class _MainPageState extends State<MainPage> with WindowListener {
|
||||
class MainPageState extends State<MainPage> with WindowListener {
|
||||
final SystemTray _systemTray = SystemTray();
|
||||
final Menu _menu = Menu();
|
||||
final AudioPlayer _audioPlayer = AudioPlayer();
|
||||
@@ -260,79 +286,70 @@ class _MainPageState extends State<MainPage> with WindowListener {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return KeyboardListener(
|
||||
focusNode: FocusNode(),
|
||||
autofocus: true,
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
debugPrint("Escape key pressed - hiding window.");
|
||||
onWindowClose();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(title: const Text('Journaler'), actions: const []),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 9,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _previousEntryController,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Previous Entry',
|
||||
),
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Journaler'), actions: const []),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 9,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _previousEntryController,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Previous Entry',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _currentEntryController,
|
||||
focusNode: _currentEntryFocusNode,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
autofocus: true,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Current Entry (What\'s on your mind?)',
|
||||
),
|
||||
onChanged: (text) {},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: TextField(
|
||||
controller: _todoController,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
style:
|
||||
Theme.of(
|
||||
context,
|
||||
).textTheme.bodyMedium, // Apply theme text style
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Todo',
|
||||
// border: OutlineInputBorder(), // Handled by theme
|
||||
// contentPadding: EdgeInsets.all(8.0), // Handled by theme or default
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _currentEntryController,
|
||||
focusNode: _currentEntryFocusNode,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
autofocus: true,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Current Entry (What\'s on your mind?)',
|
||||
),
|
||||
onChanged: (text) {},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: TextField(
|
||||
controller: _todoController,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
style:
|
||||
Theme.of(
|
||||
context,
|
||||
).textTheme.bodyMedium, // Apply theme text style
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Todo',
|
||||
// border: OutlineInputBorder(), // Handled by theme
|
||||
// contentPadding: EdgeInsets.all(8.0), // Handled by theme or default
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --- End Actions and Shortcuts ---
|
||||
|
Reference in New Issue
Block a user