diff --git a/src/main/java/Sdf1_login/CustomScreenManager.java b/src/main/java/Sdf1_login/CustomScreenManager.java index daeb7c5..eb83f4c 100644 --- a/src/main/java/Sdf1_login/CustomScreenManager.java +++ b/src/main/java/Sdf1_login/CustomScreenManager.java @@ -541,18 +541,16 @@ public class CustomScreenManager implements Listener { * 让整段编号完整留页或完整翻页, 绝不被劈。 */ static int protectCut(String s, int cut) { if (cut <= 0 || cut >= s.length()) return cut; - // 在切点附近(前12字~后5字)找"第\s*\d+\s*[节章条款]"短语 + // 15m30: 嵌套编号"第X章第X节"(X=汉字/阿拉伯数字)整串保护, 切点在短语内回退到最外层"第"前 int from = Math.max(0, cut - 12); int to = Math.min(s.length(), cut + 5); String window = s.substring(from, to); - // 找 window 里所有短语匹配, 看切点是否劈在某短语内部 - java.util.regex.Matcher m = java.util.regex.Pattern.compile("本\\s*\\d+\\s*[节章条款]").matcher(window); + java.util.regex.Matcher m = java.util.regex.Pattern.compile("第\s*[0-9一二三四五六七八九十]+\s*[节章条款](\s*第\s*[0-9一二三四五六七八九十]+\s*[节章条款]){0,2}").matcher(window); while (m.find()) { - int phraseStart = from + m.start(); // "第"字位置 - int phraseEnd = from + m.end(); // 短语末字(节/章/条/款)之后 - // 切点 cut 落在 (phraseStart, phraseEnd) 内 = 劈在短语内部 - if (cut > phraseStart && cut < phraseEnd) { - return Math.max(phraseStart, cut - 12); // 回退到"第"前 + int phraseStart = from + m.start(); + int phraseEnd = from + m.end(); + if (cut >= phraseStart && cut < phraseEnd) { + return Math.max(phraseStart - 1, cut - 12); // 回退到最外层"第"前, 整串编号翻页 } } return cut;