Liyuan Li 5 éve
szülő
commit
5056f3e69e
4 módosított fájl, 31 hozzáadás és 3 törlés
  1. 1 0
      CHANGELOG.md
  2. 15 2
      src/ts/ir/index.ts
  3. 1 1
      src/ts/ui/initUI.ts
  4. 14 0
      src/ts/wysiwyg/index.ts

+ 1 - 0
CHANGELOG.md

@@ -66,6 +66,7 @@
 
 ### v3.2.4 / 2020-05-xx
 
+* [396](https://github.com/Vanessa219/vditor/issues/396) click empty, append empty block `改进功能`
 * [385](https://github.com/Vanessa219/vditor/issues/385) image title at wysiwyg `修复缺陷`
 * [390](https://github.com/Vanessa219/vditor/issues/390) no data-marker(editing mode) `修复缺陷`
 * [392](https://github.com/Vanessa219/vditor/issues/392) anchor option `改进功能`

+ 15 - 2
src/ts/ir/index.ts

@@ -4,13 +4,14 @@ import {focusEvent, hotkeyEvent, scrollCenter, selectEvent} from "../util/editor
 import {paste} from "../util/fixBrowserBehavior";
 import {hasClosestByClassName} from "../util/hasClosest";
 import {
-    getEditorRange,
+    getEditorRange, setRangeByWbr,
     setSelectionFocus,
 } from "../util/selection";
 import {expandMarker} from "./expandMarker";
 import {highlightToolbar} from "./highlightToolbar";
 import {input} from "./input";
 import {processAfterRender, processHint} from "./process";
+import {Constants} from "../constants";
 
 class IR {
     public element: HTMLPreElement;
@@ -105,8 +106,20 @@ class IR {
                 processAfterRender(vditor);
                 return;
             }
-
             const range = getEditorRange(this.element);
+
+            if (event.target.isEqualNode(this.element)) {
+                if (this.element.lastElementChild.tagName === "P") {
+                    range.selectNodeContents(this.element.lastElementChild);
+                    range.collapse(false);
+                } else {
+                    this.element.insertAdjacentHTML("beforeend",
+                        `<p data-block="0">${Constants.ZWSP}<wbr></p>`);
+                    setRangeByWbr(this.element, range);
+                }
+                return;
+            }
+
             expandMarker(range, vditor);
             highlightToolbar(vditor);
 

+ 1 - 1
src/ts/ui/initUI.ts

@@ -86,7 +86,7 @@ export const initUI = (vditor: IVditor) => {
         toggleOutline(vditor, vditor.toolbar.elements.outline.firstElementChild);
     }
 
-    if (navigator.userAgent.indexOf("iPhone") > -1 && typeof window.visualViewport !== 'undefined') {
+    if (navigator.userAgent.indexOf("iPhone") > -1 && typeof window.visualViewport !== "undefined") {
         // https://github.com/Vanessa219/vditor/issues/379
         let pendingUpdate = false;
         const viewportHandler = (event: Event) => {

+ 14 - 0
src/ts/wysiwyg/index.ts

@@ -1,3 +1,4 @@
+import {Constants} from "../constants";
 import {hidePanel} from "../toolbar/setToolbar";
 import {uploadFiles} from "../upload";
 import {isCtrl, isFirefox} from "../util/compatibility";
@@ -246,6 +247,19 @@ class WYSIWYG {
                 return;
             }
 
+            if (event.target.isEqualNode(this.element)) {
+                const range = getEditorRange(this.element);
+                if (this.element.lastElementChild.tagName === "P") {
+                    range.selectNodeContents(this.element.lastElementChild);
+                    range.collapse(false);
+                } else {
+                    this.element.insertAdjacentHTML("beforeend",
+                        `<p data-block="0">${Constants.ZWSP}<wbr></p>`);
+                    setRangeByWbr(this.element, range);
+                }
+                return;
+            }
+
             highlightToolbar(vditor);
 
             // 点击后光标落于预览区,需展开代码块