Skip to content

Commit

Permalink
Select link text after inserting
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-r-m committed Jan 25, 2023
1 parent d5e408a commit 501525e
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 5 deletions.
102 changes: 100 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"devDependencies": {
"@types/node": "^14.0.14",
"@types/codemirror": "^5.60.7",
"chalk": "^4.1.0",
"copy-webpack-plugin": "^6.1.0",
"fs-extra": "^9.0.1",
Expand Down
11 changes: 10 additions & 1 deletion src/QuickLinksPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Editor } from "codemirror";

interface Hint {
text: string;
hint: Function;
Expand Down Expand Up @@ -47,10 +49,17 @@ module.exports = {
const note = notes[i];
const hint: Hint = {
text: note.title,
hint: async (cm, data, completion) => {
hint: async (cm: Editor, data, completion) => {
const from = completion.from || data.from;
from.ch -= 2;
cm.replaceRange(`[${note.title}](:/${note.id})`, from, cm.getCursor(), "complete");
if (response.selectText) {
const selectionStart = Object.assign({}, from);
const selectionEnd = Object.assign({}, from);
selectionStart.ch += 1;
selectionEnd.ch += 1 + note.title.length;
cm.setSelection(selectionStart, selectionEnd)
}
},
};
if (response.showFolders) {
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ joplin.plugins.register({
return {
id: n.id,
title: n.title,
folder: folders[n.parent_id],
folder: folders[n.parent_id]
};
});
return { notes: res, showFolders: showFolders, allowNewNotes: allowNewNotes};
return {
notes: res,
showFolders: showFolders,
allowNewNotes: allowNewNotes,
selectText: selectText
};
}
else if(message.command === 'createNote')
{
Expand Down

0 comments on commit 501525e

Please sign in to comment.