fix: replace code selection behaviour (fixes #614)

This commit is contained in:
Carl-Robert Linnupuu 2024-07-12 11:52:43 +03:00
parent f60fabcded
commit 2b9eaea9d4
2 changed files with 10 additions and 4 deletions

View file

@ -30,9 +30,12 @@ public class ReplaceCodeInMainEditorAction extends AnAction {
var project = event.getProject();
var toolWindowEditor = event.getData(PlatformDataKeys.EDITOR);
if (project != null && toolWindowEditor != null) {
EditorUtil.replaceEditorSelection(
toolWindowEditor,
requireNonNull(toolWindowEditor.getSelectionModel().getSelectedText()));
var mainEditor = EditorUtil.getSelectedEditor(project);
if (mainEditor != null) {
EditorUtil.replaceEditorSelection(
mainEditor,
requireNonNull(toolWindowEditor.getSelectionModel().getSelectedText()));
}
}
}

View file

@ -27,7 +27,10 @@ public class ReplaceSelectionAction extends TrackableAction {
public void handleAction(@NotNull AnActionEvent event) {
var project = requireNonNull(event.getProject());
if (EditorUtil.isMainEditorTextSelected(project)) {
EditorUtil.replaceEditorSelection(editor, editor.getDocument().getText());
var mainEditor = EditorUtil.getSelectedEditor(project);
if (mainEditor != null) {
EditorUtil.replaceEditorSelection(mainEditor, editor.getDocument().getText());
}
} else {
OverlayUtil.showSelectedEditorSelectionWarning(event);
}