mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-15 18:02:58 +08:00
feat: hyperlinks require holding down the function key to open
This commit is contained in:
@@ -185,8 +185,9 @@ class TerminalPanel(val tab: TerminalTab?, val terminal: Terminal, private val w
|
||||
this.addMouseMotionListener(mouseAdapter)
|
||||
|
||||
// 超链接
|
||||
val hyperlinkAdapter = TerminalPanelMouseHyperlinkAdapter(this, terminal)
|
||||
val hyperlinkAdapter = TerminalPanelMouseHyperlinkAdapter(this, terminalDisplay, terminal)
|
||||
this.addMouseListener(hyperlinkAdapter)
|
||||
this.addMouseMotionListener(hyperlinkAdapter)
|
||||
|
||||
// 鼠标跟踪
|
||||
val trackingAdapter = TerminalPanelMouseTrackingAdapter(this, terminal, writer)
|
||||
|
||||
@@ -2,6 +2,8 @@ package app.termora.terminal.panel
|
||||
|
||||
import app.termora.terminal.ClickableHighlighter
|
||||
import app.termora.terminal.Terminal
|
||||
import com.formdev.flatlaf.util.SystemInfo
|
||||
import java.awt.Cursor
|
||||
import java.awt.event.MouseAdapter
|
||||
import java.awt.event.MouseEvent
|
||||
import javax.swing.SwingUtilities
|
||||
@@ -11,19 +13,42 @@ import javax.swing.SwingUtilities
|
||||
*/
|
||||
class TerminalPanelMouseHyperlinkAdapter(
|
||||
private val terminalPanel: TerminalPanel,
|
||||
private val terminalDisplay: TerminalDisplay,
|
||||
private val terminal: Terminal,
|
||||
) : MouseAdapter() {
|
||||
|
||||
override fun mouseClicked(e: MouseEvent) {
|
||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||
val position = terminalPanel.pointToPosition(e.point)
|
||||
for (highlighter in terminal.getMarkupModel().getHighlighters(position)) {
|
||||
if (highlighter is ClickableHighlighter) {
|
||||
highlighter.onClicked(position)
|
||||
}
|
||||
if (SwingUtilities.isLeftMouseButton(e).not()) {
|
||||
return
|
||||
}
|
||||
|
||||
if (SystemInfo.isMacOS) {
|
||||
if (e.isMetaDown.not())
|
||||
return
|
||||
} else if (e.isControlDown.not()) {
|
||||
return
|
||||
}
|
||||
|
||||
val position = terminalPanel.pointToPosition(e.point)
|
||||
for (highlighter in terminal.getMarkupModel().getHighlighters(position)) {
|
||||
if (highlighter is ClickableHighlighter) {
|
||||
highlighter.onClicked(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun mouseMoved(e: MouseEvent) {
|
||||
val position = terminalPanel.pointToPosition(e.point)
|
||||
var cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)
|
||||
for (highlighter in terminal.getMarkupModel().getHighlighters(position)) {
|
||||
if (highlighter is ClickableHighlighter) {
|
||||
cursor = if (SystemInfo.isMacOS) Cursor.getDefaultCursor()
|
||||
else Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
|
||||
break
|
||||
}
|
||||
}
|
||||
terminalDisplay.cursor = cursor
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user