sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
950 stars 405 forks source link

find: could be more intelligent about bolding the replacement #2506

Open dgw opened 10 months ago

dgw commented 10 months ago

With #2014 (and a hotfix to that, #2066), we have the replaced text in bold after using s/find/replace/ 🥳 …unless the replacement is already inside a bolded substring, including if the replacement ran against an already-edited line.

A riff on the "not your buddy, guy" meme using find today showed that, if one does s/replace/again/, the replaced output of again won't appear bold (but it will waste 4 bytes with two ^B control characters on either side of the replaced text).

My first instinct is to just skip formatting the replacement at all if the line contains any formatting control codes. That's likely the simplest approach; anything more (e.g. determining whether the specific substring being replaced is inside a formatted range) gets into fairly complicated string analysis with diminishing returns.

Maybe no one will even want to think about this until find is extracted from core into its own plugin package, but for now this is the only reasonably relevant issue tracker for such an idea.

Exirel commented 9 months ago

So one solution would be to use the plain version of the message to issue the replacement?