Skip to content

Commit

Permalink
Refactor ModalInsertLink and setupInsertLinkMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Postcount CI committed Dec 13, 2023
1 parent ce3e898 commit babf4c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/ModalInsertLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ export class ModalInsertLink extends Modal {
.setName('URL')
.setClass('open-gate--form-field')
.addText((text) =>
text
.setPlaceholder('https://example.com')

.onChange(async (value) => {
gateOptions.url = value
})
text.setPlaceholder('https://example.com').onChange(async (value) => {
gateOptions.url = value
})
)

new Setting(this.contentEl)
Expand Down
6 changes: 4 additions & 2 deletions src/fns/setupInsertLinkMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export const setupInsertLinkMenu = (plugin: Plugin) => {
const createMenu = (app: App, menu: Menu, editor: Editor) => {
menu.addItem((item) => {
item.setTitle('Insert Gate Link').onClick(async () => {
new ModalInsertLink(app, async (gate: GateFrameOption) => {
const modal = new ModalInsertLink(app, async (gate: GateFrameOption) => {
const gateLink = `[${gate.title}](obsidian://opengate?title=${encodeURIComponent(gate.title)}&url=${encodeURIComponent(gate.url)})`
editor.replaceSelection(gateLink)
}).open()
modal.close()
})
modal.open()
})
})
}
Expand Down

0 comments on commit babf4c2

Please sign in to comment.