浏览代码

style: 长文本高亮改为整段边框包裹(与表格一致)

- 长文本段落:外层div边框包裹整个p/h标签,不再用inline span
- 视觉效果:整个段落被框选,类似表格的包裹方式
何文松 1 周之前
父节点
当前提交
8f07ca571f
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      frontend/vue-demo/src/views/Editor.vue

+ 10 - 3
frontend/vue-demo/src/views/Editor.vue

@@ -881,9 +881,8 @@ function renderBlockHtml(block, shortMap, longMatch, countFn) {
       runsHtml += rs ? `<span style="${rs}">${text}</span>` : text
     }
 
-    // 长文本高亮:整个 block 内容用边框包裹
+    // 长文本高亮:不在 runs 层面处理,在外层 block 包裹
     if (longMatch) {
-      runsHtml = `<span class="elem-highlight elem-highlight-long" data-elem-key="${longMatch.elementKey}" data-value-id="${longMatch.valueId || ''}" style="border:1.5px solid ${darkenColor(longMatch.color)};border-radius:3px;padding:2px 4px;cursor:pointer;display:inline;" contenteditable="true" title="${escapeAttr(longMatch.elementName)}">${runsHtml}</span>`
       countFn(1)
     } else if (shortMap.length > 0 && runsHtml.length > 0) {
       // 短文本高亮:用边框包裹
@@ -902,7 +901,15 @@ function renderBlockHtml(block, shortMap, longMatch, countFn) {
   }
 
   if (!inner) inner = '&nbsp;'
-  return `<${tag} class="${cls}"${styleAttr} data-block-id="${block.id}">${inner}</${tag}>`
+  let blockHtml = `<${tag} class="${cls}"${styleAttr} data-block-id="${block.id}">${inner}</${tag}>`
+
+  // 长文本高亮:用 div 边框包裹整个段落块(类似表格的包裹方式)
+  if (longMatch) {
+    const borderColor = darkenColor(longMatch.color)
+    blockHtml = `<div class="elem-highlight-wrap" data-elem-key="${longMatch.elementKey}" data-value-id="${longMatch.valueId || ''}" title="${escapeAttr(longMatch.elementName)}" style="border:2px solid ${borderColor};border-radius:4px;padding:6px 8px;margin:4px 0;cursor:pointer;">${blockHtml}</div>`
+  }
+
+  return blockHtml
 }
 
 function renderTableHtml(block, longMatch) {