Skip to content

Commit 61cff23

Browse files
NikkiAungvogella
authored andcommitted
Add global search result navigation shortcuts
1 parent 27438b5 commit 61cff23

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

bundles/org.eclipse.search/newsearch/org/eclipse/search2/internal/ui/SearchMessages.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ private SearchMessages() {
6969
public static String ShowNextResultAction_tooltip;
7070
public static String ShowPreviousResultAction_label;
7171
public static String ShowPreviousResultAction_tooltip;
72+
public static String GlobalNextSearchEntryAction_label;
73+
public static String GlobalNextSearchEntryAction_tooltip;
74+
public static String GlobalPreviousSearchEntryAction_label;
75+
public static String GlobalPreviousSearchEntryAction_tooltip;
7276
public static String RemoveMatchAction_label;
7377
public static String RemoveMatchAction_tooltip;
7478
public static String DefaultSearchViewPage_show_match;

bundles/org.eclipse.search/newsearch/org/eclipse/search2/internal/ui/SearchMessages.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ ShowNextResultAction_label=Next Match
4242
ShowNextResultAction_tooltip=Show Next Match
4343
ShowPreviousResultAction_label=Previous Match
4444
ShowPreviousResultAction_tooltip=Show Previous Match
45+
GlobalNextSearchEntryAction_label=Next Search Entry
46+
GlobalNextSearchEntryAction_tooltip=Go to Next Search Result
47+
GlobalPreviousSearchEntryAction_label=Previous Search Entry
48+
GlobalPreviousSearchEntryAction_tooltip=Go to Previous Search Result
4549
RemoveMatchAction_label=Remove Match
4650
RemoveMatchAction_tooltip=Remove Currently Showing Match
4751
DefaultSearchViewPage_show_match=Show Match
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse Foundation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Eclipse Foundation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.search2.internal.ui.basic.views;
15+
16+
import java.util.HashMap;
17+
18+
import org.eclipse.core.commands.AbstractHandler;
19+
import org.eclipse.core.commands.Command;
20+
import org.eclipse.core.commands.ExecutionEvent;
21+
import org.eclipse.core.commands.ExecutionException;
22+
import org.eclipse.core.commands.NotEnabledException;
23+
import org.eclipse.core.commands.NotHandledException;
24+
import org.eclipse.core.commands.ParameterizedCommand;
25+
import org.eclipse.core.commands.common.NotDefinedException;
26+
import org.eclipse.core.runtime.CoreException;
27+
import org.eclipse.core.runtime.IConfigurationElement;
28+
import org.eclipse.core.runtime.IExecutableExtension;
29+
import org.eclipse.swt.widgets.Event;
30+
import org.eclipse.ui.IWorkbenchCommandConstants;
31+
import org.eclipse.ui.IWorkbenchWindow;
32+
import org.eclipse.ui.commands.ICommandService;
33+
import org.eclipse.ui.handlers.HandlerUtil;
34+
import org.eclipse.ui.handlers.IHandlerService;
35+
36+
/**
37+
* Global handler for navigating to next/previous search results without requiring
38+
* focus on the Search view. This handler provides a seamless workflow for
39+
* navigating through search results while editing.
40+
*
41+
* @since 3.17
42+
*/
43+
public class GlobalNextPrevSearchEntryHandler extends AbstractHandler implements IExecutableExtension {
44+
private String searchCommand = IWorkbenchCommandConstants.NAVIGATE_NEXT;
45+
46+
@Override
47+
public Object execute(ExecutionEvent event) throws ExecutionException {
48+
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
49+
ICommandService cs = (ICommandService) window.getService(ICommandService.class);
50+
51+
// Show the Search view
52+
Command showView = cs.getCommand(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW);
53+
HashMap<String, Object> parms = new HashMap<String, Object>();
54+
parms.put(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID, "org.eclipse.search.ui.views.SearchView");
55+
ParameterizedCommand showSearchView = ParameterizedCommand.generateCommand(showView, parms);
56+
57+
IHandlerService hs = window.getService(IHandlerService.class);
58+
try {
59+
// Execute the sequence: show search view -> navigate -> activate editor
60+
hs.executeCommand(showSearchView, (Event)event.getTrigger());
61+
hs.executeCommand(searchCommand, (Event)event.getTrigger());
62+
hs.executeCommand(IWorkbenchCommandConstants.WINDOW_ACTIVATE_EDITOR, (Event)event.getTrigger());
63+
} catch (NotDefinedException e) {
64+
throw new ExecutionException(e.getMessage(), e);
65+
} catch (NotEnabledException e) {
66+
throw new ExecutionException(e.getMessage(), e);
67+
} catch (NotHandledException e) {
68+
throw new ExecutionException(e.getMessage(), e);
69+
}
70+
71+
return null;
72+
}
73+
74+
@Override
75+
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
76+
if ("previous".equals(data)) {
77+
searchCommand = IWorkbenchCommandConstants.NAVIGATE_PREVIOUS;
78+
}
79+
}
80+
}

bundles/org.eclipse.search/plugin.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@
104104
name="%command.performTextSearchFile.name"
105105
description="%command.performTextSearchFile.description"
106106
/>
107+
<command
108+
categoryId="org.eclipse.ui.category.navigate"
109+
id="org.eclipse.search.ui.globalNextSearchEntry"
110+
name="%GlobalNextSearchEntryAction_label"
111+
description="%GlobalNextSearchEntryAction_tooltip"
112+
defaultHandler="org.eclipse.search2.internal.ui.basic.views.GlobalNextPrevSearchEntryHandler:next"
113+
/>
114+
<command
115+
categoryId="org.eclipse.ui.category.navigate"
116+
id="org.eclipse.search.ui.globalPreviousSearchEntry"
117+
name="%GlobalPreviousSearchEntryAction_label"
118+
description="%GlobalPreviousSearchEntryAction_tooltip"
119+
defaultHandler="org.eclipse.search2.internal.ui.basic.views.GlobalNextPrevSearchEntryHandler:previous"
120+
/>
107121

108122
</extension>
109123

@@ -162,6 +176,18 @@
162176
commandId="org.eclipse.search.ui.performTextSearchWorkspace"
163177
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
164178
sequence="M1+M3+T"/>
179+
<key
180+
commandId="org.eclipse.search.ui.globalNextSearchEntry"
181+
contextId="org.eclipse.ui.contexts.window"
182+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
183+
sequence="ALT+.">
184+
</key>
185+
<key
186+
commandId="org.eclipse.search.ui.globalPreviousSearchEntry"
187+
contextId="org.eclipse.ui.contexts.window"
188+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
189+
sequence="ALT+,">
190+
</key>
165191

166192
</extension>
167193

0 commit comments

Comments
 (0)