From 137fcb9631010c83e3fb4f338a3ecd123f766b7f Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 25 Sep 2020 14:24:06 -0400 Subject: [PATCH] detected links now clickable --- src/buffer/out/textBuffer.cpp | 2 +- src/buffer/out/textBuffer.hpp | 4 +--- src/cascadia/TerminalCore/Terminal.cpp | 24 ++++++++++++++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index db5683e9705..5b22cfe15fe 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -2362,7 +2362,7 @@ void TextBuffer::CopyHyperlinkMaps(const TextBuffer& other) // - The regex pattern // Return value: // - An ID that the caller should associate with the given pattern -const size_t TextBuffer::AddPatternRecognizer(const std::string regexString) +const size_t TextBuffer::AddPatternRecognizer(const std::string_view regexString) { ++_currentPatternId; _IdsAndPatterns.emplace(std::make_pair(_currentPatternId, regexString)); diff --git a/src/buffer/out/textBuffer.hpp b/src/buffer/out/textBuffer.hpp index 67ebfea17d7..452dfb264ff 100644 --- a/src/buffer/out/textBuffer.hpp +++ b/src/buffer/out/textBuffer.hpp @@ -60,8 +60,6 @@ filling in the last row, and updating the screen. #include "../renderer/inc/IRenderTarget.hpp" -#include - class TextBuffer final { public: @@ -184,7 +182,7 @@ class TextBuffer final const std::optional lastCharacterViewport, std::optional> positionInfo); - const size_t AddPatternRecognizer(const std::string regexString); + const size_t AddPatternRecognizer(const std::string_view regexString); const std::vector> UpdatePatterns(const size_t firstRow, const size_t lastRow) const; private: diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 05b7e13ddf4..463243ca2e0 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -412,9 +412,9 @@ bool Terminal::IsTrackingMouseInput() const noexcept } // Method Description: -// - If the clicked text is a hyperlink, open it +// - Given a coord, get the URI at that location // Arguments: -// - The position of the clicked text +// - The position std::wstring Terminal::GetHyperlinkAtPosition(const COORD position) { auto attr = _buffer->GetCellDataAt(_ConvertToBufferCell(position))->TextAttr(); @@ -423,6 +423,26 @@ std::wstring Terminal::GetHyperlinkAtPosition(const COORD position) auto uri = _buffer->GetHyperlinkUriFromId(attr.GetHyperlinkId()); return uri; } + // also look through our known pattern locations + for (auto pattern : _patternsAndLocations) + { + if (std::get<0>(pattern) == _hyperlinkPatternId) + { + const auto start = std::get<1>(pattern); + const auto end = std::get<2>(pattern); + if (_IsLocationWithinCoordinates(position, start, end)) + { + std::wstring uri; + const auto startIter = _buffer->GetCellDataAt(_ConvertToBufferCell(start)); + const auto endIter = _buffer->GetCellDataAt(_ConvertToBufferCell(end)); + for (auto iter = startIter; iter != endIter; ++iter) + { + uri += iter->Chars(); + } + return uri; + } + } + } return {}; }