From c546fe21efbb741caa069c75425368c174feb70a Mon Sep 17 00:00:00 2001 From: callmeyan Date: Fri, 24 Jan 2025 10:37:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E6=B3=A8=E5=AF=BC=E8=87=B4=E6=A0=A1?= =?UTF-8?q?=E5=AF=B9=E4=BA=A7=E7=94=9F=E7=99=BE=E5=88=86=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIProofread/Bridge.cs | 7 ++- AIProofread/Config.cs | 6 +-- AIProofread/Model/DocumentInfo.cs | 7 +++ AIProofread/ProofreadItem.cs | 29 +++++++++- AIProofread/core/DocumentUtil.cs | 88 +++++++++++++++++++++---------- 5 files changed, 103 insertions(+), 34 deletions(-) diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index 139a61a..2035f31 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -336,9 +336,14 @@ namespace AIProofread data.Add("code", 3); data.Add("message", "文档受保护,无法编辑"); } + else if (doc.ReadOnly) + { + data.Add("code", 4); + data.Add("message", "文档无法编辑,请另存后再进行校对"); + } else { - Thread.Sleep(500); + // 判断文档是否是只读模式 //FormMessage loadingDialog = null; //// 大于15W字符无法校对 //Task.Run(() => diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs index bce0925..7470762 100644 --- a/AIProofread/Config.cs +++ b/AIProofread/Config.cs @@ -12,7 +12,7 @@ namespace AIProofread public class Config { public static readonly string APP_NAME = "AI校对王"; - public static readonly string APP_VERSION = "2.1.0"; + public static readonly string APP_VERSION = "2.1.1"; public static bool IS_WPS = false; public static bool UpgradeForcedNotice = false; public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory; @@ -25,11 +25,11 @@ namespace AIProofread /// /// 网页访问地址 /// - public static string WEB_PATH = "http://gm2-plugin.zverse.group/"; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group + public static string WEB_PATH = "http://localhost:5173/"; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group public static bool RUN_IN_DEBUG = true; public static AppEnvironment APP_ENV = AppEnvironment.Dev; #else - public static string WEB_PATH = "https://pre-gm-plugin.gachafun.com/"; // gm-plugin.gachafun.com + public static string WEB_PATH = "https://gm-plugin.gachafun.com/"; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com public static bool RUN_IN_DEBUG = false; public static AppEnvironment APP_ENV = AppEnvironment.Prod; #endif diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs index ec9f9fc..6e48a42 100644 --- a/AIProofread/Model/DocumentInfo.cs +++ b/AIProofread/Model/DocumentInfo.cs @@ -813,11 +813,18 @@ namespace AIProofread.Model return Convert.ToBase64String(bytes); } + /// + /// 采纳校对项 + /// + /// + /// internal void ProcessMark(int proofreadId, int status) { + // 是否存在书签 if (proofreadId > 0 && marks.ContainsKey(proofreadId)) { hasProcessMark = true; + // 采纳 marks[proofreadId].Process(status); } } diff --git a/AIProofread/ProofreadItem.cs b/AIProofread/ProofreadItem.cs index 6fab6ac..59fb6c3 100644 --- a/AIProofread/ProofreadItem.cs +++ b/AIProofread/ProofreadItem.cs @@ -135,12 +135,17 @@ namespace UtilLib } } + /// + /// 处理校对项 + /// + /// public void Process(int status) { if (mark == null) return; // content.IsAccept = status; + // 采纳 if (status == AcceptStatus.Accept) { if (content.Tag == "r" || content.Tag == "i") @@ -152,7 +157,7 @@ namespace UtilLib mark.Text = ""; } ResetMarkStyle(); - } + } // 复核 或者 忽略 else if (status == AcceptStatus.Review || status == AcceptStatus.Ignore) { ResetMarkStyle(); @@ -162,6 +167,7 @@ namespace UtilLib mark.Text = ""; } } + // 撤销处理 else if (status == AcceptStatus.Default) { // 撤销 @@ -175,6 +181,27 @@ namespace UtilLib } SetMarkStyle(); } + // 处理由于批注导致出现百分号 + AfterMarkTextChanged(mark); + } + + private void AfterMarkTextChanged(Bookmark mark) + { + // 获取标签所在段落最后的位置 + var paragraphEnd = mark.Paragraphs.Last.Range.End; + var end = mark.End + 2 > paragraphEnd ? paragraphEnd : mark.End + 2; + var rng = Globals.ThisAddIn.ActiveDocument.Range(mark.End, end); + + // 判断书签范围内是否有批注 + + if (rng.Text?.IndexOf("%") != -1 && rng.Comments != null && rng.Comments.Count > 0) + { + for (var i = 1; i < rng.Comments.Count; i++) + { + var comment = rng.Comments[i]; + comment.Scope.Text = comment.Scope.Text.Replace("%", ""); + } + } } } } diff --git a/AIProofread/core/DocumentUtil.cs b/AIProofread/core/DocumentUtil.cs index 2c55761..85102ab 100644 --- a/AIProofread/core/DocumentUtil.cs +++ b/AIProofread/core/DocumentUtil.cs @@ -401,40 +401,41 @@ namespace AIProofread { return document.Range(offset + item.Start, offset + item.Start); } - int count = 0; - while (true && count++ < 10) + //int count = 0; + var range = document.Range(offset + item.Start, offset + item.End + 1); + //while (true && count++ < 10) + //{ + // // + // try + // { + // if (range.Text == null && range.Comments.Count > 0) + // { + // // 删除批注 + // foreach (Comment comment in range.Comments) + // { + // comment.Delete(); + // } + // continue; + // } + // else + // { + // break; + // } + // } + // catch (Exception dce) + // { + // Logger.Log(dce); + // } + //} + // 比对原始内容与校对原文是否一致 + if (range.Text == item.Origin) { - var range = document.Range(offset + item.Start, offset + item.End + 1); - // - try - { - if (range.Text == null && range.Comments.Count > 0) - { - // 删除批注 - foreach (Comment comment in range.Comments) - { - comment.Delete(); - } - continue; - } - else - { - break; - } - } - catch (Exception dce) - { - Logger.Log(dce); - } - // 比对原始内容与校对原文是否一致 - if (range.Text == item.Origin) - { - return range; - } + return range; } } // 直接找 var range1 = document.Range(offset + item.Start, offset + item.End + 1); + // 兼容空格的全角与半角 if(item.Origin == " " && (range1.Text == " " || range1.Text == " " || range1.Text.Trim().Length == 0)) { return range1; @@ -444,6 +445,8 @@ namespace AIProofread { return range1; } + // 执行查找 + return FindTextInRange(sentence, item.Origin); } catch (Exception) { @@ -452,6 +455,26 @@ namespace AIProofread return null; } + public static Range FindTextInRange(Range range, string searchText) + { + try + { + Find find = range.Find; + if (range.Comments.Count > 0) + { + // 当前区域有批注 执行忽略模式 + find.MatchPhrase = true; + } + // 设置查找条件 + find.Text = searchText; + find.Forward = true; + find.Wrap = WdFindWrap.wdFindContinue; + find.Execute(); + if (find.Found) return range; + } catch (Exception) { } + return null; + } + private static Range FindRangeByCorrect(CorrectContext c, CorrectItem item, Paragraph paragraph, Microsoft.Office.Interop.Word.Document document, int prevOffset) { @@ -532,6 +555,13 @@ namespace AIProofread } if (range.Text == item.Origin) { return range; } } + // 使用find查找 + var r = FindTextInRange(paraRange, item.Origin); + if (r != null) + { + // 判断找到的range是否和查找区域误差过大 + return r; + } // 直接定位查找 start = paraText.IndexOf(item.Origin, prevOffset); if (start == -1) return null;