From e07ee29d13845b613f0c652ab1c43326b4b401a5 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Thu, 15 Jul 2021 14:59:51 -0500 Subject: [PATCH] (librunview) Fix hover-over for multiple links --- libs/librunview/RunView.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/librunview/RunView.cpp b/libs/librunview/RunView.cpp index e427c66..f9febe7 100644 --- a/libs/librunview/RunView.cpp +++ b/libs/librunview/RunView.cpp @@ -35,7 +35,7 @@ RunView::RunView(const char* name) fDefaultRun = { 1, {run} }; BFont urlFont; - urlFont.SetFace(B_UNDERSCORE_FACE); + urlFont.SetFace(B_REGULAR_FACE | B_UNDERSCORE_FACE); text_run urlRun = { 0, urlFont, ui_color(B_LINK_TEXT_COLOR) }; fUrlRun = { 1, {urlRun} }; @@ -170,7 +170,13 @@ RunView::MouseMoved(BPoint where, uint32 code, const BMessage* drag) int32 start = 0; int32 end = 0; FindWordAround(OffsetAt(where), &start, &end); - if (fCurrentUrlEnd == 0) { + if (fCurrentUrlEnd == 0 + || (OffsetAt(where) < fCurrentUrlStart + || OffsetAt(where) > fCurrentUrlEnd)) + { + if (fCurrentUrlEnd != 0) + ReplaceRuns(fCurrentUrlStart, fCurrentUrlEnd, + &fCurrentUrlRuns); fCurrentUrlRuns = *RunArray(start, end); fCurrentUrlStart = start; fCurrentUrlEnd = end; @@ -238,9 +244,16 @@ RunView::ReplaceRuns(int32 start, int32 end, text_run_array* runs) char* buffer = new char[end - start]; GetText(start, end - start, buffer); + // Need to make sure nothing visibly changes to the user float current = ScrollBar(B_VERTICAL)->Value(); + int32 selStart = 0, selEnd = 0; + GetSelection(&selStart, &selEnd); + Replace(start, end, buffer, runs); + ScrollBar(B_VERTICAL)->SetValue(current); + if (end > 0) + Select(selStart, selEnd); } @@ -319,8 +332,7 @@ RunView::OverUrl(BPoint where) text_run urlHover = fUrlHoverRun.runs[0]; text_run urlVisit = fUrlVisitedRun.runs[0]; - if ((run.font == urlRun.font || run.font == urlHover.font - || run.font == urlVisit.font) + if (run.font.Face() == urlRun.font.Face() && (run.color == urlRun.color || run.color == urlHover.color || run.color == urlVisit.color)) return true;