From fdb4038e8106495953455dc19c1f507204657af5 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Tue, 13 Feb 2024 00:00:38 +0100 Subject: [PATCH] highlight terminal links on hover (IDEA-218794, IDEA-342419) --- VERSION | 2 +- .../jediterm/terminal/ui/TerminalPanel.java | 31 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/VERSION b/VERSION index 19035b79..f2fe4786 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.40 \ No newline at end of file +3.41 \ No newline at end of file diff --git a/ui/src/com/jediterm/terminal/ui/TerminalPanel.java b/ui/src/com/jediterm/terminal/ui/TerminalPanel.java index bf237958..2ad7d351 100644 --- a/ui/src/com/jediterm/terminal/ui/TerminalPanel.java +++ b/ui/src/com/jediterm/terminal/ui/TerminalPanel.java @@ -183,7 +183,7 @@ public void init(@NotNull JScrollBar scrollBar) { addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { - handleHyperlinks(e.getPoint(), e.isControlDown()); + handleHyperlinks(e.getPoint()); } @Override @@ -229,6 +229,7 @@ public void mouseExited(MouseEvent e) { myLinkHoverConsumer.onMouseExited(); myLinkHoverConsumer = null; } + updateHoveredHyperlink(null); } @Override @@ -331,7 +332,7 @@ public void focusGained(FocusEvent e) { public void focusLost(FocusEvent e) { myCursor.cursorChanged(); - handleHyperlinks(e.getComponent(), false); + handleHyperlinks(e.getComponent()); } }); @@ -355,7 +356,7 @@ protected void handleMouseWheelEvent(@NotNull MouseWheelEvent e, @NotNull JScrol e.consume(); } - private void handleHyperlinks(@NotNull java.awt.Point panelPoint, boolean isControlDown) { + private void handleHyperlinks(@NotNull java.awt.Point panelPoint) { Cell cell = panelPointToCell(panelPoint); HyperlinkStyle linkStyle = findHyperlink(cell); LinkInfo linkInfo = linkStyle != null ? linkStyle.getLinkInfo() : null; @@ -370,17 +371,18 @@ private void handleHyperlinks(@NotNull java.awt.Point panelPoint, boolean isCont } } myLinkHoverConsumer = linkHoverConsumer; - if (linkStyle != null) { - if (linkStyle.getHighlightMode() == HyperlinkStyle.HighlightMode.ALWAYS || (linkStyle.getHighlightMode() == HyperlinkStyle.HighlightMode.HOVER && isControlDown)) { - updateCursor(Cursor.HAND_CURSOR); - myHoveredHyperlink = linkStyle.getLinkInfo(); - return; - } + if (linkStyle != null && linkStyle.getHighlightMode() != HyperlinkStyle.HighlightMode.NEVER) { + updateHoveredHyperlink(linkStyle.getLinkInfo()); } + else { + updateHoveredHyperlink(null); + } + } - myHoveredHyperlink = null; - if (myCursorType != Cursor.DEFAULT_CURSOR) { - updateCursor(Cursor.DEFAULT_CURSOR); + private void updateHoveredHyperlink(@Nullable LinkInfo hoveredHyperlink) { + if (myHoveredHyperlink != hoveredHyperlink) { + updateCursor(hoveredHyperlink != null ? Cursor.HAND_CURSOR : Cursor.DEFAULT_CURSOR); + myHoveredHyperlink = hoveredHyperlink; repaint(); } } @@ -397,12 +399,12 @@ private void handleHyperlinks(@NotNull java.awt.Point panelPoint, boolean isCont return new LineCellInterval(initialCell.getLine(), startColumn, endColumn); } - private void handleHyperlinks(Component component, boolean controlDown) { + private void handleHyperlinks(Component component) { PointerInfo a = MouseInfo.getPointerInfo(); if (a != null) { java.awt.Point b = a.getLocation(); SwingUtilities.convertPointFromScreen(b, component); - handleHyperlinks(b, controlDown); + handleHyperlinks(b); } } @@ -946,7 +948,6 @@ private boolean inSelection(int x, int y) { @Override public void processKeyEvent(final KeyEvent e) { handleKeyEvent(e); - handleHyperlinks(e.getComponent(), e.isControlDown()); } // also called from com.intellij.terminal.JBTerminalPanel