diff --git a/libs/squire-raw.mjs b/libs/squire-raw.mjs index 827fe4a2bcdb..fecf8c3a6688 100644 --- a/libs/squire-raw.mjs +++ b/libs/squire-raw.mjs @@ -451,13 +451,14 @@ var fixCursor = (node) => { fixer = document.createTextNode(""); } } - } else if (node instanceof Element && !node.querySelector("BR")) { + } else if ((node instanceof Element || node instanceof DocumentFragment) && !node.querySelector("BR")) { fixer = createElement("BR"); let parent = node; let child; while ((child = parent.lastElementChild) && !isInline(child)) { parent = child; } + node = parent; } if (fixer) { try { @@ -1313,6 +1314,7 @@ var insertTreeFragmentIntoRange = (range, frag, root, config) => { } if (blockContentsAfterSplit && block) { const tempRange = range.cloneRange(); + fixCursor(blockContentsAfterSplit); mergeWithBlock(block, blockContentsAfterSplit, tempRange, root); range.setEnd(tempRange.endContainer, tempRange.endOffset); } @@ -1864,10 +1866,13 @@ var Space = (self, event, range) => { const text = block.textContent?.trimEnd().replace(ZWS, ""); if (text === "*" || text === "1.") { event.preventDefault(); + self.insertPlainText(" ", false); + self._docWasChanged(); + self.saveUndoState(range); const walker = new TreeIterator(block, SHOW_TEXT); let textNode; while (textNode = walker.nextNode()) { - textNode.data = cantFocusEmptyTextNodes ? ZWS : ""; + detach(textNode); } if (text === "*") { self.makeUnorderedList(); @@ -1900,41 +1905,12 @@ var Space = (self, event, range) => { }; // source/keyboard/KeyHandlers.ts -var keys = { - 8: "Backspace", - 9: "Tab", - 13: "Enter", - 27: "Escape", - 32: "Space", - 33: "PageUp", - 34: "PageDown", - 37: "ArrowLeft", - 38: "ArrowUp", - 39: "ArrowRight", - 40: "ArrowDown", - 46: "Delete", - 191: "/", - 219: "[", - 220: "\\", - 221: "]" -}; var _onKey = function (event) { - const code = event.keyCode; - let key = keys[code]; - let modifiers = ""; - const range = this.getSelection(); - if (event.defaultPrevented) { + if (event.defaultPrevented || event.isComposing) { return; } - if (!key) { - key = String.fromCharCode(code).toLowerCase(); - if (!/^[A-Za-z0-9]$/.test(key)) { - key = ""; - } - } - if (111 < code && code < 124) { - key = "F" + (code - 111); - } + let key = event.key; + let modifiers = ""; if (key !== "Backspace" && key !== "Delete") { if (event.altKey) { modifiers += "Alt-"; @@ -1953,11 +1929,10 @@ var _onKey = function (event) { modifiers += "Shift-"; } key = modifiers + key; + const range = this.getSelection(); if (this._keyHandlers[key]) { this._keyHandlers[key](this, event, range); - } else if (!range.collapsed && // !event.isComposing stops us from blatting Kana-Kanji conversion in - // Safari - !event.isComposing && !event.ctrlKey && !event.metaKey && (event.key || key).length === 1) { + } else if (!range.collapsed && !event.ctrlKey && !event.metaKey && key.length === 1) { this.saveUndoState(range); deleteContentsOfRange(range, this._root); this._ensureBottomLine(); @@ -1970,7 +1945,7 @@ var keyHandlers = { "Delete": Delete, "Tab": Tab, "Shift-Tab": ShiftTab, - "Space": Space, + " ": Space, "ArrowLeft"(self) { self._removeZWS(); }, @@ -2742,22 +2717,26 @@ var Squire = class { * Leaves bookmark. */ _recordUndoState(range, replace) { - if (!this._isInUndoState || replace) { - let undoIndex = this._undoIndex; + const isInUndoState = this._isInUndoState; + if (!isInUndoState || replace) { + let undoIndex = this._undoIndex + 1; const undoStack = this._undoStack; const undoConfig = this._config.undo; const undoThreshold = undoConfig.documentSizeThreshold; const undoLimit = undoConfig.undoLimit; - if (!replace) { - undoIndex += 1; - } if (undoIndex < this._undoStackLength) { undoStack.length = this._undoStackLength = undoIndex; } if (range) { this._saveRangeToBookmark(range); } + if (isInUndoState) { + return this; + } const html = this._getRawHTML(); + if (replace) { + undoIndex -= 1; + } if (undoThreshold > -1 && html.length * 2 > undoThreshold) { if (undoLimit > -1 && undoIndex > undoLimit) { undoStack.splice(0, undoIndex - undoLimit); @@ -2925,6 +2904,7 @@ var Squire = class { let doInsert = true; if (isPaste) { const event = new CustomEvent("willPaste", { + cancelable: true, detail: { fragment: frag } @@ -3028,6 +3008,7 @@ var Squire = class { let doInsert = true; if (isPaste) { const event = new CustomEvent("willPaste", { + cancelable: true, detail: { text: plainText } diff --git a/package-lock.json b/package-lock.json index 8b969c588bea..ef593126b9c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,7 +38,7 @@ "mithril": "2.2.2", "pako": "2.1.0", "qrcode-svg": "1.0.0", - "squire-rte": "2.2.5", + "squire-rte": "2.2.7", "systemjs": "6.10.2", "undici": "6.6.2", "winreg": "1.2.4" @@ -9800,9 +9800,9 @@ "devOptional": true }, "node_modules/squire-rte": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/squire-rte/-/squire-rte-2.2.5.tgz", - "integrity": "sha512-qxG8CdH9haEufK5Nn7KcoixJb5UwEtmqMiFZ5+VLUpNrvSVm0PLIkoiLKS5Z0A2/w8pWvKHSTI2Gsijg9xl4Og==" + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/squire-rte/-/squire-rte-2.2.7.tgz", + "integrity": "sha512-BUMRrqnckM+hV3lwjajcckViS1aKgYFImA3Sjctygsln7f7DXILsYj7SOEdgJgNkTDGMBVkKIkTs0v0wOj2VrQ==" }, "node_modules/ssri": { "version": "10.0.5", diff --git a/package.json b/package.json index daa454deca47..a9c0600ec39c 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "luxon": "3.4.4", "mithril": "2.2.2", "qrcode-svg": "1.0.0", - "squire-rte": "2.2.5", + "squire-rte": "2.2.7", "systemjs": "6.10.2", "undici": "6.6.2", "winreg": "1.2.4",