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

Fix Live Preview & Canvas #65

Merged
merged 2 commits into from Nov 24, 2023
Merged

Fix Live Preview & Canvas #65

merged 2 commits into from Nov 24, 2023

Conversation

RyotaUshio
Copy link
Collaborator

@RyotaUshio RyotaUshio commented Nov 24, 2023

This PR contains live preview and canvas-related fixes.

Misc

  • General
    • Added a lot of comments.
  • utils.ts
    • The returned value of isExcluded is now flipped because the previous version actually checked if the given file is included or not, which was confusing (I know where it came from: isValid).
    • isEqualToOrChildOf: now it doesn't iterate over ancestor folders, and instead, it uses a simple string operation.
  • provider.ts
    • Fixed: Provider.provide() should return either string (meaning the provider wants to provide a display text to the given link) or null (i.e. do nothing), but NativeProvider returned undefined when a note doesn't have a mathLink property.

Live Preview

I rewrote the editor extension in 0.4.7 (#53), and basically, the main points of the update were

  1. create the extension only from a MathLinks plugin instance without using WorkspaceLeaf: avoid creating a new extension for every active-leaf-change
  2. Avoid re-creation of Decoration as much as possible in every update

And the approach that I took to realize the second point (which was taken from Dataview) turned out to be too conservative and sometimes failed to update the decoration even if it should have (sorry...).

For example, add three backticks ``` above a link. The decoration for the link should be removed, but it remains.

So I decided to basically revert to the implementation of 0.4.6, as well as keeping good updates introduced in 0.4.7 as much as possible. For example, it still creates a single view plugin from a MathLinks plugin instance without depending WorkspaceLeaf.

And importantly, the new implementation still successfully avoids unnecessary decoration re-rendering; it turned out that avoiding redundant re-rendering of decoration DOMs is as simple as just implementing the MathWidget.eq method.

eq(other: MathWidget) {
// Needed to avoid redundant toDOM calls
return this.outLinkText === other.outLinkText && this.outLinkMathLink === other.outLinkMathLink && this.isSourceMode == other.isSourceMode && this.sourcePath === other.sourcePath;
}

Also, I noticed that the previous version didn't respect the excluded files setting, so I also fixed this.

Canvas

Although the previous version successfully displayed MathLinks in canvas cards that are embeds of existing notes (i.e. "add note from vault" cards), it failed for non-embed cards (i.e. "add card" cards).

In this case, we need special care because

  • in reading view: context.sourcePath is ""
  • in live preview: state.field(editorInfoField).file is null

This PR fixes this problem. The details are listed below:

  • main.ts > registerMarkdownProcessor:
    • In order to display MathLinks in a non-embed canvas card as well, markdown post-processing is now executed in file === null case. (Also note that isExcluded's output is flipped)
  • preview.ts > tryBuildDecorations:
  • test_vault/Canvas.canvas
    • Added a non-embed card.

I've already tested it in the test vault, and it's working well. So I'm going to merge this pull request and release it as 0.5.3.

Thanks!

…les not respected in live preview; Fix mathlinks not displayed in a canvas card that is not associated with any note
@RyotaUshio RyotaUshio merged commit d9d4651 into master Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant