From b592415e7449664137f1de6c338de68746c875ba Mon Sep 17 00:00:00 2001 From: xuyi <2217021563@qq.com> Date: Mon, 26 May 2025 17:00:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=9D=97=E5=9B=BE=E9=92=89=E5=88=A0=E9=99=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A1=8C=E5=90=8E=E7=9A=84=E8=A1=8C=E5=8F=B7=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20#16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ilikexff/codepins/core/PinEntry.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/ilikexff/codepins/core/PinEntry.java b/src/main/java/cn/ilikexff/codepins/core/PinEntry.java index edb4090..39a33e4 100644 --- a/src/main/java/cn/ilikexff/codepins/core/PinEntry.java +++ b/src/main/java/cn/ilikexff/codepins/core/PinEntry.java @@ -222,15 +222,25 @@ public String toString() { String lineInfo; if (isBlock) { - // 如果是代码块,显示起始行号到结束行号 - int startLine = doc.getLineNumber(marker.getStartOffset()) + 1; // 转为从1开始的行号 - int endLine = doc.getLineNumber(marker.getEndOffset()) + 1; // 转为从1开始的行号 - - // 如果起始行和结束行相同,则只显示一个行号 - if (startLine == endLine) { - lineInfo = "Line " + startLine; + // 获取代码块的起始和结束偏移量 + int startOffset = marker.getStartOffset(); + int endOffset = marker.getEndOffset(); + + // 检查代码块是否完全被删除 + if (startOffset == endOffset) { + // 代码块图钉的代码已被完全删除,显示为无效状态 + lineInfo = "Line ?"; } else { - lineInfo = "Line " + startLine + "-" + endLine; + // 如果是代码块,显示起始行号到结束行号 + int startLine = doc.getLineNumber(startOffset) + 1; // 转为从1开始的行号 + int endLine = doc.getLineNumber(endOffset) + 1; // 转为从1开始的行号 + + // 如果起始行和结束行相同,则只显示一个行号 + if (startLine == endLine) { + lineInfo = "Line " + startLine; + } else { + lineInfo = "Line " + startLine + "-" + endLine; + } } } else { // 如果是单行图钉,只显示当前行号 From dbabb2be8da47bc79ac4a3fb7407309d5e54404e Mon Sep 17 00:00:00 2001 From: xuyi <2217021563@qq.com> Date: Mon, 26 May 2025 17:06:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=9D=97=E5=9B=BE=E9=92=89=E5=88=A0=E9=99=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A1=8C=E5=90=8E=E7=9A=84=E8=A1=8C=E5=8F=B7=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=A2=9E=E5=BC=BA=E8=B7=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E5=85=BC=E5=AE=B9=E6=80=A7=20#16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ilikexff/codepins/core/PinEntry.java | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/main/java/cn/ilikexff/codepins/core/PinEntry.java b/src/main/java/cn/ilikexff/codepins/core/PinEntry.java index 39a33e4..1d19598 100644 --- a/src/main/java/cn/ilikexff/codepins/core/PinEntry.java +++ b/src/main/java/cn/ilikexff/codepins/core/PinEntry.java @@ -213,7 +213,7 @@ public String toString() { if (!tags.isEmpty()) { tagsStr = " [" + String.join(", ", tags) + "]"; } - return typeLabel + " " + filePath + " @ Line ? (无效标记)" + return typeLabel + " " + filePath.replace("\\", "/") + " @ Line ? (无效标记)" + (note != null && !note.isEmpty() ? " - " + note : "") + tagsStr; } @@ -221,31 +221,37 @@ public String toString() { Document doc = marker.getDocument(); String lineInfo; - if (isBlock) { - // 获取代码块的起始和结束偏移量 - int startOffset = marker.getStartOffset(); - int endOffset = marker.getEndOffset(); - - // 检查代码块是否完全被删除 - if (startOffset == endOffset) { - // 代码块图钉的代码已被完全删除,显示为无效状态 - lineInfo = "Line ?"; - } else { - // 如果是代码块,显示起始行号到结束行号 - int startLine = doc.getLineNumber(startOffset) + 1; // 转为从1开始的行号 - int endLine = doc.getLineNumber(endOffset) + 1; // 转为从1开始的行号 - - // 如果起始行和结束行相同,则只显示一个行号 - if (startLine == endLine) { - lineInfo = "Line " + startLine; + try { + if (isBlock) { + // 获取代码块的起始和结束偏移量 + int startOffset = marker.getStartOffset(); + int endOffset = marker.getEndOffset(); + + // 检查代码块是否完全被删除 + if (startOffset == endOffset) { + // 代码块图钉的代码已被完全删除,显示为无效状态 + lineInfo = "Line ?"; } else { - lineInfo = "Line " + startLine + "-" + endLine; + // 如果是代码块,显示起始行号到结束行号 + int startLine = doc.getLineNumber(startOffset) + 1; // 转为从1开始的行号 + int endLine = doc.getLineNumber(endOffset) + 1; // 转为从1开始的行号 + + // 如果起始行和结束行相同,则只显示一个行号 + if (startLine == endLine) { + lineInfo = "Line " + startLine; + } else { + lineInfo = "Line " + startLine + "-" + endLine; + } } + } else { + // 如果是单行图钉,只显示当前行号 + int line = doc.getLineNumber(marker.getStartOffset()) + 1; // 转为从1开始的行号 + lineInfo = "Line " + line; } - } else { - // 如果是单行图钉,只显示当前行号 - int line = doc.getLineNumber(marker.getStartOffset()) + 1; // 转为从1开始的行号 - lineInfo = "Line " + line; + } catch (IndexOutOfBoundsException e) { + // 如果行号计算出现越界异常,显示为无效状态 + lineInfo = "Line ?"; + System.out.println("[CodePins] 行号计算异常: " + e.getMessage()); } String typeLabel = isBlock ? "[代码块]" : "[单行]"; @@ -253,7 +259,7 @@ public String toString() { if (!tags.isEmpty()) { tagsStr = " [" + String.join(", ", tags) + "]"; } - return typeLabel + " " + filePath + " @ " + lineInfo + return typeLabel + " " + filePath.replace("\\", "/") + " @ " + lineInfo + (note != null && !note.isEmpty() ? " - " + note : "") + tagsStr; } catch (Exception e) { @@ -263,7 +269,7 @@ public String toString() { if (!tags.isEmpty()) { tagsStr = " [" + String.join(", ", tags) + "]"; } - return typeLabel + " " + filePath + " @ Line ? (异常: " + e.getMessage() + ")" + + return typeLabel + " " + filePath.replace("\\", "/") + " @ Line ? (异常: " + e.getMessage() + ")" + (note != null && !note.isEmpty() ? " - " + note : "") + tagsStr; }