批注导致校对产生百分号

This commit is contained in:
LittleBoy 2025-01-24 10:37:53 +08:00
parent 90fc77b258
commit c546fe21ef
5 changed files with 103 additions and 34 deletions

View File

@ -336,9 +336,14 @@ namespace AIProofread
data.Add("code", 3); data.Add("code", 3);
data.Add("message", "文档受保护,无法编辑"); data.Add("message", "文档受保护,无法编辑");
} }
else if (doc.ReadOnly)
{
data.Add("code", 4);
data.Add("message", "文档无法编辑,请另存后再进行校对");
}
else else
{ {
Thread.Sleep(500); // 判断文档是否是只读模式
//FormMessage loadingDialog = null; //FormMessage loadingDialog = null;
//// 大于15W字符无法校对 //// 大于15W字符无法校对
//Task.Run(() => //Task.Run(() =>

View File

@ -12,7 +12,7 @@ namespace AIProofread
public class Config public class Config
{ {
public static readonly string APP_NAME = "AI校对王"; 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 IS_WPS = false;
public static bool UpgradeForcedNotice = false; public static bool UpgradeForcedNotice = false;
public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory; public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory;
@ -25,11 +25,11 @@ namespace AIProofread
/// <summary> /// <summary>
/// 网页访问地址 /// 网页访问地址
/// </summary> /// </summary>
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 bool RUN_IN_DEBUG = true;
public static AppEnvironment APP_ENV = AppEnvironment.Dev; public static AppEnvironment APP_ENV = AppEnvironment.Dev;
#else #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 bool RUN_IN_DEBUG = false;
public static AppEnvironment APP_ENV = AppEnvironment.Prod; public static AppEnvironment APP_ENV = AppEnvironment.Prod;
#endif #endif

View File

@ -813,11 +813,18 @@ namespace AIProofread.Model
return Convert.ToBase64String(bytes); return Convert.ToBase64String(bytes);
} }
/// <summary>
/// 采纳校对项
/// </summary>
/// <param name="proofreadId"></param>
/// <param name="status"></param>
internal void ProcessMark(int proofreadId, int status) internal void ProcessMark(int proofreadId, int status)
{ {
// 是否存在书签
if (proofreadId > 0 && marks.ContainsKey(proofreadId)) if (proofreadId > 0 && marks.ContainsKey(proofreadId))
{ {
hasProcessMark = true; hasProcessMark = true;
// 采纳
marks[proofreadId].Process(status); marks[proofreadId].Process(status);
} }
} }

View File

@ -135,12 +135,17 @@ namespace UtilLib
} }
} }
/// <summary>
/// 处理校对项
/// </summary>
/// <param name="status"></param>
public void Process(int status) public void Process(int status)
{ {
if (mark == null) return; if (mark == null) return;
// //
content.IsAccept = status; content.IsAccept = status;
// 采纳
if (status == AcceptStatus.Accept) if (status == AcceptStatus.Accept)
{ {
if (content.Tag == "r" || content.Tag == "i") if (content.Tag == "r" || content.Tag == "i")
@ -152,7 +157,7 @@ namespace UtilLib
mark.Text = ""; mark.Text = "";
} }
ResetMarkStyle(); ResetMarkStyle();
} } // 复核 或者 忽略
else if (status == AcceptStatus.Review || status == AcceptStatus.Ignore) else if (status == AcceptStatus.Review || status == AcceptStatus.Ignore)
{ {
ResetMarkStyle(); ResetMarkStyle();
@ -162,6 +167,7 @@ namespace UtilLib
mark.Text = ""; mark.Text = "";
} }
} }
// 撤销处理
else if (status == AcceptStatus.Default) else if (status == AcceptStatus.Default)
{ {
// 撤销 // 撤销
@ -175,6 +181,27 @@ namespace UtilLib
} }
SetMarkStyle(); 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("%", "");
}
}
} }
} }
} }

View File

@ -401,40 +401,41 @@ namespace AIProofread
{ {
return document.Range(offset + item.Start, offset + item.Start); return document.Range(offset + item.Start, offset + item.Start);
} }
int count = 0; //int count = 0;
while (true && count++ < 10) 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); return range;
//
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;
}
} }
} }
// 直接找 // 直接找
var range1 = document.Range(offset + item.Start, offset + item.End + 1); var range1 = document.Range(offset + item.Start, offset + item.End + 1);
// 兼容空格的全角与半角
if(item.Origin == " " && (range1.Text == " " || range1.Text == " " || range1.Text.Trim().Length == 0)) if(item.Origin == " " && (range1.Text == " " || range1.Text == " " || range1.Text.Trim().Length == 0))
{ {
return range1; return range1;
@ -444,6 +445,8 @@ namespace AIProofread
{ {
return range1; return range1;
} }
// 执行查找
return FindTextInRange(sentence, item.Origin);
} }
catch (Exception) catch (Exception)
{ {
@ -452,6 +455,26 @@ namespace AIProofread
return null; 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) 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; } 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); start = paraText.IndexOf(item.Origin, prevOffset);
if (start == -1) return null; if (start == -1) return null;