diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/block/history/CommandHistoryListener.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/history/CommandHistoryListener.kt new file mode 100644 index 000000000000..42a803b9e07a --- /dev/null +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/history/CommandHistoryListener.kt @@ -0,0 +1,18 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.terminal.block.history + +import com.intellij.util.messages.Topic +import org.jetbrains.annotations.ApiStatus +import org.jetbrains.plugins.terminal.block.prompt.TerminalPromptModel + +@ApiStatus.Internal +interface CommandHistoryListener { + fun commandHistoryShown(promptModel: TerminalPromptModel) {} + + fun commandHistoryAborted(promptModel: TerminalPromptModel) {} + + companion object { + @Topic.ProjectLevel + val TOPIC: Topic = Topic(CommandHistoryListener::class.java, Topic.BroadcastDirection.NONE) + } +} diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/block/history/CommandHistoryPresenter.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/history/CommandHistoryPresenter.kt index 10a428c1b86b..f36c0db07866 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/block/history/CommandHistoryPresenter.kt +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/history/CommandHistoryPresenter.kt @@ -11,10 +11,10 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.openapi.util.UserDataHolder -import org.jetbrains.plugins.terminal.block.ui.getDisposed -import org.jetbrains.plugins.terminal.block.ui.invokeLater import org.jetbrains.plugins.terminal.block.prompt.TerminalPromptController import org.jetbrains.plugins.terminal.block.prompt.TerminalPromptModel +import org.jetbrains.plugins.terminal.block.ui.getDisposed +import org.jetbrains.plugins.terminal.block.ui.invokeLater internal class CommandHistoryPresenter( private val project: Project, @@ -68,6 +68,7 @@ internal class CommandHistoryPresenter( if (lookup.showLookup()) { lookup.ensureSelectionVisible(false) + project.messageBus.syncPublisher(CommandHistoryListener.TOPIC).commandHistoryShown(promptModel) } else thisLogger().error("Failed to show command history") } @@ -83,6 +84,8 @@ internal class CommandHistoryPresenter( invokeLater(editor.getDisposed()) { promptModel.commandText = commandToRestore editor.caretModel.moveToOffset(editor.document.textLength) + + project.messageBus.syncPublisher(CommandHistoryListener.TOPIC).commandHistoryAborted(promptModel) } } }