Make it easier for new users to format and preview code in their posts

Suggestions to help new users posting.

#1) Use AI to determine if there is more than couple of lines of code in the post and display an embedded message at the top giving how to format code instructions.

#2) Move the Preformatted text icon to be at the front. Rename it to Format Code. Many times it even hides on my tablet to the gear icon.

#3) Your topic similar to… panel on the right is confusing to many new users as they don’t know there is a preview behind it. I would change the esc X button changed to just say Preview Post

6 Likes

All-around excellent suggestions. If you’re looking to help someone with a topic, it’s mildly frustrating to be met with code that isn’t formatted. There have been many times in which I completely skip reading a post simply because of this very issue.

I doubt that you need to use AI to detect code that is in need of formatting. You likely just need a list of keywords (or keyword combinations) that prompt the hint.

4 Likes

I’m just thinking one of the reasons also is that when code is pasted in to the post, why not at least keep the tabs or at least convert them to spaces (maybe 5)?

Example code I just pasted. It looks fine when I paste it. However the tabs are erased which messes it up. At the very least convert them to spaces. May not look color coded, but in most case it is understood.

func press_enter():
var enter_key:=InputEventKey.new()
enter_key.keycode=KEY_ENTER
enter_key.pressed = true
Input.parse_input_event(enter_key)

func _on_gui_input(event):
if event is InputEventKey and event.keycode >= 32 and event.keycode <= 167:# and event.is_pressed():
var caretln=get_caret_line()
if caretln > MAX_LINES:
accept_event()
elif get_line(caretln).length() > MAX_LENGTH:
if get_line_count() < MAX_LINES:
press_enter()
else:
accept_event()

And this is what it looks like formatted without the language tag.

func press_enter():
	var enter_key:=InputEventKey.new()
	enter_key.keycode=KEY_ENTER
	enter_key.pressed = true
	Input.parse_input_event(enter_key)

func _on_gui_input(event):
	if event is InputEventKey and event.keycode >= 32 and event.keycode <= 167:# and event.is_pressed():
		var caretln=get_caret_line()
		if caretln > MAX_LINES:
			accept_event()
		elif get_line(caretln).length() > MAX_LENGTH:
			if get_line_count() < MAX_LINES:
				press_enter()
			else:
				accept_event()
1 Like

Posting here so to be linked for later use instead of re-typing this every time


Make sure you paste scripts instead of screenshots. To properly format pasted code use three ticks ``` at the start and end of your paste like so:

```
# type or paste code here
func _ready() -> void:
    print("My ready function!")
```

Results in:

# type or paste code here
func _ready() -> void:
    print("My ready function!")

Press the </> button or ctrl+e in the forum to create these ticks.

2024-09-02-190029_478x181_scrot

5 Likes

The explanation when creating a new post should include formatting code using ``` or [code] [/code] and mention the code button.
Currently it is pretty vague for people not familiar with these kind of things.

Or maybe rework the code icon to show </code> to make it clearer.

3 Likes

May be AB-testing hiding the button, the ctrl+e shortcut has also been removed for me? Seems like a really bad call. I think it’s AB tests as this change isn’t on chromium.

2024-10-30-145731_547x116_scrot

1 Like