Commit 3f8118b0 authored by Kantz's avatar Kantz
Browse files

button verstekcn wenn Formel bearbeitet werden

parent 4f3bf68d
import { useEffect, useRef } from "react"; import { useEffect, useRef, useState } from "react";
import { EditPencil, Send, Upload } from "iconoir-react"; import { EditPencil, Send, Upload } from "iconoir-react";
import { t } from "../../i18n"; import { t } from "../../i18n";
import "mathquill/build/mathquill.css"; import "mathquill/build/mathquill.css";
...@@ -255,6 +255,7 @@ export default function MessageInput({ ...@@ -255,6 +255,7 @@ export default function MessageInput({
const sendButtonStartedFromEditorRef = useRef(false); const sendButtonStartedFromEditorRef = useRef(false);
const currentValueRef = useRef(value); const currentValueRef = useRef(value);
const mqRef = useRef<MathQuillInterface | null>(null); const mqRef = useRef<MathQuillInterface | null>(null);
const [isMathBoxActive, setIsMathBoxActive] = useState(false);
const syncEditorToValue = async (nextValue: string) => { const syncEditorToValue = async (nextValue: string) => {
const editor = editorRef.current; const editor = editorRef.current;
...@@ -313,6 +314,7 @@ export default function MessageInput({ ...@@ -313,6 +314,7 @@ export default function MessageInput({
fieldElement.replaceWith(rendered); fieldElement.replaceWith(rendered);
activeMathFields.delete(fieldElement); activeMathFields.delete(fieldElement);
field.revert(); field.revert();
setIsMathBoxActive(false);
commitEditorValue(); commitEditorValue();
return rendered; return rendered;
}; };
...@@ -338,6 +340,9 @@ export default function MessageInput({ ...@@ -338,6 +340,9 @@ export default function MessageInput({
element.dataset.empty = latex ? "false" : "true"; element.dataset.empty = latex ? "false" : "true";
const root = field.el(); const root = field.el();
root.addEventListener("focusin", () => {
setIsMathBoxActive(true);
});
root.addEventListener("keydown", (event) => { root.addEventListener("keydown", (event) => {
if (event.key !== "Enter") { if (event.key !== "Enter") {
return; return;
...@@ -353,6 +358,7 @@ export default function MessageInput({ ...@@ -353,6 +358,7 @@ export default function MessageInput({
if (root.contains(document.activeElement)) { if (root.contains(document.activeElement)) {
return; return;
} }
setIsMathBoxActive(false);
finalizeMathField(); finalizeMathField();
}); });
}); });
...@@ -508,18 +514,20 @@ export default function MessageInput({ ...@@ -508,18 +514,20 @@ export default function MessageInput({
{t("revealSolution")} {t("revealSolution")}
</button> </button>
) : null} ) : null}
<button {!isMathBoxActive ? (
className="btn btn-formula" <button
type="button" className="btn btn-formula"
onClick={() => { type="button"
void insertMathFieldAtCaret(); onClick={() => {
}} void insertMathFieldAtCaret();
disabled={isSending} }}
aria-label={t("formula")} disabled={isSending}
title={t("formula")} aria-label={t("formula")}
> title={t("formula")}
f (x) >
</button> f (x)
</button>
) : null}
<button <button
className="btn primary" className="btn primary"
type="button" type="button"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment