Can't create keyboard-scrollable RichTextLabel

Godot Version

4.7 stable

Question

How to make a proper scrollable rich text box whose scrollbar ignores the mouse, and the content can only be scrolled with up and down arrow keys on the physical keyboard?
I have spent 2 weeks trying to figure it out, even with some AI help, but nothing seems to work so far. It either has persistent mouse interaction (despite selecting "ignore") and no keyboard response, or no response whatsoever richtextlabel hides text below the visual window/box, can't scroll to it.I want a simple rich text box that only has a visual scrollbar (can’t be grabbed with the mouse!) and up/down keys would scroll the contents up and down. It’s crazy that this simple feature seems like impossible to achieve…

You need to get the VScrollBar with RichTextLabel.get_v_scroll_bar() and set its Control.mouse_filter to Ignore

Then you can change scroll it by change the Range.value of the VScrollBar or using any of the RichTextLabel.scroll_to_*() methods like RichTextLabel.scroll_to_line().

Example:

extends RichTextLabel


func _ready() -> void:
	# Change the focus to focus all to be able to focus the node
	focus_mode = Control.FOCUS_ALL
	# Grab the focus but don't show the focus style
	grab_focus(true)
	# Set the scrollbar's mouse filter to ignore
	get_v_scroll_bar().mouse_filter = Control.MOUSE_FILTER_IGNORE


func _gui_input(event: InputEvent) -> void:
	if event is InputEventKey:
		# if it's a key, grab the scrollbar and change its value
		var scrollbar = get_v_scroll_bar()
		match event.keycode:
			KEY_UP:
				scrollbar.value -= 10
			KEY_DOWN:
				scrollbar.value += 10