diff --git a/recaf-ui/src/main/java/software/coley/recaf/ui/config/KeybindingConfig.java b/recaf-ui/src/main/java/software/coley/recaf/ui/config/KeybindingConfig.java index f78e49d78..e406e6199 100644 --- a/recaf-ui/src/main/java/software/coley/recaf/ui/config/KeybindingConfig.java +++ b/recaf-ui/src/main/java/software/coley/recaf/ui/config/KeybindingConfig.java @@ -47,6 +47,7 @@ public class KeybindingConfig extends BasicConfigContainer { private static final String ID_REPLACE = "editor.replace"; private static final String ID_SAVE = "editor.save"; private static final String ID_RENAME = "editor.rename"; + private static final String ID_GOTO = "editor.goto"; private final BindingBundle bundle; @Inject @@ -59,7 +60,8 @@ public KeybindingConfig(@Nonnull GsonProvider gsonProvider, @Nonnull ConfigCompo createBindForPlatform(ID_FIND, CONTROL, F), createBindForPlatform(ID_REPLACE, CONTROL, R), createBindForPlatform(ID_SAVE, CONTROL, S), - createBindForPlatform(ID_RENAME, ALT, R) + createBindForPlatform(ID_RENAME, ALT, R), + createBindForPlatform(ID_GOTO, F3) )); addValue(new BasicMapConfigValue<>("bundle", BindingBundle.class, String.class, Binding.class, bundle)); @@ -149,6 +151,16 @@ public Binding getRename() { return Objects.requireNonNull(bundle.get(ID_RENAME)); } + /** + * @return Keybinding for renaming whatever is found at the current caret position. + * + * @see JvmDecompilerPane Usage in decompiler. + */ + @Nonnull + public Binding getGoto() { + return Objects.requireNonNull(bundle.get(ID_GOTO)); + } + /** * Wrapper around {@link Binding#newBind(String, KeyCode...)} and {@link BindingCreator} * to swap out {@link KeyCode#CONTROL} for {@link KeyCode#META} for Mac users. diff --git a/recaf-ui/src/main/java/software/coley/recaf/ui/pane/editing/jvm/JvmDecompilerPane.java b/recaf-ui/src/main/java/software/coley/recaf/ui/pane/editing/jvm/JvmDecompilerPane.java index eba20ee0f..750bfc7f0 100644 --- a/recaf-ui/src/main/java/software/coley/recaf/ui/pane/editing/jvm/JvmDecompilerPane.java +++ b/recaf-ui/src/main/java/software/coley/recaf/ui/pane/editing/jvm/JvmDecompilerPane.java @@ -22,6 +22,7 @@ import software.coley.recaf.info.builder.JvmClassInfoBuilder; import software.coley.recaf.info.properties.builtin.CachedDecompileProperty; import software.coley.recaf.path.ClassPathNode; +import software.coley.recaf.path.IncompletePathException; import software.coley.recaf.services.compile.CompileMap; import software.coley.recaf.services.compile.CompilerDiagnostic; import software.coley.recaf.services.compile.JavacArgumentsBuilder; @@ -107,11 +108,22 @@ public JvmDecompilerPane(@Nonnull DecompilerPaneConfig config, setOnKeyPressed(e -> { if (keys.getSave().match(e)) save(); - if (keys.getRename().match(e)) { + else if (keys.getRename().match(e)) { // Resolve what the caret position has, then handle renaming on the generic result. AstResolveResult result = contextActionSupport.resolvePosition(editor.getCodeArea().getCaretPosition()); if (result != null) actions.rename(result.path()); + } else if (keys.getGoto().match(e)) { + // Resolve what the caret position has, then handle navigating to the resulting path. + AstResolveResult result = contextActionSupport.resolvePosition(editor.getCodeArea().getCaretPosition()); + if (result != null) { + try { + actions.gotoDeclaration(result.path()); + } catch (IncompletePathException ex) { + // Should realistically never happen + logger.warn("Cannot goto location, path incomplete", ex); + } + } } }); diff --git a/recaf-ui/src/main/resources/translations/en_US.lang b/recaf-ui/src/main/resources/translations/en_US.lang index 2593d595f..e37719373 100644 --- a/recaf-ui/src/main/resources/translations/en_US.lang +++ b/recaf-ui/src/main/resources/translations/en_US.lang @@ -133,6 +133,7 @@ menu.plugin.uninstall.warning=Are you sure you want to delete this plugin? bind.inputprompt.initial= bind.inputprompt.finish= bind.editor.find=Find +bind.editor.goto=Goto bind.editor.rename=Rename bind.editor.replace=Replace bind.editor.save=Save