From 180ee019e70d5bae5990f3a4b6f1073fb3ae7ff5 Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Sat, 4 Apr 2020 22:31:33 +0800 Subject: [PATCH] :bug: fix #266 --- CHANGELOG.md | 8 ++++---- src/ts/ir/index.ts | 10 ++++++---- src/ts/sv/html2md.ts | 4 ++-- src/ts/util/fixBrowserBehavior.ts | 6 +++--- src/ts/wysiwyg/index.ts | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0538cb377..04a84fae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,14 +49,14 @@ * [open issues](https://github.com/Vanessa219/vditor/issues) -### v3.0.10 / 2020-04-0x +### v3.0.11 / 2020-04-0x +### v3.0.10 / 2020-04-04 + +* [266](https://github.com/Vanessa219/vditor/issues/266) linkToImgUrl 图片重复上传 `修复缺陷` * [208](https://github.com/Vanessa219/vditor/issues/208) hr in Firefox `修复缺陷` * [274](https://github.com/Vanessa219/vditor/issues/274) Toc demo at Preview `文档相关` * [269](https://github.com/Vanessa219/vditor/issues/269) 分屏预览支持 list-style-type CSS `引入特性` - -### v3.0.9 / 2020-04-04 - * [265](https://github.com/Vanessa219/vditor/issues/265) ir 模式中 toc, 链接引用,脚注 `引入特性` * [271](https://github.com/Vanessa219/vditor/issues/271) options.toolbar支持自定义绑定class `引入特性` * [267](https://github.com/Vanessa219/vditor/issues/267) 设置 codeBlockPreview false, esc 后代码块消失 `修复缺陷` diff --git a/src/ts/ir/index.ts b/src/ts/ir/index.ts index edc8df408..e85292cae 100644 --- a/src/ts/ir/index.ts +++ b/src/ts/ir/index.ts @@ -119,26 +119,28 @@ class IR { setHeaders(vditor, xhr); xhr.onreadystatechange = () => { if (xhr.readyState === XMLHttpRequest.DONE) { - const responseJSON = JSON.parse(xhr.responseText); if (xhr.status === 200) { + const responseJSON = JSON.parse(xhr.responseText); if (responseJSON.code !== 0) { vditor.tip.show(responseJSON.msg); return; } - // TODO const original = responseJSON.data.originalURL; const imgElement: HTMLImageElement = this.element.querySelector(`img[src="${original}"]`); imgElement.src = responseJSON.data.url; + imgElement.previousElementSibling.previousElementSibling.innerHTML = + responseJSON.data.url; processAfterRender(vditor); } else { - vditor.tip.show(responseJSON.msg); + vditor.tip.show(xhr.responseText); } } }; xhr.send(JSON.stringify({url: src})); } - return ["", Lute.WalkStop]; + return [`${src}`, + Lute.WalkStop]; }, }, }, diff --git a/src/ts/sv/html2md.ts b/src/ts/sv/html2md.ts index 6a079b4a2..fda0adc77 100644 --- a/src/ts/sv/html2md.ts +++ b/src/ts/sv/html2md.ts @@ -31,8 +31,8 @@ export const html2md = (vditor: IVditor, textHTML: string, textPlain?: string) = setHeaders(vditor, xhr); xhr.onreadystatechange = () => { if (xhr.readyState === XMLHttpRequest.DONE) { - const responseJSON = JSON.parse(xhr.responseText); if (xhr.status === 200) { + const responseJSON = JSON.parse(xhr.responseText); if (responseJSON.code !== 0) { vditor.tip.show(responseJSON.msg); return; @@ -41,7 +41,7 @@ export const html2md = (vditor: IVditor, textHTML: string, textPlain?: string) = setSelectionByInlineText(original, vditor.sv.element.childNodes); insertText(vditor, responseJSON.data.url, "", true); } else { - vditor.tip.show(responseJSON.msg); + vditor.tip.show(xhr.responseText); } } }; diff --git a/src/ts/util/fixBrowserBehavior.ts b/src/ts/util/fixBrowserBehavior.ts index 9b6a367ac..d58b67f6b 100644 --- a/src/ts/util/fixBrowserBehavior.ts +++ b/src/ts/util/fixBrowserBehavior.ts @@ -940,8 +940,8 @@ export const fixTask = (vditor: IVditor, range: Range, event: KeyboardEvent) => export const fixDelete = (vditor: IVditor, range: Range, event: KeyboardEvent, pElement: HTMLElement | false) => { if (range.startContainer.nodeType !== 3) { // 光标位于 hr 前,hr 前有内容 - const rangeElement = (range.startContainer as HTMLElement).children[range.startOffset] - if (rangeElement && rangeElement.tagName === 'HR') { + const rangeElement = (range.startContainer as HTMLElement).children[range.startOffset]; + if (rangeElement && rangeElement.tagName === "HR") { range.selectNodeContents(rangeElement.previousElementSibling); range.collapse(false); event.preventDefault(); @@ -977,4 +977,4 @@ export const fixHR = (range: Range) => { (range.startContainer as HTMLElement).tagName === "HR") { range.setStartBefore(range.startContainer); } -} +}; diff --git a/src/ts/wysiwyg/index.ts b/src/ts/wysiwyg/index.ts index 36bede50c..86a742bbc 100644 --- a/src/ts/wysiwyg/index.ts +++ b/src/ts/wysiwyg/index.ts @@ -184,8 +184,8 @@ class WYSIWYG { setHeaders(vditor, xhr); xhr.onreadystatechange = () => { if (xhr.readyState === XMLHttpRequest.DONE) { - const responseJSON = JSON.parse(xhr.responseText); if (xhr.status === 200) { + const responseJSON = JSON.parse(xhr.responseText); if (responseJSON.code !== 0) { vditor.tip.show(responseJSON.msg); return; @@ -196,7 +196,7 @@ class WYSIWYG { imgElement.src = responseJSON.data.url; afterRenderEvent(vditor); } else { - vditor.tip.show(responseJSON.msg); + vditor.tip.show(xhr.responseText); } } };