Skip to content

Commit 2d060d5

Browse files
committed
fix: delete text will delete img too
1 parent bac1b1e commit 2d060d5

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

src/config/menus.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,19 @@ export default {
182182
// type -> 'emoji' / 'image'
183183
type: 'emoji',
184184
// content -> 数组
185-
content:
186-
'😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇 🙂 🙃 😉 😌 😍 😘 😗 😙 😚 😋 😛 😝 😜 🤓 😎 😏 😒 😞 😔 😟 😕 🙁 😣 😖 😫 😩 😢 😭 😤 😠 😡 😳 😱 😨 🤗 🤔 😶 😑 😬 🙄 😯 😴 😷 🤑 😈 🤡 💩 👻 💀 👀 👣'.split(
187-
/\s/
188-
),
185+
content: '😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇 🙂 🙃 😉 😌 😍 😘 😗 😙 😚 😋 😛 😝 😜 🤓 😎 😏 😒 😞 😔 😟 😕 🙁 😣 😖 😫 😩 😢 😭 😤 😠 😡 😳 😱 😨 🤗 🤔 😶 😑 😬 🙄 😯 😴 😷 🤑 😈 🤡 💩 👻 💀 👀 👣'.split(
186+
/\s/
187+
),
189188
},
190189
{
191190
// tab 的标题
192191
title: '手势',
193192
// type -> 'emoji' / 'image'
194193
type: 'emoji',
195194
// content -> 数组
196-
content:
197-
'👐 🙌 👏 🤝 👍 👎 👊 ✊ 🤛 🤜 🤞 ✌️ 🤘 👌 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐 🖖 👋 🤙 💪 🖕 ✍️ 🙏'.split(
198-
/\s/
199-
),
195+
content: '👐 🙌 👏 🤝 👍 👎 👊 ✊ 🤛 🤜 🤞 ✌️ 🤘 👌 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐 🖖 👋 🤙 💪 🖕 ✍️ 🙏'.split(
196+
/\s/
197+
),
200198
},
201199
],
202200

src/lib/simplehtmlparser.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ SimpleHtmlParser.prototype = {
6161

6262
// regexps
6363

64-
startTagRe:
65-
/^<([^>\s\/]+)((\s+[^=>\s]+(\s*=\s*((\"[^"]*\")|(\'[^']*\')|[^>\s]+))?)*)\s*\/?\s*>/m,
64+
startTagRe: /^<([^>\s\/]+)((\s+[^=>\s]+(\s*=\s*((\"[^"]*\")|(\'[^']*\')|[^>\s]+))?)*)\s*\/?\s*>/m,
6665
endTagRe: /^<\/([^>\s]+)[^>]*>/m,
6766
attrRe: /([^=\s]+)(\s*=\s*((\"([^"]*)\")|(\'([^']*)\')|[^>\s]+))?/gm,
6867

src/menus/img/bind-event/keyboard-event.ts

+8
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,13 @@ export default function bindEventKeyboardEvent(editor: Editor) {
5151
lastChildNodeInPrevNode =
5252
lastChildNodeInPrevNode.childNodes[lastChildNodeInPrevNode.childNodes.length - 1]
5353
}
54+
55+
if (
56+
lastChildNodeInPrevNode instanceof HTMLElement &&
57+
lastChildNodeInPrevNode.tagName === 'IMG'
58+
) {
59+
lastChildNodeInPrevNode.remove()
60+
e.preventDefault()
61+
}
5462
})
5563
}

src/menus/lineHeight/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class LineHeight extends DropListMenu implements MenuActive {
6969
//获取range 开头结束的dom
7070
const StartElem: DomElement = $(editor.selection.getSelectionStartElem())
7171
const EndElem: DomElement = $(editor.selection.getSelectionEndElem())
72-
const childList: NodeListOf<ChildNode> | undefined =
73-
editor.selection.getRange()?.commonAncestorContainer.childNodes
72+
const childList: NodeListOf<ChildNode> | undefined = editor.selection.getRange()
73+
?.commonAncestorContainer.childNodes
7474
arrayDom_a.push(this.getDom(StartElem.elems[0]))
7575
childList?.forEach((item, index) => {
7676
if (item === this.getDom(StartElem.elems[0])) {

src/text/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ class Text {
343343
// 键盘 down 时的 hooks
344344
$textElem.on('keydown', (e: KeyboardEvent) => {
345345
const keydownEvents = eventHooks.keydownEvents
346-
setTimeout(() => {
347-
keydownEvents.forEach(fn => fn(e))
348-
})
346+
keydownEvents.forEach(fn => fn(e))
349347
})
350348

351349
// delete 键 up 时 hooks

src/utils/const.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
export function EMPTY_FN() {}
77

88
//用于校验是否为url格式字符串
9-
export const urlRegex =
10-
/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-.,@?^=%&amp;:/~+#]*[\w\-@?^=%&amp;/~+#])?/
9+
export const urlRegex = /^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-.,@?^=%&amp;:/~+#]*[\w\-@?^=%&amp;/~+#])?/
1110

1211
// 编辑器为了方便继续输入/换行等原因 主动生成的空标签
1312
export const EMPTY_P = '<p data-we-empty-p=""><br></p>'

0 commit comments

Comments
 (0)