Skip to content

Commit

Permalink
highlight terminal links on hover (IDEA-218794, IDEA-342419)
Browse files Browse the repository at this point in the history
  • Loading branch information
segrey committed Feb 12, 2024
1 parent c3b0041 commit fdb4038
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.40
3.41
31 changes: 16 additions & 15 deletions ui/src/com/jediterm/terminal/ui/TerminalPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -229,6 +229,7 @@ public void mouseExited(MouseEvent e) {
myLinkHoverConsumer.onMouseExited();
myLinkHoverConsumer = null;
}
updateHoveredHyperlink(null);
}

@Override
Expand Down Expand Up @@ -331,7 +332,7 @@ public void focusGained(FocusEvent e) {
public void focusLost(FocusEvent e) {
myCursor.cursorChanged();

handleHyperlinks(e.getComponent(), false);
handleHyperlinks(e.getComponent());
}
});

Expand All @@ -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;
Expand All @@ -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();
}
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fdb4038

Please sign in to comment.