Skip to content

Commit a188559

Browse files
committed
Fixed redo and cursor scrolling
Fixed the issue where I forgot a bracket and redo was being called for every keypress Added scrolling functionality so that the dom scrolls to the mathquill cursor when typing This is very poorly made
1 parent 37abe25 commit a188559

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

editor/js/extension.min.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,26 @@ function inputChange(event) {
520520
inputField.addEventListener("input", inputChange, false); // user input
521521
observeElement(inputField, "value", inputChange); // Mutation observer for value, thank you https://stackoverflow.com/a/61975440
522522

523+
// This is a really dumb way of making our dom scroll to where we're writing
524+
// We are PRAYING that making the span element containing the textArea position:static doesn't break anything
525+
// so that we can use position:absolute on the textArea to move it relative to the document
526+
527+
const mathTextArea = mathField.__controller.textarea[0]
528+
const mathSpan = mathField.__controller.textareaSpan[0]
529+
mathSpan.style.position = 'static'
530+
mathTextArea.style.position = "absolute"
531+
mathFieldElement.addEventListener('click', moveMathTextArea, false)
532+
mathFieldElement.addEventListener('keydown', moveMathTextArea, false)
533+
534+
535+
function moveMathTextArea() {
536+
const cursorElement = mathField.__controller.cursor.jQ[0]
537+
if(cursorElement) {
538+
const newOffset = window.pageYOffset + cursorElement.getBoundingClientRect().top
539+
mathTextArea.style.top = newOffset + "px"
540+
}
541+
}
542+
523543
function catchUndo(event) {
524544
const controlZPressed = event.key === 'z' && (event.ctrlKey || event.metaKey)
525545
const shiftPressed = event.shiftKey;
@@ -544,10 +564,11 @@ function catchSoftwareUndo(event) {
544564
undoInput();
545565
}
546566
if (event.inputType == 'historyRedo') {
547-
if(stateIndex !== historyLength)
548-
event.preventDefault();
567+
if(stateIndex !== historyLength) {
568+
event.preventDefault();
569+
}
570+
redoInput();
549571
}
550-
redoInput();
551572

552573
}
553574

0 commit comments

Comments
 (0)