Skip to content

Commit 9da8dbc

Browse files
committed
fix: prevent serious corruption due to mathception
No idea what causes the corruption, but preventing the issue that triggers it, we can avoid it. This needs further investigation.
1 parent 45fa455 commit 9da8dbc

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/components/Document.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default function Document({
104104
instance: window.internal.ui.activeFilesystemInstance,
105105
id: window.internal.ui.activeLocation,
106106
write: {
107-
name: event.target.innerText,
107+
name: event.target.innerText.trim(),
108108
type: 0
109109
}
110110
}

src/math-editor/editor.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,22 @@ class Editor {
251251
event.preventDefault()
252252
if (this.activeMathElement !== null) return // No math inside math
253253
const mathElement = Math.create()
254-
Utils.insertNodeAt(Utils.getCaretPosition(), mathElement.container)
254+
255+
// If we are inside a math element, insert the new math after it
256+
const selection = document.getSelection()
257+
if (selection.anchorNode.nodeName.toLowerCase() === "math") {
258+
// Should only occur when math is only element in line
259+
// So this is OK
260+
this.activeLine.appendChild(mathElement.container)
261+
262+
// Check for BR elements inside activeLine and remove them
263+
// They appear between elements and we don't want them
264+
for (const element of this.activeLine.childNodes) {
265+
if (element.nodeName.toLowerCase() === "br") element.remove()
266+
}
267+
} else {
268+
Utils.insertNodeAt(Utils.getCaretPosition(), mathElement.container)
269+
}
255270
Math.open(mathElement.id)
256271
return
257272
}

0 commit comments

Comments
 (0)