From e7a4f6a4f75e5bf4119f186d8d8a8c9a52dfac5d Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 4 Aug 2022 13:04:25 +0800 Subject: [PATCH] :bug: fix https://github.com/Vanessa219/vditor/issues/1263 --- CHANGELOG.md | 1 + src/ts/ir/input.ts | 7 +++++++ src/ts/wysiwyg/index.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1b6de197..c0ff549f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,7 @@ ### v3.8.16 / 2022-08 +* [1263](https://github.com/Vanessa219/vditor/issues/1263) 所见即所得和即使渲染只有空格输入时,不会触发 input 事件 `修复缺陷` * [1264](https://github.com/Vanessa219/vditor/issues/1264) 链接中,会强制将®解析为 ® 字符 `修复缺陷` * [1242](https://github.com/Vanessa219/vditor/issues/1242) 在即时渲染模式下表格源文件未对齐 `改进功能` diff --git a/src/ts/ir/input.ts b/src/ts/ir/input.ts index 865aba9fe..99713b2d9 100644 --- a/src/ts/ir/input.ts +++ b/src/ts/ir/input.ts @@ -11,6 +11,7 @@ import {processCodeRender} from "../util/processCode"; import {getSelectPosition, setRangeByWbr} from "../util/selection"; import {renderToc} from "../util/toc"; import {processAfterRender} from "./process"; +import {getMarkdown} from "../markdown/getMarkdown"; export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event?: InputEvent) => { let blockElement = hasClosestBlock(range.startContainer); @@ -51,6 +52,9 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event? } if (startSpace) { + if (typeof vditor.options.input === "function") { + vditor.options.input(getMarkdown(vditor)); + } return; } if (endSpace) { @@ -63,6 +67,9 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event? // FireFox https://github.com/Vanessa219/vditor/issues/239 previousNode.classList.remove("vditor-ir__node--expand"); } + if (typeof vditor.options.input === "function") { + vditor.options.input(getMarkdown(vditor)); + } return; } } diff --git a/src/ts/wysiwyg/index.ts b/src/ts/wysiwyg/index.ts index 2c3888446..9bab93ce7 100644 --- a/src/ts/wysiwyg/index.ts +++ b/src/ts/wysiwyg/index.ts @@ -28,6 +28,7 @@ import {genImagePopover, genLinkRefPopover, highlightToolbarWYSIWYG} from "./hig import {getRenderElementNextNode, modifyPre} from "./inlineTag"; import {input} from "./input"; import {showCode} from "./showCode"; +import {getMarkdown} from "../markdown/getMarkdown"; class WYSIWYG { public range: Range; @@ -389,6 +390,9 @@ class WYSIWYG { if ((startSpace && blockElement.getAttribute("data-type") !== "code-block") || endSpace || isHeadingMD(blockElement.innerHTML) || (isHrMD(blockElement.innerHTML) && blockElement.previousElementSibling)) { + if (typeof vditor.options.input === "function") { + vditor.options.input(getMarkdown(vditor)); + } return; }