From 1b9b31a245f9a545ec757f8d8e3c745b4d170a39 Mon Sep 17 00:00:00 2001 From: krishrathi1 Date: Thu, 6 Aug 2026 14:11:05 +0530 Subject: [PATCH] docs(formatting): document greedy keep-first tie-breaking in resolveOverlappingMatches --- bitchat/Services/MessageFormattingEngine.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bitchat/Services/MessageFormattingEngine.swift b/bitchat/Services/MessageFormattingEngine.swift index 1f5c656e..adb7f2c4 100644 --- a/bitchat/Services/MessageFormattingEngine.swift +++ b/bitchat/Services/MessageFormattingEngine.swift @@ -385,6 +385,13 @@ final class MessageFormattingEngine { /// strictly-increasing ranges; without this resolution a nested match /// re-renders already-shown text and can walk the render cursor /// backwards, duplicating a trailing slice of content a second time. + /// + /// Ties break by start position only, not length: whichever match starts + /// first wins outright, so an outer match (e.g. a URL) always keeps + /// priority over a shorter match nested inside it (e.g. an embedded cashu + /// token) rather than the other way around. That's intentional for + /// rendering — flip it to prefer the inner match only with a matching + /// change to how callers render the dropped outer span. static func resolveOverlappingMatches( _ matches: [Match], range: (Match) -> NSRange