godot icon indicating copy to clipboard operation
godot copied to clipboard

Editor: Renaming Node with default name to whitespace 'accepts' whitespace as Node name

Open thygrrr opened this issue 3 months ago • 1 comments

Tested versions

  • reproducible in v4.2.2.stable.mono.official [15073afe3]

System information

Windows 11

Issue description

Renaming a Node, for example a Panel or Node2D, to whitespace (e.g. , a single or multiple space characters), seemingly accepts the whitespace name.

image

The whitespace is even editable.

The issue only occurs if the Node already bears its default name.

This is perhaps just a display/editor issue, as other controls react to the default name of the control.

Restarting the editor will reveal the true name of the Node again.

Renaming any other nodes after a whitespace name was given makes the true name show up, as well.

https://github.com/godotengine/godot/assets/8904620/1b8e7dfd-18f2-4fe2-8d47-9885699bcb16

Relevant Sub-Issue (leading/trailing whitespace)

The documentation does not mention that whitespace isn't an invalid node name (is it?), and neither does the error dialog when trying to give an invalid name, e.g. choosing a period as name . will show: (to be fair, we couldn't see the whitespace if it were mentioned)

image

There is an added issue where inputting or pasting text with leading/trailing whitespaces into a name has them truncated on first paste, but not on subsequent pastes/input attempts.

It appears that in this case, the issue, too, is display related, likely a whitespace-insensitive string comparison (or comparison after trim).

https://github.com/godotengine/godot/assets/8904620/e3e5ed60-f3fc-4015-988b-e1c2bdcac3b0

Expected behaviour:

  • EITHER leading and trailing whitespace are always trimmed (if deemed illegal as node names or undesirable as UX)
  • OR they are always kept

image (the .tscn format actually allows them and they load correctly, and they persist repeat saving of the scene, but are destroyed when edited because the string is trimmed upon pressing the enter key)

Obscure Sub-Sub-Issue (tabulators)

Tabs are neither inputtable nor displayed by the editor. However, they can be read from, written to, and persisted in a .tscn file. (with some funky behaviour)

image

When a TAB (character) is encountered in a .tscn file, the editor does not display it, but when the editor saves the scene, the TAB is subsequently serialized and keeps being persisted as \t, even when the Node name is edited.

The editor is aware of the tab, holding shift and using the cursor keys shows the cursor "hangs" on the invisible character.

Expected behaviour:

  • EITHER tabs can be input (e.g. via alt-code, or escape sequence)
  • AND tabs are displayed
  • OR tabs are stripped, and raise an error or warning when a .tscn is loaded where node names contain them

Interestingly, the escape sequence \s is read from the .tscn as the character s, not U+0020 (i.e. a space character). Conversely however, \s in a node name is serialized as \\s (the latter makes sense, actually)

In conclusion, Godot really is on my side when it comes to the eternal tabs, not spaces battle. ;)

Steps to reproduce

  1. Create any node, e.g. a Node2D or Panel
  2. ensure it has its default name (e.g. "Node2D" for a Node2D)
  3. Enter renaming mode, either by pressing F2, single mouse click, or the context menu
  4. Clear the name and input one or more spaces (Space Key)
  5. Observe: Spaces are 'accepted' as name. (after a short flicker)
  6. Enter renaming mode again.
  7. Observe: The spaces are even 'editable', you can remove or add more here.
  8. Observe: 'editing' the fake name does not cause the flicker (as the actual underlying node name seems to be equal the default)
  9. Rename the node to something not default (e.g. "Demo")
  10. Rename the node to whitespace again.
  11. Observe: The node actually receives its default name (a short flicker of the wrong name is visible).
  12. Reset Node name to default
  13. Manually enter or paste a name with leading/trailing whitespace example
  14. Observe: The node name is example, whitespace has been trimmed.
  15. Repeat step 14 (same input!) (actually, any input where the trimmed string equals the current node name)
  16. Observe: The editor 'accepts' the leading and trailing whitespace this time.

Minimal reproduction project (MRP)

None needed, this happens in any scene. Simply Create a new project.

thygrrr avatar May 01 '24 08:05 thygrrr

I can take a look at this one, I imagine that it will involve just validating input when the node's name is set for the first time.

toadkarter avatar May 01 '24 11:05 toadkarter

Hmm, while I do see this bug on the revision you tested this on but not on latest, both on Windows and Linux - it seems to me that has been fixed since? When I try to rename the node to one with whitespace it seems to revert to the class name.

toadkarter avatar May 02 '24 08:05 toadkarter

Issue no longer reproducible 4.3-dev6_mono_win64.

thygrrr avatar May 06 '24 08:05 thygrrr