Skip to content

Commit

Permalink
fix: prevent serious corruption due to mathception
Browse files Browse the repository at this point in the history
No idea what causes the corruption, but preventing the issue that triggers it, we can avoid it.

This needs further investigation.
  • Loading branch information
Esinko committed Aug 23, 2024
1 parent 45fa455 commit 9da8dbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Document.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/math-editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9da8dbc

Please sign in to comment.