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

A script that might be of use #7

Closed
fjueic opened this issue Feb 6, 2024 · 6 comments
Closed

A script that might be of use #7

fjueic opened this issue Feb 6, 2024 · 6 comments

Comments

@fjueic
Copy link

fjueic commented Feb 6, 2024

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
@oflisback
Copy link
Owner

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
Copy link
Author

fjueic commented Feb 7, 2024

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
Copy link
Author

fjueic commented Feb 7, 2024

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));

@one2three4f
Copy link

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
Copy link
Author

fjueic commented Feb 16, 2024

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.

@oflisback
Copy link
Owner

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.

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

No branches or pull requests

3 participants