From 1822c00a3b03e5ba2eaf8807b035d1ea6566f17f Mon Sep 17 00:00:00 2001 From: hz Date: Thu, 9 Jul 2026 21:48:34 -0500 Subject: [PATCH] Support partial unhighlight selection --- scripts/ui/question_player.gd | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/ui/question_player.gd b/scripts/ui/question_player.gd index 0726e9b..1f9964b 100644 --- a/scripts/ui/question_player.gd +++ b/scripts/ui/question_player.gd @@ -329,7 +329,7 @@ func _highlight_range(start: int, end: int) -> void: if start == end: return - if _remove_overlapping_highlights(highlights, start, end): + if _subtract_highlight_range(highlights, start, end): _render_stem() if stem_label.has_method("deselect"): stem_label.deselect() @@ -370,14 +370,21 @@ func _escape_bbcode(value: String) -> String: return value.replace("[", "[lb]").replace("]", "[rb]") -func _remove_overlapping_highlights(highlights: Array, start: int, end: int) -> bool: - var removed := false +func _subtract_highlight_range(highlights: Array, start: int, end: int) -> bool: + var changed := false for index in range(highlights.size() - 1, -1, -1): var highlight_range: Dictionary = highlights[index] - if start < int(highlight_range.get("end", 0)) and end > int(highlight_range.get("start", 0)): + var highlight_start := int(highlight_range.get("start", 0)) + var highlight_end := int(highlight_range.get("end", 0)) + if start < highlight_end and end > highlight_start: highlights.remove_at(index) - removed = true - return removed + if highlight_start < start: + highlights.insert(index, {"start": highlight_start, "end": start}) + index += 1 + if end < highlight_end: + highlights.insert(index, {"start": end, "end": highlight_end}) + changed = true + return changed func _apply_saved_choice_state() -> void: