mirror of https://github.com/Wox-launcher/Wox
Refactor keyboard event handling and action panel logic
Switched from KeyboardListener to Focus with autofocus for better keyboard event handling across multiple views. Improved action panel behavior by prioritizing default actions, ensuring they appear first in the list.
This commit is contained in:
parent
e9ede3033a
commit
82efa3b791
|
@ -149,8 +149,17 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
|
||||||
}
|
}
|
||||||
|
|
||||||
void showActionPanel() {
|
void showActionPanel() {
|
||||||
|
var actions = queryResults[_activeResultIndex.value].actions;
|
||||||
|
// move default action to the first
|
||||||
|
final defaultActionIndex = actions.indexWhere((element) => element.isDefault);
|
||||||
|
if (defaultActionIndex != -1) {
|
||||||
|
final defaultAction = actions[defaultActionIndex];
|
||||||
|
actions.removeAt(defaultActionIndex);
|
||||||
|
actions.insert(0, defaultAction);
|
||||||
|
}
|
||||||
|
|
||||||
_activeActionIndex.value = 0;
|
_activeActionIndex.value = 0;
|
||||||
_resultActions.value = queryResults[_activeResultIndex.value].actions;
|
_resultActions.value = actions;
|
||||||
filterResultActions.value = _resultActions;
|
filterResultActions.value = _resultActions;
|
||||||
for (var _ in filterResultActions) {
|
for (var _ in filterResultActions) {
|
||||||
_resultActionItemGlobalKeys.add(GlobalKey());
|
_resultActionItemGlobalKeys.add(GlobalKey());
|
||||||
|
|
|
@ -37,8 +37,9 @@ class WoxSettingPluginView extends GetView<WoxSettingController> {
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 20),
|
padding: const EdgeInsets.only(bottom: 20),
|
||||||
child: KeyboardListener(
|
child: Focus(
|
||||||
focusNode: FocusNode(onKeyEvent: (FocusNode node, KeyEvent event) {
|
autofocus: true,
|
||||||
|
onKeyEvent: (FocusNode node, KeyEvent event) {
|
||||||
if (event is KeyDownEvent) {
|
if (event is KeyDownEvent) {
|
||||||
switch (event.logicalKey) {
|
switch (event.logicalKey) {
|
||||||
case LogicalKeyboardKey.escape:
|
case LogicalKeyboardKey.escape:
|
||||||
|
@ -48,7 +49,7 @@ class WoxSettingPluginView extends GetView<WoxSettingController> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
}),
|
},
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
return TextBox(
|
return TextBox(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
|
|
|
@ -14,8 +14,9 @@ class WoxSettingThemeView extends GetView<WoxSettingController> {
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 20),
|
padding: const EdgeInsets.only(bottom: 20),
|
||||||
child: KeyboardListener(
|
child: Focus(
|
||||||
focusNode: FocusNode(onKeyEvent: (FocusNode node, event) {
|
autofocus: true,
|
||||||
|
onKeyEvent: (FocusNode node, KeyEvent event) {
|
||||||
if (event is KeyDownEvent) {
|
if (event is KeyDownEvent) {
|
||||||
switch (event.logicalKey) {
|
switch (event.logicalKey) {
|
||||||
case LogicalKeyboardKey.escape:
|
case LogicalKeyboardKey.escape:
|
||||||
|
@ -25,7 +26,7 @@ class WoxSettingThemeView extends GetView<WoxSettingController> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
}),
|
},
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
return TextBox(
|
return TextBox(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
|
|
|
@ -15,8 +15,9 @@ class WoxSettingView extends GetView<WoxSettingController> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
return KeyboardListener(
|
return Focus(
|
||||||
focusNode: FocusNode(onKeyEvent: (FocusNode node, KeyEvent event) {
|
autofocus: true,
|
||||||
|
onKeyEvent: (FocusNode node, KeyEvent event) {
|
||||||
if (event is KeyDownEvent) {
|
if (event is KeyDownEvent) {
|
||||||
switch (event.logicalKey) {
|
switch (event.logicalKey) {
|
||||||
case LogicalKeyboardKey.escape:
|
case LogicalKeyboardKey.escape:
|
||||||
|
@ -26,7 +27,7 @@ class WoxSettingView extends GetView<WoxSettingController> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
}),
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
body: FluentApp(
|
body: FluentApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
|
|
Loading…
Reference in New Issue