From b5763115521ff1f5b5525e35826e99faacd2a811 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Wed, 11 Aug 2021 17:14:08 -0500 Subject: [PATCH] (libinterface) Use default textruns if none selected, fix multi-URL lines --- libs/libinterface/UrlTextView.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libs/libinterface/UrlTextView.cpp b/libs/libinterface/UrlTextView.cpp index 3246e05..b025605 100644 --- a/libs/libinterface/UrlTextView.cpp +++ b/libs/libinterface/UrlTextView.cpp @@ -39,6 +39,15 @@ UrlTextView::UrlTextView(const char* name, const BFont* initialFont, AdoptSystemColors(); SetViewCursor(B_CURSOR_SYSTEM_DEFAULT); + BFont font; + if (initialFont != NULL) + font = BFont(initialFont); + rgb_color color = ui_color(B_PANEL_TEXT_COLOR); + if (initialColor != NULL) + color = *initialColor; + text_run normalRun = { 0, font, color }; + fNormalRun = { 1, {normalRun} }; + BFont urlFont; urlFont.SetFace(B_REGULAR_FACE | B_UNDERSCORE_FACE); text_run urlRun = { 0, urlFont, ui_color(B_LINK_TEXT_COLOR) }; @@ -159,6 +168,9 @@ UrlTextView::Insert(const char* text, const text_run_array* runs) int32 lastEnd = 0; int32 length = buf.CountChars(); + if (runs == NULL) + runs = &fNormalRun; + while (_FindUrlString(buf, &specStart, &specEnd, lastEnd) == true) { if (lastEnd < specStart) { BString normie; @@ -244,12 +256,18 @@ UrlTextView::GetLine(int32 line) BUrl UrlTextView::UrlAt(BPoint where) { - BString urlStr, line = GetLine(LineAt(where)); + int32 lineNo = LineAt(where); + BString urlStr, line = GetLine(lineNo); BUrl url; + int32 clickedOffset = OffsetAt(where) - OffsetAt(lineNo); + int32 offset = line.FindLast(" ", clickedOffset); + if (offset == B_ERROR) + offset = 0; + int32 start; int32 end; - if (_FindUrlString(line, &start, &end, 0) == true) { + if (_FindUrlString(line, &start, &end, offset) == true) { line.CopyCharsInto(urlStr, start, end - start); url.SetUrlString(urlStr); }