From 9e90510b433a69afbec52c6fc55bf06d50c0f980 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 9 Dec 2020 14:32:14 +0100 Subject: [PATCH] Fixed HTML link copy pasting --- ChangeLog.md | 1 + .../ChannelConversationManager.ts | 4 +-- shared/js/ui/react-elements/ChatBox.tsx | 27 ++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c7ce7b2e..e46cbd86 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,7 @@ - Fixed the private messages unread indicator - Properly updating the private message unread count - Improved channel conversation mode detection support + - Added support for HTML encoded links (Example would be when copying from Edge the URL) * **08.12.20** - Fixed the permission editor not resolving unique ids diff --git a/shared/js/conversations/ChannelConversationManager.ts b/shared/js/conversations/ChannelConversationManager.ts index 0adb68a8..103d6b6a 100644 --- a/shared/js/conversations/ChannelConversationManager.ts +++ b/shared/js/conversations/ChannelConversationManager.ts @@ -363,8 +363,8 @@ export class ChannelConversationManager extends AbstractChatManager { if(event.client instanceof LocalClientEntry) { - const fromConversation = this.findConversation(event.oldChannel.channelId); - const targetConversation = this.findConversation(event.newChannel.channelId); + const fromConversation = this.findConversation(event.oldChannel?.channelId); + const targetConversation = this.findConversation(event.newChannel?.channelId); fromConversation?.updateAccessState(); targetConversation?.updateAccessState(); diff --git a/shared/js/ui/react-elements/ChatBox.tsx b/shared/js/ui/react-elements/ChatBox.tsx index 0c29798e..f2c5803c 100644 --- a/shared/js/ui/react-elements/ChatBox.tsx +++ b/shared/js/ui/react-elements/ChatBox.tsx @@ -89,6 +89,30 @@ const nodeToText = (element: Node) => { return element.alt || element.title; } else if(element instanceof HTMLBRElement) { return '\n'; + } else if(element instanceof HTMLAnchorElement) { + const content = [...element.childNodes].map(nodeToText).join(""); + + if(element.href) { + if(settings.static_global(Settings.KEY_CHAT_ENABLE_MARKDOWN)) { + if(content && element.title) { + return `[${content}](${element.href} "${element.title}")`; + } else if(content) { + return `[${content}](${element.href})`; + } else { + return `[${element.href}](${element.href})`; + } + } else if(settings.static_global(Settings.KEY_CHAT_ENABLE_BBCODE)) { + if(content) { + return `[url=${element.href}]${content}"[/url]`; + } else { + return `[url]${element.href}"[/url]`; + } + } else { + return element.href; + } + } else { + return content; + } } if(element.children.length > 0) { @@ -143,8 +167,9 @@ const TextInput = (props: { events: Registry, enabled?: boolean, const rawText = clipboard.getData('text/plain'); const selection = window.getSelection(); - if (!selection.rangeCount) + if (!selection.rangeCount) { return false; + } let htmlXML = clipboard.getData('text/html'); if(!htmlXML) {