Hidden text in RichTextLabel doesn't behave as documentation claims. BBCode bug

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By monsterousoperandi

I’m ussing BBCode RichTextEffects to hide text. The text only turns invisable but doesn’t behave as it would in 3.5 or as the 4.10 documentation states it should.

@tool
extends RichTextEffect
class_name HideText

var bbcode := "hide"

func _process_custom_fx( char_fx : CharFXTransform) -> bool :
	if Settings.hide == true :
		char_fx.set_visibility( false )
	return true  

Unparsed text:
"Integer vitae justo eget magna fermentum iaculis eu non diam.[no_hide]

This should show. [/no_hide][hide]

This should be hidden…[/hide]

Convallis a cras semper auctor neque vitae tempus quam. Integer vitae justo eget magna fermentum iaculis eu non diam."


output looks like this :
"Integer vitae justo eget magna fermentum iaculis eu non diam.

This should show.

invisible, selectable, space-consuming characters be here!!!!!

Convallis a cras semper auctor neque vitae tempus quam. Integer vitae justo eget magna fermentum iaculis eu non diam."

The [hide] tag “works”, in that it hides the text. The issue is that you can still select, copy and paste this “hidden” text and it still takes up space. The documentation says that the text should move to take up this space and that if I didn’t want this, I should set the Alpha to 0 instead. But it seems like setting the Alpha to 0 is exactly what this char_fx is actually doing, rather than hiding the text and shifting the visible characters as the documentation implies.

I switched to 4.10 because 3.5 would hide the text but the control would still size itself as if the text was still there. I just can’t seem win… sigh.

:bust_in_silhouette: Reply From: monsterousoperandi

Incase anyone is interested I got feedback from the Godot peeps. Turns out that it’s borkt and rather than fixing it, they’re changing the documentation to show that this is now a “feature”.

So I created a content parser that nukes the tags before BB Code can do it’s thing. In your string you’d enter something like "<male>this text will show if the player is male</male> and <female>this text will show if the the player is female</female> " if they are male it will only nuke the <male></male> tags and if they are female it will nuke everything, to include the tags.

extends Node
class_name ContentParser

func parse_content( _text : String ) -> String :
	##### Player Stuff #####
	if Player.is_male :
		_text = _hide_tag_only( _text, "male" )
		_text = _hide_content( _text, "female" )
	else : 
		_text = _hide_tag_only( _text, "female" )
		_text = _hide_content( _text, "male" )


func _hide_tag_only( _text : String,   _tag : String ) -> String :
	var pattern = RegEx.new()
	var results : Array 
	var reg_ex : String = (
		"<" + 
		_tag +
		">|</" +
		_tag +
		">"
	)  
	pattern.compile( reg_ex )
	#check if regex is valid
	if pattern.is_valid() :
		results = pattern.search_all( _text )
	
	#check if tags need to be scrubbed.
	if results.size() > 0 :
		_text =  pattern.sub( _text, "", true)
	
	return _text

func _hide_content( _text : String,   _tag : String ) -> String :
	var pattern = RegEx.new()
	var results : Array 
	var reg_ex : String = (
		"<" + 
		_tag +
		">[.\\s\\S]*?</" +
		_tag +
		">"
	)  
	pattern.compile( reg_ex )
	#check if regex is valid
	if pattern.is_valid() :
		results = pattern.search_all( _text )
	
	#check if tags need to be scrubbed.
	if results.size() > 0 :
		_text =  pattern.sub( _text, "", true)
	
	return _text