Skip to content

Conversation

@timothyqiu
Copy link
Member

The problem: When editing scripts, I often notice this kind of jump caused by line numbers.

Peek 2025-10-28 16-56

This PR:

  • Adds a line_numbers_min_digits property to CodeEdit. It defaults to 1 to be compatible with existing projects.
  • Adds an editor setting text_editor/appearance/gutters/line_numbers_min_digits which defaults to 2.

@Mickeon
Copy link
Member

Mickeon commented Oct 28, 2025

For reference, and from what I can see, in terms of what other programs do:

  • Visual Studio Code has a minimum width of 4. This cannot be customized.
  • Notepad++ has a minimum width of 3 if the "Line Number" is set to "Dynamic width", otherwise it's 4.
  • Github's online text editor has no minimum width.

Given that some scripts can genuinely be really brief and self-sustaining, a minimum width of 2 by default in this PR may sound ideal. However, I would say that for any practical purposes most scripts will easily reach 3 digits, so that would be more ideal in my opinion.

I also would not make this an editor setting, personally, unless there's severe demand for it, because it's far too niche. A property or theme item may be fine, however.
Even if you disagree, the current range (up to 10 or even greater) is absolutely ridiculous for many reasons, but let's also keep in mind that the existing text editor already struggles with horizontal space, which makes the need to increase this number even more unlikely.

@AThousandShips AThousandShips added this to the 4.x milestone Oct 28, 2025
@timothyqiu timothyqiu force-pushed the line-number-min-chars branch from fe7ac97 to 7031bab Compare October 28, 2025 13:35
@timothyqiu
Copy link
Member Author

  • Changed the range hint to 1,5,1.
  • Changed the editor setting's default to 3.

I also would not make this an editor setting, personally, unless there's severe demand for it, because it's far too niche. A property or theme item may be fine, however.

There may be some misunderstanding here. This PR adds a property to the CodeEdit node. The CodeTextEditor in the editor uses CodeEdit and applies the editor setting to it.

@Mickeon
Copy link
Member

Mickeon commented Oct 28, 2025

No misunderstanding. I am aware of what this PR does. I just think an editor setting is excessive.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected. I think this is a good usability improvement, not only when editing code, but also when switching between scripts.

That said, in complex projects, the majority of GDScript files are expected to be in the 100-999 line range. Therefore, I don't think we need to expose an editor setting for this. A lower value would save a tiny bit of horizontal space in projects that use lots of small scripts, but you'd reintroduce the issue with layout shifts on script change as soon as you even have one script with 100+ lines of code.

Copy link
Member

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am neutral on the actual property itself. I think it makes sense, but I've never seen it being suggested until now. I approve for the editor's usability.

@akien-mga akien-mga modified the milestones: 4.x, 4.6 Nov 1, 2025
@akien-mga
Copy link
Member

Adds a line_numbers_min_digits property to CodeEdit. It defaults to 1 to be compatible with existing projects.

IMO this would be fine to default to 3 too. It changes behavior slightly, but users who want to keep the former behavior can set the property to 1 themselves. I think the default behavior should be to minimize these jumps.

@Mickeon
Copy link
Member

Mickeon commented Nov 1, 2025

Alright then, but let's remember to document it in the migration guide.

@timothyqiu
Copy link
Member Author

timothyqiu commented Nov 2, 2025

How about this?

When a node is created in the editor (e.g., via the Create dialog), assign more appropriate values to the node's properties. This ensures existing projects remain unaffected.

For example, this method is used to assign properties marked with PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT a new resource instance after the node / resource is created in the editor. We can repurpose / rename it to also set saner default values.

void EditorData::instantiate_object_properties(Object *p_object) {
ERR_FAIL_NULL(p_object);
// Check if any Object-type property should be instantiated.
List<PropertyInfo> pinfo;
p_object->get_property_list(&pinfo);
for (const PropertyInfo &pi : pinfo) {
if (pi.type == Variant::OBJECT && pi.usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) {
Object *prop = ClassDB::instantiate(pi.class_name);
p_object->set(pi.name, prop);
}
}
}

Since these classes and their "default values" are listed in a centralized location, it also acts as a tracker. It'll be easier to make them the default in the next compat-breaking release.

@timothyqiu timothyqiu force-pushed the line-number-min-chars branch from 175d819 to 990889f Compare November 3, 2025 10:18
@timothyqiu
Copy link
Member Author

Updated and just changed the default to 3.

@Repiteo Repiteo merged commit 2132ba8 into godotengine:master Nov 3, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 3, 2025

Thanks!

@timothyqiu timothyqiu deleted the line-number-min-chars branch November 4, 2025 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants