@@ -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// 切换参考资料面板
514447const showReferencesPanel = ref (false )
515448
0 commit comments