Skip to content

Highlight verses using tag folder color. Solves #968 - #1336

Open
LAfricain wants to merge 2 commits into
crosswire:masterfrom
LAfricain:verse-highlight
Open

Highlight verses using tag folder color. Solves #968#1336
LAfricain wants to merge 2 commits into
crosswire:masterfrom
LAfricain:verse-highlight

Conversation

@LAfricain

Copy link
Copy Markdown
Contributor

feat: highlight verses using tag folder color

This PR adds visual highlighting of Bible verses based on their bookmark tag color.

New behavior

When a verse is bookmarked inside a colored tag folder, it is highlighted in the Bible text using that folder's color. The text color is automatically adjusted (white or black) based on the background luminance to ensure readability.

  • The current verse green highlight is disabled when a tag color is present, avoiding visual conflicts.
  • Verse ranges, comma-separated verses and semicolon-separated references are all supported.

Opting out

This feature is entirely driven by the tag color. If you do not want a tag folder to highlight its verses in the Bible text, simply remove its color (click "No color" when editing the folder). Folders without a color will not highlight any verses.

Details

  • Highlighting is handled in display.cc via get_tag_color_for_versekey()
  • Text color contrast is computed using the ITU-R BT.709 relative luminance formula
  • Depends on the bookmark color feature introduced in PR Bookmark color solves #685 #1317

@karlkleinpaste

Copy link
Copy Markdown
Contributor

First observation: It seems to work properly. That may seem like a trivial thing to say, but compared to the previous version a couple months ago, I'm pleased to be able to make the observation.

I have a couple further thoughts. No surprise there, I suppose.

  1. I like the fact that, when user annotation highlight is enabled, it still shows a bookmark folder color 1-space block next to the verse, although the annotation highlight controls. Kudos for that. Turning off annotation highlight makes the whole verse highlight according to folder color.
Screenshot at 2026-07-03 17-33-23
  1. However, the luminance test seems to be off. This verse is in a folder colored black (deliberately), and the resulting display is unreadable, when annotation highlight is turned off. I don't know if there's a way to improve this test, but I think you'd agree that "dark green text on black background" is far from a preferred colorization choice. It's probably significant, of course, that the verse is the current verse, which is why it's getting green in the first place. Perhaps being the current verse needs a special case consideration for luminance adjustment? I'm really not sure what to say about it other than that. I would appreciate your thoughts on it.
Screenshot at 2026-07-03 17-33-42
  1. I have an extensive set of bookmarks, after having been using Xiphos for 20 years; bookmarks.xml is ~250 lines long. So I've gone to the trouble to colorize my many folders, and unavoidably I've found myself re-using colors or using similar colors because, well, there are just so many colors out there. I have 2 folders that are somewhat different shades of blue, and another that's bright green. The result is a somewhat complicated-looking Gen 2.

Here's the thing: I can see that they're bookmarked because they're colored, but I have no reference for which bookmark in which folder.
Screenshot at 2026-07-03 17-34-00
Would there be a way to provide something like a mouse-hover (non-click) display in the status bar to show transiently (say) the bookmark name, or even folder+name? Not the whole folder-in-folder path -- my folders go 4 deep -- just the single containing folder. That would give me the clue to know where to go looking to find a bookmark I set 15 years ago and have long forgotten.

  1. A final thing, but I must say it's important. I realize that colorization is explicitly driven by folders having color, and getting rid of color is a controlled by a folder being set for No Color. But there are times I want to share my screen with an audience (e.g. teaching Bible study) when I don't want everyone else in the room to have their eyes drawn to my particular colorizations. I think what's needed is an enhancement to turn on/off the entire bookmark colorization system, in Preferences -> General -> Options. Default on, because the colorized display is valuable, but able to be turned off so that no bookmark colorization happens at all. Then when I go to teach, I could just disable the whole thing, and others seeing my screen don't find their eyes scrambled by my unusual color choices.

The Options part of Prefs has gotten kinda long and dense, so I suspect part of this latter need is that the default (or should I say minimum) size of Prefs should grow by a dozen pixels, or maybe two.

If you like, I could merge this as it stands -- it's good and functional and valuable -- with the proviso to do some more for it.

@karlkleinpaste

Copy link
Copy Markdown
Contributor

