Skip to content

Commit

Permalink
detected links now clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Sep 25, 2020
1 parent 4db85a4 commit 137fcb9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 1 addition & 3 deletions src/buffer/out/textBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ filling in the last row, and updating the screen.

#include "../renderer/inc/IRenderTarget.hpp"

#include <regex>

class TextBuffer final
{
public:
Expand Down Expand Up @@ -184,7 +182,7 @@ class TextBuffer final
const std::optional<Microsoft::Console::Types::Viewport> lastCharacterViewport,
std::optional<std::reference_wrapper<PositionInformation>> positionInfo);

const size_t AddPatternRecognizer(const std::string regexString);
const size_t AddPatternRecognizer(const std::string_view regexString);
const std::vector<std::tuple<size_t, COORD, COORD>> UpdatePatterns(const size_t firstRow, const size_t lastRow) const;

private:
Expand Down
24 changes: 22 additions & 2 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {};
}

Expand Down

0 comments on commit 137fcb9

Please sign in to comment.