Skip to content

Commit 44f7ad4

Browse files
committed
refactor: Update SearchableMarkdown component to use startIndex for match highlighting, improving accuracy in search result navigation
1 parent 84c638b commit 44f7ad4

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/renderer/src/components/common/markdown/SearchableMarkdown.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,13 @@ const SearchableMarkdown: React.FC<SearchableMarkdownProps> = ({
101101
let currentMatchIndexInMessage = -1
102102
if (currentMatch?.messageId === messageId && allMatches.length > 0) {
103103
// 这个消息包含当前匹配
104-
// 使用matchIndex(消息内的索引)来确定高亮哪个
105-
const targetMatchIndex = currentMatch.matchIndex || 0
104+
// 使用startIndex来找到对应的匹配项
105+
const matchIndex = allMatches.findIndex(m => m.globalStart === currentMatch.startIndex)
106106

107-
// 确保索引在有效范围内
108-
if (targetMatchIndex < allMatches.length) {
109-
currentMatchIndexInMessage = targetMatchIndex
107+
if (matchIndex !== -1) {
108+
currentMatchIndexInMessage = matchIndex
110109
} else {
111-
// 如果索引超出范围,高亮第一个
110+
// 如果找不到精确匹配,高亮第一个
112111
currentMatchIndexInMessage = 0
113112
}
114113
}

0 commit comments

Comments
 (0)