Skip to content

Commit

Permalink
Add goto keybind for navigating decompiled source, defaults to F3
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jan 13, 2025
1 parent c7c6026 commit 3aff987
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
});

Expand Down
1 change: 1 addition & 0 deletions recaf-ui/src/main/resources/translations/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ menu.plugin.uninstall.warning=Are you sure you want to delete this plugin?
bind.inputprompt.initial=<waiting>
bind.inputprompt.finish=<ENTER to finish>
bind.editor.find=Find
bind.editor.goto=Goto
bind.editor.rename=Rename
bind.editor.replace=Replace
bind.editor.save=Save
Expand Down

0 comments on commit 3aff987

Please sign in to comment.