mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2025-04-24 15:15:47 +02:00
Make middle-clicking an inspection lens jump to the start of the inspection highlight
This commit is contained in:
parent
4c80573375
commit
89e71d5301
src/main/kotlin/com/chylex/intellij/inspectionlens/editor/lens
@ -5,23 +5,19 @@ import com.intellij.codeInsight.hint.HintManager
|
||||
import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler
|
||||
import com.intellij.lang.LangBundle
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.ScrollType
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.PsiUtilBase
|
||||
|
||||
internal object IntentionsPopup {
|
||||
fun showAt(editor: Editor, offset: Int) {
|
||||
editor.caretModel.moveToOffset(offset)
|
||||
editor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
|
||||
|
||||
if (!tryShowPopup(editor)) {
|
||||
HintManager.getInstance().showInformationHint(editor, LangBundle.message("hint.text.no.context.actions.available.at.this.location"));
|
||||
fun show(editor: Editor) {
|
||||
if (!tryShow(editor)) {
|
||||
HintManager.getInstance().showInformationHint(editor, LangBundle.message("hint.text.no.context.actions.available.at.this.location"))
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryShowPopup(editor: Editor): Boolean {
|
||||
private fun tryShow(editor: Editor): Boolean {
|
||||
val project = editor.project ?: return false
|
||||
val file = PsiUtilBase.getPsiFileInEditor(editor, project) ?: return false
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.intellij.codeInsight.daemon.impl.HintRenderer
|
||||
import com.intellij.codeInsight.hints.presentation.InputHandler
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.Inlay
|
||||
import com.intellij.openapi.editor.ScrollType
|
||||
import com.intellij.openapi.editor.colors.EditorFontType
|
||||
import com.intellij.openapi.editor.ex.EditorEx
|
||||
import com.intellij.openapi.editor.impl.EditorImpl
|
||||
@ -107,12 +108,20 @@ class LensRenderer(private var info: HighlightInfo, settings: LensSettingsState)
|
||||
}
|
||||
|
||||
override fun mousePressed(event: MouseEvent, translated: Point) {
|
||||
if (!SwingUtilities.isLeftMouseButton(event) || !isHoveringText(translated)) {
|
||||
if (!isHoveringText(translated)) {
|
||||
return
|
||||
}
|
||||
|
||||
event.consume()
|
||||
IntentionsPopup.showAt(inlay.editor, info.actualStartOffset)
|
||||
if (SwingUtilities.isLeftMouseButton(event) || SwingUtilities.isMiddleMouseButton(event)) {
|
||||
event.consume()
|
||||
|
||||
val editor = inlay.editor
|
||||
moveToOffset(editor, info.actualStartOffset)
|
||||
|
||||
if (SwingUtilities.isLeftMouseButton(event)) {
|
||||
IntentionsPopup.show(editor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isHoveringText(point: Point): Boolean {
|
||||
@ -167,5 +176,10 @@ class LensRenderer(private var info: HighlightInfo, settings: LensSettingsState)
|
||||
private fun fixBaselineForTextRendering(rect: Rectangle) {
|
||||
rect.y += 1
|
||||
}
|
||||
|
||||
private fun moveToOffset(editor: Editor, offset: Int) {
|
||||
editor.caretModel.moveToOffset(offset)
|
||||
editor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user