Skip to content

Commit

Permalink
Merge pull request #205 from mgreminger/cell-move-bug-fix
Browse files Browse the repository at this point in the history
fix: cell move inlineShortcuts bug
  • Loading branch information
mgreminger authored Aug 25, 2023
2 parents 77e9f4c + 414cdc6 commit 48ccbae
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/MathField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { MathField } from "./cells/MathField";
import type { MathfieldElement } from "mathlive";
import { INLINE_SHORTCUTS } from "./constants";
export let latex = "";
export let mathField: MathField | null = null;
Expand Down Expand Up @@ -42,19 +43,7 @@
mathLiveField.mathVirtualKeyboardPolicy = "manual";
mathLiveField.inlineShortcutTimeout = 0;
mathLiveField.smartSuperscript = false;
mathLiveField.inlineShortcuts = {
'*': '\\cdot',
'@': '\\times',
'<=': '\\le',
'>=': '\\ge',
'~': '\\approx',
'sqrt': '\\sqrt{#?}',
'$int': '\\int _{#?}^{#?}\\left(#?\\right)\\mathrm{d}\\left(#?\\right)',
'$prime': '\\frac{\\mathrm{d}}{\\mathrm{d}\\left(#?\\right)}\\left(#?\\right)',
'$doubleprime': '\\frac{\\mathrm{d}^{2}}{\\mathrm{d}\\left(#?\\right)^{2}}\\left(#?\\right)',
'$tripleprime': '\\frac{\\mathrm{d}^{3}}{\\mathrm{d}\\left(#?\\right)^{3}}\\left(#?\\right)',
'log_': '\\log_{#?}(#?)',
};
mathLiveField.inlineShortcuts = INLINE_SHORTCUTS;
mathLiveField.keybindings = mathLiveField.keybindings
.filter((value) => value.key !== '[Paste]' &&
Expand Down Expand Up @@ -151,6 +140,11 @@
}
// workaround needed for move cell inlineShortcuts bug
$: if (editable && mathLiveField && mathLiveField.inlineShortcuts) {
mathLiveField.inlineShortcuts = INLINE_SHORTCUTS;
}
$: if (!editable && mathLiveField ) {
mathLiveField.value = latex;
}
Expand Down
13 changes: 13 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const INLINE_SHORTCUTS = {
'*': '\\cdot',
'@': '\\times',
'<=': '\\le',
'>=': '\\ge',
'~': '\\approx',
'sqrt': '\\sqrt{#?}',
'$int': '\\int _{#?}^{#?}\\left(#?\\right)\\mathrm{d}\\left(#?\\right)',
'$prime': '\\frac{\\mathrm{d}}{\\mathrm{d}\\left(#?\\right)}\\left(#?\\right)',
'$doubleprime': '\\frac{\\mathrm{d}^{2}}{\\mathrm{d}\\left(#?\\right)^{2}}\\left(#?\\right)',
'$tripleprime': '\\frac{\\mathrm{d}^{3}}{\\mathrm{d}\\left(#?\\right)^{3}}\\left(#?\\right)',
'log_': '\\log_{#?}(#?)',
};
16 changes: 16 additions & 0 deletions tests/test_basic.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,4 +1466,20 @@ test('Negative grouping with fractions with negative denominator', async () => {

content = await page.textContent('#result-value-3');
expect(content).toBe('b');
});

test('Test cell move inlineShortcuts bug', async () => {

await page.locator('#add-math-cell').click();

await page.locator('#up-1').click();

await page.locator('#cell-0 >> math-field.editable').type('1[mm]=[mm]');

await page.waitForSelector('.status-footer', { state: 'detached'});

let content = await page.textContent('#result-value-0');
expect(parseLatexFloat(content)).toBeCloseTo(1, precision);
content = await page.textContent('#result-units-0');
expect(content).toBe('mm');
});

0 comments on commit 48ccbae

Please sign in to comment.