Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump version to 1.9.9 and optimize performance of cursor movement in LaTeX blocks #398

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-latex-suite",
"version": "1.9.8",
"version": "1.9.9",
"description": "Make typesetting LaTeX math as fast as handwriting through snippets, text expansion, and editor enhancements",
"main": "main.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/editor_extensions/highlight_brackets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export const colorPairedBracketsPlugin = ViewPlugin.fromClass(class {

update(update: ViewUpdate) {
if (update.docChanged || update.viewportChanged) {
this.decorations = colorPairedBrackets(update.view);
// request animation frame to reduce load. Minimal inpact
requestAnimationFrame(() => {
this.decorations = colorPairedBrackets(update.view);
});
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/editor_extensions/math_tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ export const cursorTooltipField = StateField.define<readonly Tooltip[]>({
export function handleMathTooltip(update: ViewUpdate) {
const shouldUpdate = update.docChanged || update.selectionSet;
if (!shouldUpdate) return;

// We don't need to update the tooltip every time the cursor moves.
// Only update when we leaf or enter a LaTeX block. High impact.
if (update.selectionSet && !update.docChanged) {
const oldSel = update.startState.selection.main;
const newSel = update.state.selection.main;

const checkRange = {
from: Math.min(oldSel.from, newSel.from),
to: Math.max(oldSel.to, newSel.to)
};

const text = update.state.sliceDoc(checkRange.from, checkRange.to);
if (!text.includes('$')) {
return;
}
}

const settings = getLatexSuiteConfig(update.state);
const ctx = Context.fromState(update.state);
Expand Down
6 changes: 3 additions & 3 deletions src/features/autofraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { Context } from "src/utils/context";
import { getLatexSuiteConfig } from "src/snippets/codemirror/config";


export const runAutoFraction = (view: EditorView, ctx: Context):boolean => {
export const runAutoFraction = (view: EditorView, ctx: Context): boolean => {

for (const range of ctx.ranges) {
runAutoFractionCursor(view, ctx, range);
}

const success = expandSnippets(view);

if (success) {
if (success) {
autoEnlargeBrackets(view);
}

Expand Down
7 changes: 6 additions & 1 deletion src/latex_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export const handleUpdate = (update: ViewUpdate) => {
}

export const onKeydown = (event: KeyboardEvent, view: EditorView) => {
// Skip full update since the keymove can't trigger anything but can spamm the function a lot.
if (event.key == "ArrowUp" || event.key == "ArrowDown" || event.key == "ArrowLeft" || event.key == "ArrowRight") {
return;
}

const success = handleKeydown(event.key, event.shiftKey, event.ctrlKey || event.metaKey, isComposing(view, event), view);

if (success) event.preventDefault();
Expand Down Expand Up @@ -109,4 +114,4 @@ export const handleKeydown = (key: string, shiftKey: boolean, ctrlKey: boolean,
}

return false;
}
}