启用多项功能开关,优化查找方法参数与健壮性
本次提交主要包括: - 优化查找相关方法(FindBySentence、FindTextInRange),新增 prevOffset 和 findStart 参数,支持从指定偏移量和位置开始查找,提升查找灵活性与准确性(DocumentUtil.cs)
This commit is contained in:
parent
fc3773b65d
commit
16c24c10ec
Binary file not shown.
@ -13,7 +13,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用常识性检测
|
/// 是否启用常识性检测
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const bool ENABLE_COMMONSENSE_CHECK = false;
|
public const bool ENABLE_COMMONSENSE_CHECK = true;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置功能
|
/// 设置功能
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,9 +34,9 @@
|
|||||||
|
|
||||||
public const bool ENABLE_SAVE_CACHE = true;
|
public const bool ENABLE_SAVE_CACHE = true;
|
||||||
public const bool ENABLE_LOAD_CACHE = true;
|
public const bool ENABLE_LOAD_CACHE = true;
|
||||||
public const bool ENABLE_CUSTOMER_SERVICE = false;
|
public const bool ENABLE_CUSTOMER_SERVICE = true;
|
||||||
public const bool ENABLE_UPGRADE = false;
|
public const bool ENABLE_UPGRADE = true;
|
||||||
public const bool ENABLE_HELP = false;
|
public const bool ENABLE_HELP = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ namespace AIProofread
|
|||||||
return bookmark;
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -377,9 +377,9 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
return range1;
|
return range1;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
// 执行查找
|
// 执行查找
|
||||||
//return FindTextInRange(sentence, item.Origin);
|
return FindTextInRange(sentence, item.Origin,prevOffset);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -389,10 +389,14 @@ namespace AIProofread
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Range FindTextInRange(Range range, string searchText)
|
public static Range FindTextInRange(Range range, string searchText,int prevOffset, int findStart = -1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (findStart > 0)
|
||||||
|
{
|
||||||
|
range.Start = range.Start + findStart;
|
||||||
|
}
|
||||||
Find find = range.Find;
|
Find find = range.Find;
|
||||||
if (range.Comments.Count > 0)
|
if (range.Comments.Count > 0)
|
||||||
{
|
{
|
||||||
@ -422,7 +426,7 @@ namespace AIProofread
|
|||||||
//var offset = paraStart + c.SentenceOffset;
|
//var offset = paraStart + c.SentenceOffset;
|
||||||
////var cutLength = Math.Min(c.InsertLen, paraText.Length - offset);
|
////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;
|
if (originFindRange != null) return originFindRange;
|
||||||
|
|
||||||
// 如果是新增 则查找定位
|
// 如果是新增 则查找定位
|
||||||
@ -491,7 +495,7 @@ namespace AIProofread
|
|||||||
if (range.Text == item.Origin) { return range; }
|
if (range.Text == item.Origin) { return range; }
|
||||||
}
|
}
|
||||||
// 使用find查找
|
// 使用find查找
|
||||||
var r = FindTextInRange(paraRange, item.Origin);
|
var r = FindTextInRange(paraRange, item.Origin, prevOffset);
|
||||||
if (r != null)
|
if (r != null)
|
||||||
{
|
{
|
||||||
// 判断找到的range是否和查找区域误差过大
|
// 判断找到的range是否和查找区域误差过大
|
||||||
|
Loading…
x
Reference in New Issue
Block a user