diff --git a/src/components/Document.jsx b/src/components/Document.jsx index 1545e1a..8ed04a0 100644 --- a/src/components/Document.jsx +++ b/src/components/Document.jsx @@ -104,7 +104,7 @@ export default function Document({ instance: window.internal.ui.activeFilesystemInstance, id: window.internal.ui.activeLocation, write: { - name: event.target.innerText, + name: event.target.innerText.trim(), type: 0 } } diff --git a/src/math-editor/editor.js b/src/math-editor/editor.js index 46d26bd..2432f0a 100644 --- a/src/math-editor/editor.js +++ b/src/math-editor/editor.js @@ -251,7 +251,22 @@ class Editor { event.preventDefault() if (this.activeMathElement !== null) return // No math inside math const mathElement = Math.create() - Utils.insertNodeAt(Utils.getCaretPosition(), mathElement.container) + + // If we are inside a math element, insert the new math after it + const selection = document.getSelection() + if (selection.anchorNode.nodeName.toLowerCase() === "math") { + // Should only occur when math is only element in line + // So this is OK + this.activeLine.appendChild(mathElement.container) + + // Check for BR elements inside activeLine and remove them + // They appear between elements and we don't want them + for (const element of this.activeLine.childNodes) { + if (element.nodeName.toLowerCase() === "br") element.remove() + } + } else { + Utils.insertNodeAt(Utils.getCaretPosition(), mathElement.container) + } Math.open(mathElement.id) return }