Skip to content

Commit

Permalink
mathVirtualKeyboard layout fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibastawisi committed Apr 1, 2024
1 parent 99298c1 commit 038fdfd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/editor/nodes/MathNode/MathComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ export default function MathComponent({ initialValue, nodeKey, mathfieldRef: ref
mathfield.smartMode = true;
mathfield.mathModeSpace = "\\,";

mathfield.keybindings = [
...mathfield.keybindings,
{ key: '[Return]', ifMode: 'math', command: 'addRowAfter' },
{ key: '[Enter]', ifMode: 'math', command: 'addRowAfter' },
];
// focus newly created mathfield
if (isSelected && !mathfield.hasFocus()) {
focus(mathfield);
}

mathfield.addEventListener("input", e => {
const event = e as InputEvent;
if (event.inputType === "insertLineBreak") {
event.preventDefault();
mathfield.executeCommand(["performWithFeedback", "addRowAfter"]);
}
mathfield.addEventListener("input", event => {
const value = mathfield.getValue();
editor.update(() => {
if (value === initialValue) return;
Expand Down
27 changes: 15 additions & 12 deletions src/editor/nodes/MathNode/mathVirtualKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use client";

const mathVirtualKeyboardLayout =[ ...window.mathVirtualKeyboard.normalizedLayouts ];
// @ts-expect-error
window.mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[1][6] = {
mathVirtualKeyboardLayout[0].layers[0].rows[1][6] = {
variants: [
{
latex: "\\prod_{#0}^{#0}",
Expand All @@ -18,25 +19,25 @@ window.mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[1][6] = {
class: "big-op hide-shift"
};
// @ts-expect-error
window.mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[3][9].command = ['performWithFeedback', 'addRowAfter'];
mathVirtualKeyboardLayout[0].layers[0].rows[3][9].command = ['performWithFeedback', 'addRowAfter'];
// @ts-expect-error
delete window.mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[3][9].shift;
delete mathVirtualKeyboardLayout[0].layers[0].rows[3][9].shift;
// @ts-expect-error
window.mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[3][8].command = ['performWithFeedback', 'addRowAfter'];
mathVirtualKeyboardLayout[1].layers[0].rows[3][8].command = ['performWithFeedback', 'addRowAfter'];
// @ts-expect-error
delete window.mathVirtualKeyboard.normalizedLayouts[1].layers[0].rows[3][8].shift;
delete mathVirtualKeyboardLayout[1].layers[0].rows[3][8].shift;
// @ts-expect-error
window.mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[3][8].command = ['performWithFeedback', 'addRowAfter'];
mathVirtualKeyboardLayout[2].layers[0].rows[3][8].command = ['performWithFeedback', 'addRowAfter'];
// @ts-expect-error
delete window.mathVirtualKeyboard.normalizedLayouts[2].layers[0].rows[3][8].shift;
delete mathVirtualKeyboardLayout[2].layers[0].rows[3][8].shift;
// @ts-expect-error
window.mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[3][8].command = ['performWithFeedback', 'addRowAfter'];
mathVirtualKeyboardLayout[3].layers[0].rows[3][8].command = ['performWithFeedback', 'addRowAfter'];
// @ts-expect-error
delete window.mathVirtualKeyboard.normalizedLayouts[3].layers[0].rows[3][8].shift;
delete mathVirtualKeyboardLayout[3].layers[0].rows[3][8].shift;
// @ts-expect-error
window.mathVirtualKeyboard.normalizedLayouts[2].layers[0].rows.shift();
mathVirtualKeyboardLayout[2].layers[0].rows.shift();
// @ts-expect-error
mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[2][9].variants = [
mathVirtualKeyboardLayout[0].layers[0].rows[2][9].variants = [
{ latex: '\\exists', aside: 'there is' },
{ latex: '\\nexists', aside: 'there isn’t' },

Expand Down Expand Up @@ -74,7 +75,7 @@ mathVirtualKeyboard.normalizedLayouts[0].layers[0].rows[2][9].variants = [
];

// @ts-expect-error
mathVirtualKeyboard.normalizedLayouts[2].layers[0].rows[3][3].variants = [
mathVirtualKeyboardLayout[2].layers[0].rows[3][3].variants = [
{
latex: '\\char"203A\\ \\char"2039',
insert: '\\ ',
Expand All @@ -96,3 +97,5 @@ mathVirtualKeyboard.normalizedLayouts[2].layers[0].rows[3][3].variants = [
aside: '2 em',
},
];

window.mathVirtualKeyboard.layouts = mathVirtualKeyboardLayout;
10 changes: 8 additions & 2 deletions src/editor/plugins/ToolbarPlugin/Dialogs/Sketch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ function SketchDialog({ editor, node, open }: { editor: LexicalEditor, node: Ima
}
} else {
convertImagetoSketch(src);
excalidrawAPI?.setActiveTool({ type: "freedraw" });
}
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -206,7 +205,14 @@ function SketchDialog({ editor, node, open }: { editor: LexicalEditor, node: Ima
},
]);
setLastSceneVersion(getSceneVersion([imageElement]));
excalidrawAPI?.updateScene({ elements: [imageElement], appState: { theme: theme.palette.mode } });
excalidrawAPI?.updateScene({
elements: [imageElement],
appState: {
activeTool: { type: "freedraw", lastActiveTool: null, customType: null, locked: true },
currentItemStrokeWidth: 0.5,
theme: theme.palette.mode
}
});
}
};
reader.readAsDataURL(blob);
Expand Down

0 comments on commit 038fdfd

Please sign in to comment.