Skip to content

Commit fcaef96

Browse files
committed
fix: 插入链接后再修改的问题
1 parent feac0af commit fcaef96

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/menus/link/create-panel-conf.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ export default function (editor: Editor, text: string, link: string): PanelConf
4343
*/
4444
function insertLink(text: string, link: string): void {
4545
// fix: 修复列表下无法设置超链接的问题(替换选中文字中的标签)
46-
const subStr = new RegExp(/(<\/*ul>)|(<\/*li>)|(<\/*ol>)/g)
47-
text = text.replace(subStr, '')
46+
47+
// const TagRegExp = new RegExp(/(<\/?ul>)|(<\/?li>)|(<\/?ol>)/g)
48+
49+
// const resultText = text.replace(TagRegExp, '')
50+
51+
/**
52+
* fix: 插入链接后再修改链接地址问题,会导致页面链接有问题
53+
*
54+
* 同上,列表无法插入链接的原因,是因为在insertLink, 处理text时有问题。
55+
*/
4856
if (isActive(editor)) {
4957
// 选区处于链接中,则选中整个菜单,再执行 insertHTML
5058
selectLinkElem()
@@ -142,20 +150,23 @@ export default function (editor: Editor, text: string, link: string): PanelConf
142150
let text = $text.val().trim()
143151

144152
let html: string = ''
145-
if (selection && !selection?.isCollapsed)
153+
154+
if (selection && !selection?.isCollapsed) {
146155
html = insertHtml(selection, topNode)?.trim()
156+
}
147157

148158
// 去除html的tag标签
149-
let htmlText = html?.replace(/<.*?>/g, '')
150-
let htmlTextLen = htmlText?.length ?? 0
159+
const htmlText = html?.replace(/<.*?>/g, '')
160+
const htmlTextLen = htmlText?.length ?? 0
161+
151162
// 当input中的text的长度大于等于选区的文字时
152163
// 需要判断两者相同的长度的text内容是否相同
153164
// 相同则只需把多余的部分添加上去即可,否则使用input中的内容
154165
if (htmlTextLen <= text.length) {
155-
let startText = text.substring(0, htmlTextLen)
156-
let endText = text.substring(htmlTextLen)
166+
const startText = text.substring(0, htmlTextLen)
167+
const endText = text.substring(htmlTextLen)
157168
if (htmlText === startText) {
158-
text = html + endText
169+
text = htmlText + endText
159170
}
160171
}
161172
// 链接为空,则不插入

0 commit comments

Comments
 (0)