oflisback/obsidian-bridge.nvim

A script that might be of use

fjueic opened this issue · 6 comments

fjueic commented

Script to add scroll with buffer REST api /editor/scroll-into-view without building

Adding to Readme as a possible way might help others. But I would totally understand if you outright reject this idea.

I clone the Original REST api repo manually added the changes from Your fork
used diff to compare both main.js files and created a script to add the changes to the original file.

Why script?

In case of update of the original extension, I can just run the script again to add the changes.

I am still a newbie in neovim, I wonder if there is a way to conditionally add the changes to the original file using obsidian-bridge.nvim plugin.

#!/bin/bash

# This is a really bad way to do it.

echo -n "Enter the path of your Obsidian vault: "
read vault_path

vault_path+="/.obsidian/plugins/obsidian-local-rest-api/main.js"


sed -i 's/this.api.route("\/open\/(.*)").post(this.openPost.bind(this));/this.api.route("\/open\/(.*)").post(this.openPost.bind(this));\n    this.api.route("\/editor\/scroll-into-view").post(this.scrollEditorPositionIntoView.bind(this));/g' $vault_path

sed -i 's/certificateGet(req, res) {/scrollEditorPositionIntoView(req, res) {\n    return __async(this, null, function* () {\n      const { center, range } = req.body;\n      const activeView = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);\n      const editor = activeView.editor;\n      editor.scrollIntoView(range, center);\n      res.json();\n    });\n  }\n  certificateGet(req, res) {/g' $vault_path

Hi @fjueic, I can see how this can be a useful alternative!

Perhaps it could be packaged even nicer if you when you diff direct the output to a patch file (diff file1 file2 > descriptive-name.patch), then you can use patch instead of sed to apply it in your script, I think that would simplify it quite a bit. If that makes sense maybe we can add it as an alternative approach in the README.

fjueic commented

I just learnt about the patch command.
Yes, it makes sense but I still like the idea of copy paste one command.

#!/bin/sh 

echo -n "Enter the path of your Obsidian vault: "
read vault_path

vault_path+="/.obsidian/plugins/obsidian-local-rest-api/main.js"

echo "46992a46993,47001
>   scrollEditorPositionIntoView(req, res) {
>     return __async(this, null, function* () {
>       const { center, range } = req.body;
>       const activeView = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
>       const editor = activeView.editor;
>       editor.scrollIntoView(range, center);
>       res.json();
>     });
>   }
47048a47058
>     this.api.route(\"/editor/scroll-into-view\").post(this.scrollEditorPositionIntoView.bind(this));
" | patch $vault_path
fjueic commented

I still like the idea of copy paste one command.

In case you want the file

46992a46993,47001
>   scrollEditorPositionIntoView(req, res) {
>     return __async(this, null, function* () {
>       const { center, range } = req.body;
>       const activeView = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
>       const editor = activeView.editor;
>       editor.scrollIntoView(range, center);
>       res.json();
>     });
>   }
47048a47058
>     this.api.route("/editor/scroll-into-view").post(this.scrollEditorPositionIntoView.bind(this));

I still like the idea of copy paste one command.

In case you want the file

46992a46993,47001
>   scrollEditorPositionIntoView(req, res) {
>     return __async(this, null, function* () {
>       const { center, range } = req.body;
>       const activeView = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
>       const editor = activeView.editor;
>       editor.scrollIntoView(range, center);
>       res.json();
>     });
>   }
47048a47058
>     this.api.route("/editor/scroll-into-view").post(this.scrollEditorPositionIntoView.bind(this));

thanks for the patch script, its really convenient.

also @oflisback is obsidian_sync not intended to be a two way sync?

for example in obsidian when i use "open weekly note" or open a file, i expect nvim to also open the corresponding file.

fjueic commented

thanks for the patch script, its really convenient.

welcome

is obsidian_sync not intended to be a two way sync?

same in my machine. i think you can somehow use shell command extension. i am still a noob at neovim. can't help with it.

I have added a reference to this issue from the README now as an alternative to building the fork, thanks for suggesting it.

And @one2three4f, no obsidian-bridge is unfortunately one-way communication to control obsidian via network calls, I agree that ideally it would be a two-way sync, please share if you have ideas on how to accomplish it.