-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,92 @@ | ||
import joplin from 'api'; | ||
import { MenuItemLocation, ToolbarButtonLocation } from 'api/types'; | ||
|
||
|
||
function escapeTitleText(text: string) { | ||
return text.replace(/(\[|\])/g, '\\$1'); | ||
} | ||
|
||
joplin.plugins.register({ | ||
onStart: async function() { | ||
console.info('Test plugin started!'); | ||
}, | ||
onStart: async function () { | ||
await joplin.commands.register({ | ||
name: 'goToItemViaText', | ||
label: 'Go to note via highlighted text', | ||
iconName: 'fas fa-anchor', | ||
execute: async () => { | ||
//Get selected text | ||
const selectedText = (await joplin.commands.execute('selectedText') as string); | ||
|
||
try { | ||
let first = selectedText.substr(0,1); | ||
if(first == "#"){ | ||
let tagId ='' | ||
let page = 1 | ||
let tags | ||
console.info(tags); | ||
let has_more = true | ||
while(has_more){ | ||
tags = await joplin.data.get(['tags'], {page:page}); | ||
tags.items.forEach(element => { | ||
console.log(element) | ||
if (element.title==selectedText.substr(1)){ | ||
console.log('open '+element.id) | ||
tagId = element.id | ||
} | ||
}); | ||
if(tags.has_more) {page=page+1} else {has_more=false} | ||
|
||
} | ||
|
||
|
||
await joplin.commands.execute('openTag',tagId); | ||
|
||
|
||
} | ||
else if(first =="@"){ | ||
let folderId ='' | ||
let page = 1 | ||
let folders | ||
|
||
let has_more = true | ||
while(has_more){ | ||
folders = await joplin.data.get(['folders'], {page:page}); | ||
folders.items.forEach(element => { | ||
console.log(element) | ||
if (element.title==selectedText.substr(1)){ | ||
console.log('open '+element.id) | ||
folderId = element.id | ||
} | ||
}); | ||
if(folders.has_more) {page=page+1} else {has_more=false} | ||
|
||
} | ||
|
||
console.info(folders); | ||
await joplin.commands.execute('openFolder',folderId); | ||
|
||
|
||
} | ||
else{ | ||
await joplin.commands.execute('openNote',selectedText); | ||
} | ||
|
||
} | ||
catch(err) | ||
{ | ||
console.log(err) | ||
let dialog = await joplin.views.dialogs.create('wrongText') | ||
await joplin.views.dialogs.setHtml(dialog, "Seems like text is not an exact id,tag or folder<br>Or other error occured"); | ||
await joplin.views.dialogs.setButtons(dialog,[{id:"ok"}]); | ||
await joplin.views.dialogs.open(dialog); | ||
} | ||
|
||
|
||
} | ||
}) | ||
await joplin.views.menuItems.create('goToViaTextMenuItem', 'goToItemViaText', MenuItemLocation.EditorContextMenu); | ||
await joplin.views.toolbarButtons.create('Go to item via text', 'goToItemViaText',ToolbarButtonLocation.EditorToolbar); | ||
|
||
} | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"manifest_version": 1, | ||
"id": "com.ambrth.GoToItemViaText", | ||
"app_min_version": "1.4", | ||
"id": "goToItemViaTextPlugin", | ||
"app_min_version": "1.4.19", | ||
"version": "1.0.0", | ||
"name": "Go To Item Via Text", | ||
"description": "Goes to item (#tag, @notebook, noteId) highlighted in text editor and goes to it.", | ||
"name": "Go to via text", | ||
"description": "Goes to tag, notebook or note via highlighted text", | ||
"author": "a", | ||
"homepage_url": "" | ||
"homepage_url": "a" | ||
} |