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

Latest release broken on Obsidian Mobile #99

Open
jloh opened this issue Aug 4, 2023 · 1 comment · May be fixed by #100
Open

Latest release broken on Obsidian Mobile #99

jloh opened this issue Aug 4, 2023 · 1 comment · May be fixed by #100

Comments

@jloh
Copy link

jloh commented Aug 4, 2023

Thanks for MetaEdit! I use it a lot in scripts and other places through QuickAdd and its fantastic.

The latest round of updates to fix the plugin with 1.4.x have unfortunately broken MetaEdit on mobile for me with an error only saying:

right side of assignment cannot be destructed

Any hints on how I can help to debug this at all?

I'm running Obsidian's TestFlight edition on iOS which is according to the about page 1.4.7 (106) API version v.1.3.7.

Reverting back to MetaEdit 1.8.0 fixes the problem for me but this means its broken on desktop.

@xt0rted xt0rted linked a pull request Sep 3, 2023 that will close this issue
@xt0rted
Copy link

xt0rted commented Sep 3, 2023

I ran into this issue after setting up a number of buttons to edit my metadata more easily on mobile. For the time being I patched this in my local version. If you open .obsidian\plugins\metaedit\main.js and search for frontmatterPosition you can try to manually apply the fix in #100 which should look something like this (also has a fix to remove the trailing blank line that's showing up for me):

diff --git a/main.js b/main.js
index 45766ac..731fad5 100644
--- a/main.js
+++ b/main.js
@@ -4407,7 +4407,7 @@ class MetaEditParser {
         if (!frontmatter)
             return [];
         //@ts-ignore - this is part of the new Obsidian API as of v1.4.1
-        const { start, end } = fileCache === null || fileCache === void 0 ? void 0 : fileCache.frontmatterPosition;
+        const { start, end } = fileCache === null || fileCache === void 0 ? void 0 : fileCache.frontmatterPosition ?? fileCache.frontmatter.position;
         const filecontent = await this.app.vault.cachedRead(file);
         const yamlContent = filecontent.split("\n").slice(start.line, end.line).join("\n");
         const parsedYaml = obsidian.parseYaml(yamlContent);
@@ -4927,10 +4927,12 @@ class MetaController {
     async updatePropertyInFile(property, newValue, file) {
         // I'm aware this is hacky. Didn't want to spend a bunch of time rewriting old logic.
         // This uses the new frontmatter API to update the frontmatter. Later TODO: rewrite old logic to just do this & clean.
-        if (property.type === MetaType.YAML) {
-            const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}\n---`;
-            //@ts-ignore
-            const frontmatterPosition = this.app.metadataCache.getFileCache(file).frontmatterPosition;
+        //@ts-ignore
+        const frontmatterPosition = this.app.metadataCache.getFileCache(file).frontmatterPosition;
+
+        if (property.type === MetaType.YAML && frontmatterPosition) {
+            const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}---`;
+
             const fileContents = await this.app.vault.read(file);
             const deleteFrom = frontmatterPosition.start.offset;
             const deleteTo = frontmatterPosition.end.offset;

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 a pull request may close this issue.

2 participants