Oh, no...
Well, I can't merge this as-is after all, because of a major problem in rendering. I should have looked for more examples before running into this.

image

The luminance test (I suppose) has failed drastically. The missing text is actually present, it's just invisible, as indicated when I mouse-sweep the entire chapter.

Screenshot at 2026-07-04 08-23-58

The text is present, but is white-on-white.

Also, this again shows that current verse highlight leads to unreadable text, as v.1 is dark green on medium blue. Current verse color highlighting may need to be avoided entirely when a bookmark folder color is selected. And this shows why a means for disabling the entire bookmark colorization facility needs to be available on demand.

@karlkleinpaste

Copy link
Copy Markdown
Contributor

This further exposes another problem:

  • Only NET fails display this chapter correctly.
  • Some bookmark color choices are not uniform across versions.

This image is ESV.

Screenshot at 2026-07-04 08-30-51
  • There is no white-on-white text.
  • There is only one bookmark-colored verse.

Indeed, only NET shows the errors.

My NET (not the standard module) is ThML, not OSIS, but by the time Xiphos is providing renderable text, it's all just XHTML, so the source origin shouldn't be what's affecting this.

@karlkleinpaste

Copy link
Copy Markdown
Contributor

I'm afraid this is getting worse.

I have just 2 bookmarks that include Rev 22.

grep Rev.*22 ~/.config/xiphos/bookmarks/bookmarks.xml
      <Bookmark modulename="" key="Deu.28.27; 1Sam.17.39; Isa.14.23; Rom.5.7; Rom.13.13; 2Tim.2.25; Matt.1.1; Psalm.12.7; Prov.18.24; Matt.5.47;17.20; 1Cor.13.8; Gal.5.12;6.4; Eph.2.1; Rev.22.19" moduledescription=" " description="KJV flaws"/>
      <Bookmark modulename="" key="Deut 4:2;12:32; Rev 22:18,19" moduledescription=" " description="Add to/take away"/>

But all versions are showing colorization as if I had a half dozen such bookmarks.

ESV.
Screenshot at 2026-07-04 09-03-48

BSB.
Screenshot at 2026-07-04 08-49-49

@LAfricain

Copy link
Copy Markdown
Contributor Author

I'll take a look at it next week, but I can already say that, strangely enough, I'm not getting the same errors as you—in Revelation, everything is displaying correctly.
Don't you have any other blue bookmarks?

@karlkleinpaste

Copy link
Copy Markdown
Contributor

Regrets that yesterday's "render whole books" PR has rendered this PR conflicted...probably deeply so. It will have to be reworked against the updated architecture where one display function for main window no longer does all the work; rather that function does just the initial HTML header generation and then farms out the rendering work to a separate RenderOneChapter function and another RenderWholeBook function which calls RenderOneChapter repeatedly.

It is possible that one type of error previously seen by me in this PR was caused in part by marginal module content involving paragraph breaks with improper trailing specifications. The paragraph ending problem has not one but rather two cases, both now handled. I hope I won't find any more in the future.

As I mentioned elsewhere, I am out of town for a few days but I'll take another look at all of these when I get back.

@LAfricain

Copy link
Copy Markdown
Contributor Author

Do you plan on working on this, or should I take a look? I have to admit, if you have a little time, I'd be happy to let you handle it, but let me know! I really like your commit that lets you scroll through the entire Bible.

I'm waiting for the last three PRs to be merged, and then I'll start translating the text that's still in English. Do you think it would make sense to release an new version once the three PRs are merged? These are some great new features!

@LAfricain

Copy link
Copy Markdown
Contributor Author

Finally I solved the conflict

@karlkleinpaste

Copy link
Copy Markdown
Contributor

I intended to test the current state of this. However, notwithstanding the claim by GH of "no conflics with base", ...

