From 60f08cd2468f19b8214ef38df5601ed400febfe8 Mon Sep 17 00:00:00 2001 From: macdfree Date: Mon, 1 Dec 2025 23:57:11 +0800 Subject: [PATCH] fix: fix the handling logic for mouse clicks on empty nodes in the request tree --- .../left/handler/RequestTreeMouseHandler.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/laker/postman/panel/collections/left/handler/RequestTreeMouseHandler.java b/src/main/java/com/laker/postman/panel/collections/left/handler/RequestTreeMouseHandler.java index 659c4728..e878dc6e 100644 --- a/src/main/java/com/laker/postman/panel/collections/left/handler/RequestTreeMouseHandler.java +++ b/src/main/java/com/laker/postman/panel/collections/left/handler/RequestTreeMouseHandler.java @@ -138,12 +138,22 @@ private boolean isClickOnHandle(int clickX, TreePath path) { * 获取鼠标位置的树路径 */ private TreePath getTreePathAt(int x, int y) { - int selRow = requestTree.getRowForLocation(x, y); TreePath selPath = requestTree.getPathForLocation(x, y); - if (selRow == -1 || selPath == null) { - // 如果没有找到坐标对应的节点,应该直接返回null,不做处理 - return null; + if (selPath == null) { + selPath = requestTree.getClosestPathForLocation(x, y); + if (selPath != null) { + // 判断Y坐标是否在树节点的矩形范围内,解决Y轴被误选中问题 + Rectangle bounds = requestTree.getPathBounds(selPath); + if (bounds == null) { + return null; + } + if (y > bounds.y && y < bounds.y + bounds.height) { + return selPath; + } else { + return null; + } + } } return selPath; }