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

Add obsidian-view-mode-by-frontmatter to plugin list #411

Merged
merged 3 commits into from Aug 24, 2021

Conversation

bwydoogh
Copy link
Contributor

@bwydoogh bwydoogh commented Aug 8, 2021

I am submitting a new Community Plugin

Repo URL

Link to my plugin: https://github.com/bwydoogh/obsidian-force-view-mode-of-note

Release Checklist

  • I have tested this on macOS
  • My GitHub release contains all required files
    • main.js
    • manifest.json
    • styles.css (optional)
  • GitHub release name matches the exact version number specified in my manifest.json (Note: Use the exact version number, don't include a prefix v)
  • The id in my manifest.json matches the id in the community-plugins.json file.
  • README clearly describes the plugins purpose and provides clear usage instructions.
  • I have added a license in the LICENSE file.

@lishid
Copy link
Collaborator

@lishid lishid commented Aug 12, 2021

https://github.com/bwydoogh/obsidian-force-view-mode-of-note/blob/7235398a9a47adb6eb847aa87700f3761dffb4d6/main.ts#L4
Maybe use something more friendly, not with underscores?

https://github.com/bwydoogh/obsidian-force-view-mode-of-note/blob/7235398a9a47adb6eb847aa87700f3761dffb4d6/main.ts#L8
Should use MarkdownView here instead of TextFileView.

https://github.com/bwydoogh/obsidian-force-view-mode-of-note/blob/7235398a9a47adb6eb847aa87700f3761dffb4d6/main.ts#L14

To get the mode, you should use getMode(). To set the mode, you should use:

let state = leaf.getViewState();
state.state.mode = 'preview'; // or 'source'
leaf.setViewState(state);

@bwydoogh
Copy link
Contributor Author

@bwydoogh bwydoogh commented Aug 12, 2021

@lishid Thank you for your review. Have addressed these comments; hopefully OK for you.

@lishid lishid merged commit ca1504a into obsidianmd:master Aug 24, 2021
1 check passed
@lishid
Copy link
Collaborator

@lishid lishid commented Aug 24, 2021

I'd still suggest using view.getMode() to check for the mode, and only use leaf.getViewState when you need to set the mode. getViewState could be a somewhat expensive call.

@bwydoogh
Copy link
Contributor Author

@bwydoogh bwydoogh commented Aug 25, 2021

I'd still suggest using view.getMode() to check for the mode, and only use leaf.getViewState when you need to set the mode. getViewState could be a somewhat expensive call.

Implemented your suggestion; thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants