Skip to content

Commit

Permalink
FIX laurent22#9950: Link created by LINKIFY in WYSIWYG editor is not …
Browse files Browse the repository at this point in the history
…underlined until switch to another note

The current behavior is such that when adding a link to a note using the WYSIWYG editor, the link is not immediately underlined.
However, if you switch to another note and then return to the note created earlier, the link is underlined as expected.
The expected behavior is that links should be underlined immediately upon insertion, without the need to leave and return to the note.

I found that the problem was that when I pasted the link it was considered as plainText, so I created a function that checks if the pasted
text is a link and added this check to the markdowntags if.
  • Loading branch information
danimnunes committed Mar 25, 2024
1 parent 2097046 commit 9a862e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
editor.insertContent(result.html);
}
} else {
if (BaseItem.isMarkdownTag(pastedText)) { // Paste a link to a note
if (BaseItem.isMarkdownTag(pastedText) || BaseItem.isLink(pastedText)) { // Paste a link to a note
logger.info('onPaste: pasting as a Markdown tag');
const result = await markupToHtml.current(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, pastedText, markupRenderOptions({ bodyOnly: true }));
editor.insertContent(result.html);
Expand Down
6 changes: 6 additions & 0 deletions packages/lib/models/BaseItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,4 +966,10 @@ export default class BaseItem extends BaseModel {
if (!md) return false;
return !!md.match(/^\[.*?\]\(:\/[0-9a-zA-Z]{32}\)$/);
}

public static isLink(text: any) {
if (!text) return false;
const linkRegex = /^https?:\/\/[^)\s]+$/;
return !!text.match(linkRegex);
}
}

0 comments on commit 9a862e6

Please sign in to comment.