mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2025-05-05 20:34:08 +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.codeInsight.intention.impl.ShowIntentionActionsHandler
|
||||||
import com.intellij.lang.LangBundle
|
import com.intellij.lang.LangBundle
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.ScrollType
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.util.PsiUtilBase
|
import com.intellij.psi.util.PsiUtilBase
|
||||||
|
|
||||||
internal object IntentionsPopup {
|
internal object IntentionsPopup {
|
||||||
fun showAt(editor: Editor, offset: Int) {
|
fun show(editor: Editor) {
|
||||||
editor.caretModel.moveToOffset(offset)
|
if (!tryShow(editor)) {
|
||||||
editor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
|
HintManager.getInstance().showInformationHint(editor, LangBundle.message("hint.text.no.context.actions.available.at.this.location"))
|
||||||
|
|
||||||
if (!tryShowPopup(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 project = editor.project ?: return false
|
||||||
val file = PsiUtilBase.getPsiFileInEditor(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.codeInsight.hints.presentation.InputHandler
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.Inlay
|
import com.intellij.openapi.editor.Inlay
|
||||||
|
import com.intellij.openapi.editor.ScrollType
|
||||||
import com.intellij.openapi.editor.colors.EditorFontType
|
import com.intellij.openapi.editor.colors.EditorFontType
|
||||||
import com.intellij.openapi.editor.ex.EditorEx
|
import com.intellij.openapi.editor.ex.EditorEx
|
||||||
import com.intellij.openapi.editor.impl.EditorImpl
|
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) {
|
override fun mousePressed(event: MouseEvent, translated: Point) {
|
||||||
if (!SwingUtilities.isLeftMouseButton(event) || !isHoveringText(translated)) {
|
if (!isHoveringText(translated)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
event.consume()
|
if (SwingUtilities.isLeftMouseButton(event) || SwingUtilities.isMiddleMouseButton(event)) {
|
||||||
IntentionsPopup.showAt(inlay.editor, info.actualStartOffset)
|
event.consume()
|
||||||
|
|
||||||
|
val editor = inlay.editor
|
||||||
|
moveToOffset(editor, info.actualStartOffset)
|
||||||
|
|
||||||
|
if (SwingUtilities.isLeftMouseButton(event)) {
|
||||||
|
IntentionsPopup.show(editor)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isHoveringText(point: Point): Boolean {
|
private fun isHoveringText(point: Point): Boolean {
|
||||||
@ -167,5 +176,10 @@ class LensRenderer(private var info: HighlightInfo, settings: LensSettingsState)
|
|||||||
private fun fixBaselineForTextRendering(rect: Rectangle) {
|
private fun fixBaselineForTextRendering(rect: Rectangle) {
|
||||||
rect.y += 1
|
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