dissent icon indicating copy to clipboard operation
dissent copied to clipboard

Message spoilers

Open tfuxu opened this issue 1 year ago • 3 comments

This PR implements custom Spoiler widget used as a overlay on messages wrapped in || tags.

Note: Putting this as a draft for now, as there are a couple MarkdownViewer bugs that needs to be fixed beforehand, and the current spoiler style definitely needs some polishing.

Fixes #152

TODO:

  • [ ] Make spoiler overlay the same size as the message text
  • [ ] Refine spoiler style

Screenshots:

Simple message hidden:

Screenshot from 2023-10-11 19-24-18

Simple message visible:

Screenshot from 2023-10-11 19-25-43

Textblock/multi-line message hidden:

Screenshot from 2023-10-11 19-24-30

tfuxu avatar Oct 11 '23 18:10 tfuxu

Does this not work for inline spoiler tags, e.g. hello ||world||?

diamondburned avatar Oct 11 '23 20:10 diamondburned

Does this not work for inline spoiler tags, e.g. hello ||world||?

Ah, I completely forgot about this 🤦‍♂️️ I'll think of another solution for this, since the overlay probably isn't as flexible to put only on a specific section of the message (at least not with the current implementation).

tfuxu avatar Oct 12 '23 19:10 tfuxu

You can use a hover/tap EventController combined with method.TextView.get_iter_at_position and method.TextView.window_to_buffer_coords to obtain the character mark at the hovering point, then check if it has a spoiler tag and set its opacity to 1 if there is any.

You'll also need to keep a last spoiler tag:

var lastSpoilerTag *gtk.TextTag
func(spoilerTag *gtk.TextTag) { // callback
    if lastSpoilerTag == spoilerTag {
        return
    }

    if lastSpoilerTag != nil {
        lastSpoilerTag.SetProperty("opacity", 0)
    }

    spoilerTag.SetProperty("opacity", 1)
}

diamondburned avatar Oct 12 '23 22:10 diamondburned

Partially implemented in https://github.com/diamondburned/dissent/commit/a52c614ea157324770a72333a61ede960365bafb.

diamondburned avatar Jun 13 '24 01:06 diamondburned

Cool! Closing as there is a new solution implemented. I've also created a tracking issue for currently unsupported types of spoilers #282

tfuxu avatar Jun 16 '24 20:06 tfuxu