Skip to content

Commit

Permalink
fix: delete text will delete img too
Browse files Browse the repository at this point in the history
  • Loading branch information
guqianfeng committed Dec 19, 2021
1 parent bac1b1e commit 2d060d5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
14 changes: 6 additions & 8 deletions src/config/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,19 @@ export default {
// type -> 'emoji' / 'image'
type: 'emoji',
// content -> 数组
content:
'😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇 🙂 🙃 😉 😌 😍 😘 😗 😙 😚 😋 😛 😝 😜 🤓 😎 😏 😒 😞 😔 😟 😕 🙁 😣 😖 😫 😩 😢 😭 😤 😠 😡 😳 😱 😨 🤗 🤔 😶 😑 😬 🙄 😯 😴 😷 🤑 😈 🤡 💩 👻 💀 👀 👣'.split(
/\s/
),
content: '😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇 🙂 🙃 😉 😌 😍 😘 😗 😙 😚 😋 😛 😝 😜 🤓 😎 😏 😒 😞 😔 😟 😕 🙁 😣 😖 😫 😩 😢 😭 😤 😠 😡 😳 😱 😨 🤗 🤔 😶 😑 😬 🙄 😯 😴 😷 🤑 😈 🤡 💩 👻 💀 👀 👣'.split(
/\s/
),
},
{
// tab 的标题
title: '手势',
// type -> 'emoji' / 'image'
type: 'emoji',
// content -> 数组
content:
'👐 🙌 👏 🤝 👍 👎 👊 ✊ 🤛 🤜 🤞 ✌️ 🤘 👌 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐 🖖 👋 🤙 💪 🖕 ✍️ 🙏'.split(
/\s/
),
content: '👐 🙌 👏 🤝 👍 👎 👊 ✊ 🤛 🤜 🤞 ✌️ 🤘 👌 👈 👉 👆 👇 ☝️ ✋ 🤚 🖐 🖖 👋 🤙 💪 🖕 ✍️ 🙏'.split(
/\s/
),
},
],

Expand Down
3 changes: 1 addition & 2 deletions src/lib/simplehtmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ SimpleHtmlParser.prototype = {

// regexps

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

Expand Down
8 changes: 8 additions & 0 deletions src/menus/img/bind-event/keyboard-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@ export default function bindEventKeyboardEvent(editor: Editor) {
lastChildNodeInPrevNode =
lastChildNodeInPrevNode.childNodes[lastChildNodeInPrevNode.childNodes.length - 1]
}

if (
lastChildNodeInPrevNode instanceof HTMLElement &&
lastChildNodeInPrevNode.tagName === 'IMG'
) {
lastChildNodeInPrevNode.remove()
e.preventDefault()
}
})
}
4 changes: 2 additions & 2 deletions src/menus/lineHeight/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class LineHeight extends DropListMenu implements MenuActive {
//获取range 开头结束的dom
const StartElem: DomElement = $(editor.selection.getSelectionStartElem())
const EndElem: DomElement = $(editor.selection.getSelectionEndElem())
const childList: NodeListOf<ChildNode> | undefined =
editor.selection.getRange()?.commonAncestorContainer.childNodes
const childList: NodeListOf<ChildNode> | undefined = editor.selection.getRange()
?.commonAncestorContainer.childNodes
arrayDom_a.push(this.getDom(StartElem.elems[0]))
childList?.forEach((item, index) => {
if (item === this.getDom(StartElem.elems[0])) {
Expand Down
4 changes: 1 addition & 3 deletions src/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ class Text {
// 键盘 down 时的 hooks
$textElem.on('keydown', (e: KeyboardEvent) => {
const keydownEvents = eventHooks.keydownEvents
setTimeout(() => {
keydownEvents.forEach(fn => fn(e))
})
keydownEvents.forEach(fn => fn(e))
})

// delete 键 up 时 hooks
Expand Down
3 changes: 1 addition & 2 deletions src/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
export function EMPTY_FN() {}

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

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

0 comments on commit 2d060d5

Please sign in to comment.