@@ -43,8 +43,16 @@ export default function (editor: Editor, text: string, link: string): PanelConf
43
43
*/
44
44
function insertLink ( text : string , link : string ) : void {
45
45
// fix: 修复列表下无法设置超链接的问题(替换选中文字中的标签)
46
- const subStr = new RegExp ( / ( < \/ * u l > ) | ( < \/ * l i > ) | ( < \/ * o l > ) / 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
+ */
48
56
if ( isActive ( editor ) ) {
49
57
// 选区处于链接中,则选中整个菜单,再执行 insertHTML
50
58
selectLinkElem ( )
@@ -142,20 +150,23 @@ export default function (editor: Editor, text: string, link: string): PanelConf
142
150
let text = $text . val ( ) . trim ( )
143
151
144
152
let html : string = ''
145
- if ( selection && ! selection ?. isCollapsed )
153
+
154
+ if ( selection && ! selection ?. isCollapsed ) {
146
155
html = insertHtml ( selection , topNode ) ?. trim ( )
156
+ }
147
157
148
158
// 去除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
+
151
162
// 当input中的text的长度大于等于选区的文字时
152
163
// 需要判断两者相同的长度的text内容是否相同
153
164
// 相同则只需把多余的部分添加上去即可,否则使用input中的内容
154
165
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 )
157
168
if ( htmlText === startText ) {
158
- text = html + endText
169
+ text = htmlText + endText
159
170
}
160
171
}
161
172
// 链接为空,则不插入
0 commit comments