$ patch -p1 < ~/Desktop/1336.patch
patching file src/backend/sword_main.cc
Hunk #1 succeeded at 925 (offset 1 line).
patching file src/gtk/bookmarks_menu.c
Hunk #1 succeeded at 499 (offset 191 lines).
Hunk #2 succeeded at 1288 (offset 192 lines).
patching file src/gtk/bookmarks_treeview.c
patching file src/gui/bookmarks_menu.h
Hunk #1 succeeded at 44 (offset 1 line).
Hunk #2 succeeded at 65 (offset 1 line).
patching file src/gui/bookmarks_treeview.h
patching file src/main/display.cc
Hunk #2 succeeded at 97 (offset -2 lines).
Hunk #3 succeeded at 1549 (offset 123 lines).
Hunk #4 FAILED at 1671.
Hunk #5 FAILED at 1737.
Hunk #6 FAILED at 1748.
Hunk #7 FAILED at 1756.
4 out of 7 hunks FAILED -- saving rejects to file src/main/display.cc.rej
patching file src/main/settings.c
Hunk #1 succeeded at 1107 (offset 42 lines).
patching file src/main/settings.h
Hunk #1 succeeded at 106 (offset 2 lines).
patching file src/main/url.cc
patching file ui/xi-menus-popup.gtkbuilder
patching file ui/xi-menus.glade
Hunk #1 succeeded at 1793 (offset 9 lines).
patching file src/main/main.c

src/main/display.cc does not patch cleanly. The number of offset mentions disturbs me. As it stands, this isn't clean.

I simply don't trust GH itself. I trust patch because it's been around for 30 years without making mistakes.

You may need just a rebase.

lafricain79 added 2 commits August 1, 2026 20:53
- **Truncated multi-reference bookmarks**: `BackEnd::parse_verse_list()`
  used `popError()` as a loop-termination condition, which also fires
  when a single element in the list fails to resolve — silently
  dropping every element after it, even valid ones. Switched to
  indexed access (`getCount()` / `getElement()`), so one bad reference
  no longer swallows the rest of a bookmark's verse list.

- **Unreadable text on dark tag colors**: the current-verse `<font
  color="...">` wrapper was applied unconditionally, overriding the
  contrast color already computed for the tag background. It's now
  skipped whenever a tag color is active, so the computed
  black/white contrast color is respected instead.

- **Major bug: verse text turning invisible for the rest of the
  chapter**: the tag-color `<span>` and the current-verse/annotation
  `<span><font>` were opened independently but shared a single,
  under-conditioned closing statement. When a verse had a tag color
  but wasn't the current verse, the highlight span was opened is
  never opened but its closing tag was still emitted, corrupting the
  HTML structure for every subsequent verse in the chapter. Each span
  now tracks its own open/close state explicitly.

- **Strong's/morphology links ignoring computed contrast**: verse
  numbers and linked words are colored via a global CSS `a:link`
  rule, which overrides any `color` inherited from an ancestor
  `<span>`. Added a `.tagcolor a:link { color: inherit !important }`
  rule and tagged the relevant span with `class="tagcolor"` so link
  text respects the computed contrast color too.

- **On/off toggle**: added "Colorize verses by folder color" as a
  right-click checkbox item on the bookmarks tree (rather than
  buried in Preferences), matching the existing "Popup menu for
  cross-references" toggle added by crosswire#1335. Defaults to on, persists
  across restarts, and takes effect immediately.

- **Status bar bookmark info on hover**: hovering (not clicking) a
  verse number that belongs to a bookmark now shows "<containing
  folder>: <bookmark name>" in the status bar, making it easier to
  identify which of several similarly-colored bookmarks a verse
  belongs to — without exposing the full nested folder path.

- The luminance/contrast calculation itself (`text_color_for_bg`)
  was already correct; the "dark green on black" and "white on
  white" issues were caused by other elements overriding its output,
  not by the luminance formula.
Xiphos never called setlocale(LC_ALL, ""), relying instead on
gtk_init_with_args() to set the process locale implicitly as a
side effect. gettext (bindtextdomain/textdomain) was also only
initialized later, inside gui_init().

Both of these happen well after settings_init() -> init_bookmarks(),
which generates the user's default bookmarks.xml using _()-wrapped
strings ("What must I do to be saved?", "What is the Gospel?", etc.).
As a result, the default bookmarks were always written in English,
even when .po translations existed and the rest of the UI displayed
correctly in the user's language.

Move setlocale(LC_ALL, "") and the bindtextdomain/textdomain calls
to the very start of main(), before settings_init(). The later
calls in gui_init() are left in place and are harmless to repeat
(gettext initialization is idempotent).
@LAfricain

Copy link
Copy Markdown
Contributor Author

@karlkleinpaste done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants