Skip to content

Commit

Permalink
IJPL-172124 Allow to listen for command history popup events
Browse files Browse the repository at this point in the history
IJ-CR-148020

(cherry picked from commit a8ae3afc201097a0644567d414cd4350d9c9373c)

GitOrigin-RevId: 7614f8449f0df3ca3221df95bf81d1b9061dd816
  • Loading branch information
KonstantinHudyakov authored and intellij-monorepo-bot committed Nov 26, 2024
1 parent 6f492c9 commit 5b1545a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<CommandHistoryListener> = Topic(CommandHistoryListener::class.java, Topic.BroadcastDirection.NONE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 5b1545a

Please sign in to comment.