启用多项功能开关,优化查找方法参数与健壮性

本次提交主要包括:
- 优化查找相关方法(FindBySentence、FindTextInRange),新增 prevOffset 和 findStart 参数,支持从指定偏移量和位置开始查找,提升查找灵活性与准确性(DocumentUtil.cs)
This commit is contained in:
LittleBoy 2025-06-05 23:51:36 +08:00
parent fc3773b65d
commit 16c24c10ec
3 changed files with 14 additions and 10 deletions

Binary file not shown.

View File

@ -13,7 +13,7 @@
/// <summary>
/// 是否启用常识性检测
/// </summary>
public const bool ENABLE_COMMONSENSE_CHECK = false;
public const bool ENABLE_COMMONSENSE_CHECK = true;
/// <summary>
/// 设置功能
/// </summary>
@ -34,9 +34,9 @@
public const bool ENABLE_SAVE_CACHE = true;
public const bool ENABLE_LOAD_CACHE = true;
public const bool ENABLE_CUSTOMER_SERVICE = false;
public const bool ENABLE_UPGRADE = false;
public const bool ENABLE_HELP = false;
public const bool ENABLE_CUSTOMER_SERVICE = true;
public const bool ENABLE_UPGRADE = true;
public const bool ENABLE_HELP = true;
}
}

View File

@ -315,7 +315,7 @@ namespace AIProofread
return bookmark;
}
private static Range FindBySentence(Range paraRange, CorrectContext c, CorrectItem item, Microsoft.Office.Interop.Word.Document document)
private static Range FindBySentence(Range paraRange, CorrectContext c, CorrectItem item, Microsoft.Office.Interop.Word.Document document, int prevOffset)
{
try
{
@ -377,9 +377,9 @@ namespace AIProofread
{
return range1;
}
return null;
// 执行查找
//return FindTextInRange(sentence, item.Origin);
return FindTextInRange(sentence, item.Origin,prevOffset);
}
catch (Exception e)
{
@ -389,10 +389,14 @@ namespace AIProofread
return null;
}
public static Range FindTextInRange(Range range, string searchText)
public static Range FindTextInRange(Range range, string searchText,int prevOffset, int findStart = -1)
{
try
{
if (findStart > 0)
{
range.Start = range.Start + findStart;
}
Find find = range.Find;
if (range.Comments.Count > 0)
{
@ -422,7 +426,7 @@ namespace AIProofread
//var offset = paraStart + c.SentenceOffset;
////var cutLength = Math.Min(c.InsertLen, paraText.Length - offset);
var originFindRange = FindBySentence(paraRange, c, item, document);
var originFindRange = FindBySentence(paraRange, c, item, document, prevOffset);
if (originFindRange != null) return originFindRange;
// 如果是新增 则查找定位
@ -491,7 +495,7 @@ namespace AIProofread
if (range.Text == item.Origin) { return range; }
}
// 使用find查找
var r = FindTextInRange(paraRange, item.Origin);
var r = FindTextInRange(paraRange, item.Origin, prevOffset);
if (r != null)
{
// 判断找到的range是否和查找区域误差过大