From 6e443cd767ce223cc5865587a20605cd4bb51d3a Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 25 Oct 2025 15:30:49 +0200 Subject: [PATCH] Plugin links pt 2: Link::InsertText (#6527) --- CHANGELOG.md | 2 +- docs/chatterino.d.ts | 1 + docs/lua-meta/globals.lua | 1 + docs/wip-plugins.md | 1 + src/controllers/plugins/api/Message.cpp | 2 +- src/controllers/plugins/api/Message.hpp | 1 + src/widgets/helper/ChannelView.cpp | 9 +++++++++ 7 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ca8c54b..48f1e204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Minor: Badges now link to their home page like emotes in the context menu. (#6437) - Minor: Fixed usercard resizing improperly without recent messages. (#6496) - Minor: Added setting for character limit of deleted messages. (#6491) -- Minor: Added link support to plugin message API. (#6386) +- Minor: Added link support to plugin message API. (#6386, #6527) - Minor: Added a description for the logging option under moderation tab. (#6514) - Minor: Fixed "edit hotkey" dialog opening like a normal window. (#6540) - Bugfix: Expose the "Extra extension IDs" setting on non-Windows systems too. (#6509) diff --git a/docs/chatterino.d.ts b/docs/chatterino.d.ts index ab279a73..dd833df0 100644 --- a/docs/chatterino.d.ts +++ b/docs/chatterino.d.ts @@ -255,6 +255,7 @@ declare namespace c2 { JumpToChannel, CopyToClipboard, JumpToMessage, + InsertText, } enum MessageFlag { diff --git a/docs/lua-meta/globals.lua b/docs/lua-meta/globals.lua index 388147d2..a3047e96 100644 --- a/docs/lua-meta/globals.lua +++ b/docs/lua-meta/globals.lua @@ -354,6 +354,7 @@ c2.LinkType = { JumpToChannel = {}, ---@type c2.LinkType.JumpToChannel CopyToClipboard = {}, ---@type c2.LinkType.CopyToClipboard JumpToMessage = {}, ---@type c2.LinkType.JumpToMessage + InsertText = {}, ---@type c2.LinkType.InsertText } -- Begin src/singletons/Fonts.hpp diff --git a/docs/wip-plugins.md b/docs/wip-plugins.md index 134e4478..75c4efe0 100644 --- a/docs/wip-plugins.md +++ b/docs/wip-plugins.md @@ -621,6 +621,7 @@ This table describes links available to plugins. | `JumpToChannel` | [Channel name](#channelget_name) | Go to already open split with given channel | `#pajlada` | | `CopyToClipboard` | Any Unicode text | Copy value to clipboard | n/a | | `JumpToMessage` | ID of the message | Highlight the message with given ID in current split, do nothing if it was not found | n/a | +| `InsertText` | Any text, command or emote | Insert text into split input | n/a | ### Input/Output API diff --git a/src/controllers/plugins/api/Message.cpp b/src/controllers/plugins/api/Message.cpp index e5d035e0..690a0010 100644 --- a/src/controllers/plugins/api/Message.cpp +++ b/src/controllers/plugins/api/Message.cpp @@ -190,6 +190,7 @@ std::unique_ptr elementFromTable(const sol::table &tbl) break; // these links should be safe to click as they don't have any immediate action associated with them + case Link::InsertText: case Link::JumpToChannel: case Link::JumpToMessage: case Link::UserInfo: @@ -201,7 +202,6 @@ std::unique_ptr elementFromTable(const sol::table &tbl) case Link::None: case Link::AutoModAllow: case Link::AutoModDeny: - case Link::InsertText: case Link::OpenAccountsPage: case Link::Reconnect: throw std::runtime_error( diff --git a/src/controllers/plugins/api/Message.hpp b/src/controllers/plugins/api/Message.hpp index ba66eab9..650ca8dc 100644 --- a/src/controllers/plugins/api/Message.hpp +++ b/src/controllers/plugins/api/Message.hpp @@ -102,6 +102,7 @@ enum class ExposedLinkType : std::uint8_t { JumpToChannel = Link::Type::JumpToChannel, CopyToClipboard = Link::Type::CopyToClipboard, JumpToMessage = Link::Type::JumpToMessage, + InsertText = Link::Type::InsertText, }; /** diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index a6a54c2c..6b624d7b 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -2423,6 +2423,15 @@ void ChannelView::handleMouseClick(QMouseEvent *event, if (link.type == Link::InsertText) { this->linkClicked.invoke(link); + + if (this->context_ == Context::None) + { + auto *split = dynamic_cast(this->parentWidget()); + if (split) + { + split->insertTextToInput(link.value); + } + } } } break;