diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromHistoryAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromHistoryAction.java index f6c77e289dc3..025896065f45 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromHistoryAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromHistoryAction.java @@ -5,6 +5,7 @@ import com.intellij.ide.CopyPasteManagerEx; import com.intellij.ide.DataManager; import com.intellij.idea.ActionsBundle; import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.ActionUiKind; import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -35,8 +36,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -final class PasteFromHistoryAction extends DumbAwareAction { - PasteFromHistoryAction() { +@ApiStatus.Internal +public class PasteFromHistoryAction extends DumbAwareAction { + protected PasteFromHistoryAction() { setEnabledInModalContext(true); } @@ -62,7 +64,7 @@ final class PasteFromHistoryAction extends DumbAwareAction { List selectedContents = chooser.getSelectedContents(); CopyPasteManagerEx copyPasteManager = CopyPasteManagerEx.getInstanceEx(); if (selectedContents.size() == 1) { - copyPasteManager.moveContentToStackTop(selectedContents.get(0)); + copyPasteManager.moveContentToStackTop(selectedContents.getFirst()); } else { copyPasteManager.setContents(new StringSelection(chooser.getSelectedText())); @@ -71,22 +73,25 @@ final class PasteFromHistoryAction extends DumbAwareAction { if (editor != null) { if (editor.isViewer()) return; } - final AnAction pasteAction = ActionManager.getInstance().getAction(chooser.getExitCode() == getPasteSimpleExitCode() - ? IdeActions.ACTION_EDITOR_PASTE_SIMPLE : IdeActions.ACTION_PASTE); - var dataContextForEvent = DataManager.getInstance().getDataContext(focusedComponent); - if (pasteAction != null && PlatformDataKeys.PASTE_PROVIDER.getData(dataContextForEvent) != null) { - AnActionEvent newEvent = new AnActionEvent(e.getInputEvent(), - dataContextForEvent, - e.getPlace(), e.getPresentation(), - ActionManager.getInstance(), - e.getModifiers()); - pasteAction.actionPerformed(newEvent); - } - else { - final Action defaultPasteAction = ((JComponent)focusedComponent).getActionMap().get(DefaultEditorKit.pasteAction); - if (defaultPasteAction != null) { - defaultPasteAction.actionPerformed(new ActionEvent(focusedComponent, ActionEvent.ACTION_PERFORMED, "")); - } + performPaste(e, (JComponent)focusedComponent, chooser.getExitCode() == getPasteSimpleExitCode()); + } + } + + @ApiStatus.Internal + protected void performPaste(@NotNull AnActionEvent e, @NotNull JComponent focusedComponent, boolean pasteSimple) { + final AnAction pasteAction = ActionManager.getInstance().getAction(pasteSimple + ? IdeActions.ACTION_EDITOR_PASTE_SIMPLE + : IdeActions.ACTION_PASTE); + var dataContextForEvent = DataManager.getInstance().getDataContext(focusedComponent); + if (pasteAction != null && PlatformDataKeys.PASTE_PROVIDER.getData(dataContextForEvent) != null) { + AnActionEvent newEvent = AnActionEvent.createEvent(pasteAction, dataContextForEvent, e.getPresentation(), + e.getPlace(), ActionUiKind.NONE, e.getInputEvent()); + pasteAction.actionPerformed(newEvent); + } + else { + final Action defaultPasteAction = focusedComponent.getActionMap().get(DefaultEditorKit.pasteAction); + if (defaultPasteAction != null) { + defaultPasteAction.actionPerformed(new ActionEvent(focusedComponent, ActionEvent.ACTION_PERFORMED, "")); } } } diff --git a/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java b/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java index f29ddaf6bd26..8adc23972c3b 100644 --- a/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java +++ b/platform/testFramework/extensions/src/com/intellij/keymap/KeymapsTestCase.java @@ -152,7 +152,7 @@ public abstract class KeymapsTestCase extends KeymapsTestCaseBase { {"shift control T", "GotoTest", "ServiceView.ShowServices", "Terminal.NewTab"}, {"shift control TAB", "Switcher", "Diff.FocusOppositePane"}, {"shift control U", "ShelveChanges.UnshelveWithDialog", "EditorToggleCase", "Markdown.Styling.CreateLink"}, - {"shift control V", "PasteMultiple", "JupyterNotebookPasteCellAboveCommandModeAction"}, + {"shift control V", "PasteMultiple", "JupyterNotebookPasteCellAboveCommandModeAction", "Terminal.PasteFromHistory"}, {"shift control alt D", "UML.ShowChanges", "Console.TableResult.CloneColumn"}, {"shift control alt ENTER", "Console.Jpa.GenerateDDL", "Console.TableResult.SubmitAndCommit", "Console.Transaction.Commit", "NotebookRunAllAction", "org.jetbrains.r.actions.RDebugAction"}, diff --git a/plugins/terminal/frontend/resources/intellij.terminal.frontend.xml b/plugins/terminal/frontend/resources/intellij.terminal.frontend.xml index 0adc0797d3fb..8e60fed6614b 100644 --- a/plugins/terminal/frontend/resources/intellij.terminal.frontend.xml +++ b/plugins/terminal/frontend/resources/intellij.terminal.frontend.xml @@ -98,6 +98,19 @@ + + + + + + + + + + + + @@ -157,6 +170,7 @@ + @@ -164,6 +178,7 @@ + @@ -196,6 +211,7 @@ + diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/action/TerminalPasteFromHistoryAction.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/action/TerminalPasteFromHistoryAction.kt new file mode 100644 index 000000000000..aa2da323cf29 --- /dev/null +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/action/TerminalPasteFromHistoryAction.kt @@ -0,0 +1,37 @@ +package com.intellij.terminal.frontend.action + +import com.intellij.openapi.actionSystem.ActionManager +import com.intellij.openapi.actionSystem.ActionPromoter +import com.intellij.openapi.actionSystem.ActionUiKind +import com.intellij.openapi.actionSystem.ActionUpdateThread +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.ex.ActionUtil +import com.intellij.openapi.actionSystem.remoting.ActionRemoteBehaviorSpecification +import com.intellij.openapi.editor.actions.PasteFromHistoryAction +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isAlternateBufferEditor +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isAlternateBufferModelEditor +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isOutputEditor +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isOutputModelEditor +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isPromptEditor +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.terminalEditor +import javax.swing.JComponent + +internal class TerminalPasteFromHistoryAction + : PasteFromHistoryAction(), ActionPromoter, ActionRemoteBehaviorSpecification.Frontend { + + override fun update(e: AnActionEvent) { + val editor = e.terminalEditor + e.presentation.isEnabledAndVisible = editor != null && ( + editor.isPromptEditor || editor.isOutputEditor || editor.isAlternateBufferEditor || // gen1 + editor.isOutputModelEditor || editor.isAlternateBufferModelEditor // gen2 + ) + } + + override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT + + override fun performPaste(e: AnActionEvent, focusedComponent: JComponent, pasteSimple: Boolean) { + val terminalPaste = ActionManager.getInstance().getAction("Terminal.Paste") ?: return + val newEvent = AnActionEvent.createEvent(terminalPaste, e.dataContext, null, e.place, ActionUiKind.NONE, e.inputEvent) + ActionUtil.performAction(terminalPaste, newEvent) + } +} \ No newline at end of file diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalEventDispatcher.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalEventDispatcher.kt index 7a0c1a1baf49..67e63a5becb1 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalEventDispatcher.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/impl/TerminalEventDispatcher.kt @@ -239,6 +239,7 @@ private class TerminalEventDispatcher( "Terminal.SwitchFocusToEditor", "Terminal.CopySelectedText", "Terminal.Paste", + "Terminal.PasteFromHistory", "Terminal.LineUp", "Terminal.LineDown", "Terminal.PageUp", diff --git a/plugins/terminal/resources/messages/TerminalBundle.properties b/plugins/terminal/resources/messages/TerminalBundle.properties index e528a7a6cd96..ecae0dc56e29 100644 --- a/plugins/terminal/resources/messages/TerminalBundle.properties +++ b/plugins/terminal/resources/messages/TerminalBundle.properties @@ -17,6 +17,8 @@ action.Terminal.CopySelectedText.text=Copy action.Terminal.CopySelectedText.description=Copy selected text to clipboard action.Terminal.Paste.text=Paste action.Terminal.Paste.description=Paste from clipboard +action.Terminal.PasteFromHistory.text=Past_e from History\u2026 +action.Terminal.PasteFromHistory.description=Paste from recent clipboards action.Terminal.PasteSelection.text=Paste From Selection Clipboard action.Terminal.PasteSelection.GoToAction.text=Paste From Selection Clipboard (Terminal) action.Terminal.PasteSelection.description=Paste from selection clipboard if available, or from regular clipboard diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/block/output/TerminalEventDispatcher.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/output/TerminalEventDispatcher.kt index 8026efdad00c..bca2cacad404 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/block/output/TerminalEventDispatcher.kt +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/output/TerminalEventDispatcher.kt @@ -184,6 +184,7 @@ internal abstract class TerminalEventDispatcher( "TerminalDecreaseFontSize", "TerminalResetFontSize", "Terminal.Paste", + "Terminal.PasteFromHistory", "Terminal.CopySelectedText", "Terminal.CopyBlock" )