Skip to content

Commit

Permalink
Refactor searchPublicApi.js to handle selected text as title if avail…
Browse files Browse the repository at this point in the history
…able.
  • Loading branch information
Claudio-Emmolo committed Jan 2, 2024
1 parent 37e2d7e commit 36f6c41
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/searchPublicApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,18 @@ function addArticleLinkOnEditor () {
form.addEventListener('submit', (e) => {
e.preventDefault()
const formDataArticle = new FormData(form)
const title = formDataArticle.get('title')

let title = formDataArticle.get('title')
const url = formDataArticle.get('url')

const selectedText = tinymce.activeEditor.selection.getContent()

if (selectedText.length > 0) {
title = selectedText
}

const content = `<a href="${url}" target="_blank">${title}</a>`

tinymce.activeEditor.insertContent(content)
tinymce.activeEditor.windowManager.close()
})
Expand Down

0 comments on commit 36f6c41

Please sign in to comment.