Skip to content

Commit

Permalink
Changed callback to checkCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
agathauy committed Nov 18, 2020
1 parent 2f7912e commit fa41e40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ https://github.com/obsidianmd/obsidian-sample-plugin
https://github.com/obsidianmd/obsidian-api

# Version History
## 0.0.5
- Updated for callback check

## 0.0.4
- Updated markdown link regex

Expand Down
17 changes: 11 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ export default class WikilinksToMdlinks extends Plugin {
this.addCommand({
id: "toggle-wiki-md-links",
name: "Toggle selected wikilink to markdown link and vice versa",
callback: () => this.toggleLink(),
checkCallback: () => {
const currentView = this.app.workspace.getActiveLeafOfViewType(MarkdownView)
const editor = currentView.sourceMode.cmEditor

if (!(editor.hasFocus)) {
return
}

return this.toggleLink()
},
hotkeys: [{
modifiers: ["Mod", "Shift"],
key: "="
Expand All @@ -19,17 +28,13 @@ export default class WikilinksToMdlinks extends Plugin {
}

onunload() {
console.log('unloading wikilinks-to-md plugin')
console.log('unloading wikilinks-to-mdlinks plugin')
}

toggleLink() {
const currentView = this.app.workspace.getActiveLeafOfViewType(MarkdownView)
const editor = currentView.sourceMode.cmEditor

if (!(editor.hasFocus)) {
return
}

const cursor = editor.getCursor()
const line = editor.getDoc().getLine(cursor.line);

Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "wikilinks-to-mdlinks",
"id": "wikilinks-to-mdlinks-obsidian",
"name": "Wikilinks to MDLinks",
"version": "0.0.4",
"version": "0.0.5",
"minAppVersion": "0.9.12",
"description": "A plugin that converts wikilinks to markdown links and vice versa",
"author": "Agatha Uy",
Expand Down

0 comments on commit fa41e40

Please sign in to comment.