Skip to content

Commit b366f4f

Browse files
committed
refactor(chat): remove unused cursor helpers
1 parent 10caf93 commit b366f4f

2 files changed

Lines changed: 4 additions & 68 deletions

File tree

src/components/chat/ChatMessage.vue

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -443,73 +443,6 @@ const switchToNextBranch = () => {
443443
}
444444
}
445445
446-
// 在HTML末尾添加光标
447-
const addCursorToHtml = (html: string, isReasoning = false) => {
448-
if (!html) return '<span class="input-cursor' + (isReasoning ? ' reasoning-cursor' : '') + '"></span>'
449-
450-
// 创建一个临时的DOM元素来解析HTML
451-
const tempDiv = document.createElement('div')
452-
tempDiv.innerHTML = html
453-
454-
// 找到最后一个元素
455-
const lastElement = findLastElement(tempDiv)
456-
457-
// 如果找到了最后一个元素,添加光标
458-
if (lastElement) {
459-
lastElement.insertAdjacentHTML(
460-
'beforeend',
461-
'<span class="input-cursor' + (isReasoning ? ' reasoning-cursor' : '') + '"></span>'
462-
)
463-
return tempDiv.innerHTML
464-
}
465-
466-
// 如果没有找到元素,直接在末尾添加光标
467-
return html + '<span class="input-cursor' + (isReasoning ? ' reasoning-cursor' : '') + '"></span>'
468-
}
469-
470-
const isLastChildNodeTextOrSpan = (el: HTMLElement): boolean => {
471-
// eslint-disable-next-line no-undef
472-
const lastChild = el.lastChild as ChildNode | null
473-
return (
474-
lastChild?.nodeType === Node.TEXT_NODE ||
475-
(lastChild?.nodeType === Node.ELEMENT_NODE && (lastChild as HTMLElement).tagName === 'SPAN')
476-
)
477-
}
478-
479-
// 递归找到DOM下最后一个元素节点
480-
const findLastElement = (element: HTMLElement): HTMLElement | null => {
481-
// 如果该DOM没有子元素,则返回自身
482-
if (!element.children.length) {
483-
return element
484-
}
485-
486-
const lastChild = element.children[element.children.length - 1] as HTMLElement
487-
488-
if (isLastChildNodeTextOrSpan(lastChild)) {
489-
return lastChild
490-
}
491-
492-
// 如果是pre标签,就在pre标签中找到code元素
493-
if (lastChild.tagName === 'PRE') {
494-
const codeElement = lastChild.getElementsByTagName('code')[0] as HTMLElement | undefined
495-
if (codeElement) {
496-
if (isLastChildNodeTextOrSpan(codeElement)) {
497-
return codeElement
498-
} else {
499-
return findLastElement(codeElement)
500-
}
501-
}
502-
return lastChild
503-
}
504-
505-
// 如果最后一个子元素是元素节点,则递归查找
506-
if (lastChild.nodeType === Node.ELEMENT_NODE && lastChild.children.length > 0) {
507-
return findLastElement(lastChild)
508-
}
509-
510-
return lastChild
511-
}
512-
513446
// 切换参考资料面板
514447
const showReferencesPanel = ref(false)
515448

src/services/response-builder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export class ResponseBuilder {
1111
private phase: Phase = 'preface'
1212
private currentTextIndex: number | null = null
1313

14-
constructor(private readonly update: (message: AssistantMessage) => void, seed: AssistantMessage) {
14+
constructor(
15+
private readonly update: (message: AssistantMessage) => void,
16+
seed: AssistantMessage
17+
) {
1518
this.message = { ...seed, parts: [] }
1619
}
1720

0 commit comments

Comments
 (0)