Skip to content

Commit

Permalink
Fix #4080 add mouse support for results
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Oct 24, 2024

Verified

This commit was signed with the committer’s verified signature.
mikealfare Mike Alfare
1 parent fbd9220 commit c30649c
Showing 2 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -96,7 +96,12 @@ class WoxQueryResultView extends GetView<WoxLauncherController> {
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [Text("Actions", style: TextStyle(color: fromCssColor(controller.woxTheme.value.actionContainerHeaderFontColor), fontSize: 16.0)), const Divider(), getActionListView(), getActionQueryBox()],
children: [
Text("Actions", style: TextStyle(color: fromCssColor(controller.woxTheme.value.actionContainerHeaderFontColor), fontSize: 16.0)),
const Divider(),
getActionListView(),
getActionQueryBox()
],
),
),
),
@@ -138,16 +143,39 @@ class WoxQueryResultView extends GetView<WoxLauncherController> {
itemExtent: WoxThemeUtil.instance.getResultListViewHeightByCount(1),
itemBuilder: (context, index) {
WoxQueryResult woxQueryResult = controller.getQueryResultByIndex(index);
return WoxListItemView(
key: controller.getResultItemGlobalKeyByIndex(index),
woxTheme: controller.woxTheme.value,
icon: woxQueryResult.icon,
title: woxQueryResult.title,
tails: woxQueryResult.tails,
subTitle: woxQueryResult.subTitle,
isActive: controller.isResultActiveByIndex(index),
listViewType: WoxListViewTypeEnum.WOX_LIST_VIEW_TYPE_RESULT.code,
isGroup: woxQueryResult.isGroup,
return MouseRegion(
onEnter: (_) {
if (controller.isMouseMoved) {
controller.setActiveResultIndex(index);
}
},
onHover: (_) {
if (!controller.isMouseMoved) {
controller.isMouseMoved = true;
controller.setActiveResultIndex(index);
}
},
child: GestureDetector(
onTap: () {
// request focus to action query box since it will lose focus when tap
controller.queryBoxFocusNode.requestFocus();
},
onDoubleTap: () {
controller.onEnter(const UuidV4().generate());
controller.queryBoxFocusNode.requestFocus();
},
child: WoxListItemView(
key: controller.getResultItemGlobalKeyByIndex(index),
woxTheme: controller.woxTheme.value,
icon: woxQueryResult.icon,
title: woxQueryResult.title,
tails: woxQueryResult.tails,
subTitle: woxQueryResult.subTitle,
isActive: controller.isResultActiveByIndex(index),
listViewType: WoxListViewTypeEnum.WOX_LIST_VIEW_TYPE_RESULT.code,
isGroup: woxQueryResult.isGroup,
),
),
);
},
),
Original file line number Diff line number Diff line change
@@ -96,6 +96,10 @@ class WoxLauncherController extends GetxController {
Timer cleanToolbarTimer = Timer(const Duration(), () => {});
final cleanToolbarDelay = 1000;

/// This flag is used to control whether the result item is selected by mouse hover.
/// This is used to prevent the result item from being selected when the mouse is just hovering over the item in the result list.
var isMouseMoved = false;

/// Triggered when received query results from the server.
void onReceivedQueryResults(String traceId, List<WoxQueryResult> receivedResults) {
if (receivedResults.isEmpty) {
@@ -338,6 +342,7 @@ class WoxLauncherController extends GetxController {

void onQueryBoxTextChanged(String value) {
canArrowUpHistory = false;
isMouseMoved = false;

if (currentQuery.value.queryType == WoxQueryTypeEnum.WOX_QUERY_TYPE_SELECTION.code) {
// do local filter if query type is selection
@@ -742,6 +747,14 @@ class WoxLauncherController extends GetxController {
return activeActionIndex.value == index;
}

void setActiveResultIndex(int index) {
activeResultIndex.value = index;
currentPreview.value = results[index].preview;
isShowPreviewPanel.value = currentPreview.value.previewData != "";
resetActiveAction(const UuidV4().generate(), "mouse hover");
results.refresh();
}

/// update active actions based on active result and reset active action index to 0
void resetActiveAction(String traceId, String reason) {
var activeQueryResult = getActiveResult();

0 comments on commit c30649c

Please sign in to comment.