Skip to content

Commit

Permalink
Allow home and end keys in query box
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Dec 19, 2023
1 parent 82fac20 commit 4cdf849
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Wox.UI.Flutter/wox/lib/components/wox_image_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WoxImageView extends StatelessWidget {
return Text("Invalid image data: ${woxImage.imageData}", style: const TextStyle(color: Colors.red));
}
final imageData = woxImage.imageData.split(";base64,")[1];
return Image.memory(base64Decode(imageData), width: width, height: height);
return Image.memory(base64Decode(imageData), width: width, height: height, fit: BoxFit.fill);
}
return const SizedBox(width: 24, height: 24);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class WoxQueryBoxView extends GetView<WoxLauncherController> {
case LogicalKeyboardKey.tab:
controller.autoCompleteQuery();
return KeyEventResult.handled;
case LogicalKeyboardKey.home:
controller.moveQueryBoxCursorToStart();
return KeyEventResult.handled;
case LogicalKeyboardKey.end:
controller.moveQueryBoxCursorToEnd();
return KeyEventResult.handled;
case LogicalKeyboardKey.keyJ:
if (event.isMetaPressed || event.isAltPressed) {
controller.toggleActionPanel();
Expand All @@ -55,7 +61,7 @@ class WoxQueryBoxView extends GetView<WoxLauncherController> {
height: 55.0,
child: TextField(
style: TextStyle(
fontSize: 24.0,
fontSize: 28.0,
color: fromCssColor(controller.woxTheme.value.queryBoxFontColor),
),
decoration: InputDecoration(
Expand All @@ -64,7 +70,7 @@ class WoxQueryBoxView extends GetView<WoxLauncherController> {
left: 8,
right: 8,
top: 10,
bottom: 20,
bottom: 18,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(controller.woxTheme.value.queryBoxBorderRadius.toDouble()),
Expand All @@ -77,6 +83,7 @@ class WoxQueryBoxView extends GetView<WoxLauncherController> {
autofocus: true,
focusNode: controller.queryBoxFocusNode,
controller: controller.queryBoxTextFieldController,
scrollController: controller.queryBoxScrollController,
onChanged: (value) {
// isComposingRangeValid is not reliable on Windows, we need to use inside post frame callback to check the value
// see https://github.com/flutter/flutter/issues/128565#issuecomment-1772016743
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
final queryBoxFocusNode = FocusNode();
final resultActionFocusNode = FocusNode();
final queryBoxTextFieldController = TextEditingController();
final queryBoxScrollController = ScrollController(initialScrollOffset: 0.0);
final resultActionTextFieldController = TextEditingController();
final resultListViewScrollController = ScrollController(initialScrollOffset: 0.0);
final resultActionListViewScrollController = ScrollController(initialScrollOffset: 0.0);
Expand Down Expand Up @@ -148,8 +149,13 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
void onQueryChanged(WoxChangeQuery query) {
_query.value = query;
isShowActionPanel.value = false;

if (query.queryType == WoxQueryTypeEnum.WOX_QUERY_TYPE_INPUT.code) {
// save the cursor position
final cursorPosition = queryBoxTextFieldController.selection.baseOffset;
queryBoxTextFieldController.text = query.queryText;
// try to restore the cursor position after set text, which will reset the cursor position
queryBoxTextFieldController.selection = TextSelection(baseOffset: cursorPosition, extentOffset: cursorPosition);
} else {
queryBoxTextFieldController.text = query.toString();
}
Expand Down Expand Up @@ -347,7 +353,7 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
// 2.5-> 3.8
// 3.0-> 3

final totalHeightFinal = totalHeight.toDouble() + (10 / window.devicePixelRatio).ceil();
final totalHeightFinal = totalHeight.toDouble() + (10 / PlatformDispatcher.instance.views.first.devicePixelRatio).ceil();
Logger.instance.info("Resize window height to $totalHeightFinal");
windowManager.setSize(Size(800, totalHeightFinal));
} else {
Expand Down Expand Up @@ -471,4 +477,14 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
resultListViewScrollController.dispose();
super.dispose();
}

void moveQueryBoxCursorToStart() {
queryBoxTextFieldController.selection = TextSelection.fromPosition(const TextPosition(offset: 0));
queryBoxScrollController.jumpTo(0);
}

void moveQueryBoxCursorToEnd() {
queryBoxTextFieldController.selection = TextSelection.collapsed(offset: queryBoxTextFieldController.text.length);
queryBoxScrollController.jumpTo(queryBoxScrollController.position.maxScrollExtent);
}
}
4 changes: 2 additions & 2 deletions Wox/plugin/system/chatgpt.go

Large diffs are not rendered by default.

0 comments on commit 4cdf849

Please sign in to comment.