-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Code Block Guidelines to Script Editor & CodeEdit #65757
base: master
Are you sure you want to change the base?
Conversation
0a96b46
to
c52be7d
Compare
I'd prefer this to be enabled by default, as it matches how other text editors look by default more closely. |
I wanted to avoid alienating existing Godot users but if people love this a lot I have no problem turning this on by default! |
fd032b6
to
564bea3
Compare
How do the branches in the tree-like structure look when there's lots of nesting or when the editor is zoomed out? |
Anyway, we have an editor setting to display spaces as little points, off by default. A setting to display tabs, right next to that setting, would be super fitting. I don't think it should be a toggle between displaying tabs or displaying this tree-like thingy, some might want both, after all tabs are valid whitespaces too. |
Major sidenote: While this is heavily inspired by #20725 and #38833, it's not the same, although in practice it accomplishes the same thing, just with more "finesse". Those PRs were aiming to do what Visual Studio Code does, for example. Those implementations suit more when "open and close" brackets are involved, because the indent line would directly connect between the top and bottom brackets. |
I mean like the uneven dictionary example, if there are 6+ of these little branches and the text is zoomed out, wouldn't they slip out on top? |
There's an hard cap, at which point they just start stacking on top of one another (this should be proportional to the font size but it currently isn't yet, so technically yes, they do slip up right now at a small size) |
Thanks for picking this feature again, it's a great one to have.
|
With these preferences, it sounds like you'd much love if that is how indents were symbolised (like #65757 (comment)), instead. I like the way the PR currently looks, minus minor tweaks, and one could argue it's a matter of getting used to, but I will keep this in mind. Perhaps theme overrides could be used for the minor adjustments. |
@Mickeon symbolized indents could be a good idea BUT for a follow-up PR |
564bea3
to
33b1ef2
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of the horizontal lines. Could turn it into an enum
if there is a want for both styles.
This will not work if folding
is disabled, whereas it should be independent of that setting, we can pull out the code into private methods if needs be.
scene/gui/code_edit.cpp
Outdated
const double v_scroll = get_v_scroll(); | ||
const double h_scroll = get_h_scroll(); | ||
Vector<int> block_ends; | ||
for (int i = 0; i < get_line_count(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only draw what is on screen, rather then the entire text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this would require caching block start and endings whenever the text is changed and starting from there. The change may take a while to implement, but it has potential to make the additional "extra highlight" of the code block the caret is in more reliable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can certainly calculate from line 0 to end of the visible viewport, so long as we don't make any unnecessary calls to the RenderingServer
. TextEdit
already does quite a lot around this. Will probably require some form of benchmarking to see if it's worth caching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what you're suggesting for now is to at least make sure that the RenderingServer doesn't draw guidelines that cannot be seen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah whilst stopping calculation at the end of the visible viewport rather then all the way to the end of the script. I think caching will be faster, but better to benchmark first to make sure the extra complexity is worth it.
I find it pretty nice. Godot doesn't have your classic closing brackets at the end of a block, which makes it a bit difficult to discern, were it not for the change of indentation. It could also be a matter of getting used to, but unfortunately you're not the only one expressing this opinion. A shame. Without it, and all of the detection required to figure out a code block, this PR would be little to no different than making all indents look like semi-transparent columns (like the "ancestor PRs", and Visual Studio Code do). I could make it an enum. Perhaps, in the future, more styles could be added if requested (e.g. Visual Studio uses dashed lines).
This is true. This would require having CodeEdit detect code blocks beforehand and caching them, which could go hand-to-hand with the change required here #65757 (comment). |
Done the drawing optimisation. All that is missing is #65757 (review) which, for the gutters thing, may possibly prove tricky and admittedly janky. EDIT: |
d38de7b
to
34ec895
Compare
f2ddcb5
to
93cf9af
Compare
47831b0
to
759f8ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested out the draw performance in CodeEdit
alone, currently way to slow. 300ms slower on a ~5.5k line script. Even at 2k lines it takes 50ms.
Might be worth seeing if there are other places to optimise, otherwise looks like it will require some form of caching.
759f8ea
to
dcf10ee
Compare
Add `code_block_guidelines_style` in CodeEdit. When set, lines appear between the start and end of a foldable code block. This line is appropriately indented. Multiples guides may stack on top of each other, within reason, and prefer to connect to a bottom parenthesis. The colour of the guide line becomes _slightly_ more noticeable when the caret is inside the code block: It can be switched between "None", "Line" and "Line (Close)". This feature is set to "None" by default for the Editor. Its colors can be customised in the Editor Settings.
dcf10ee
to
2fa1b34
Compare
I don't think there is much else to optimise. The issue right now is that the code blocks themselves are re-calculated every draw call. So maybe this feature may have to wait until CodeEdit can actually detect and store code blocks on its own (and not just code folding)? |
Can we just modify the indent guidelines to use vertical lines instead of chevrons and not have the horizontal lines drawn? This should be much faster while suiting most use cases. The horizontal lines can be left for a future PR as they're not essential. |
@Calinou If I were to implement that in another PR, for the time being, should it be based on the indent amount (so that both spaces and tabulations will display them) or should it be outright replacing the tabulation symbol? |
I think it should be based on the indent amount, so that trailing whitespace does not show indent guides. This will also make indentation look the same when using spaces for indentation, which matches the behavior in most other editors. (We could display invisible characters when selected to make troubleshooting easier, like in VS Code.) |
Point2 point_start = Point2(indent_guide_x, row_height * visible_indent_start); | ||
Point2 point_end = Point2(indent_guide_x, row_height * visible_indent_end - offset_y); | ||
|
||
RenderingServer::get_singleton()->canvas_item_add_line(ci, point_start, point_end, color, 1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be a bit naive, but won't we get a performance boost by doing this at once with canvas_item_add_multiline()
?
Why was this never merged? |
It hasn't been approved and still has feedback to address |
The PR is pretty old so it would be better be done from scratch. It's also not really performant. These are both because there was no existing methods to accomplish this PR, and little to no caching in between. Both of these may no longer be a problem now (?) |
It would be lovely if you shared your EditorPlugin as a proof-of-concept, perhaps in the Asset Library as well. |
Still on pending at Asset Library, but repo is here It's a bit buggy, in GDScript not available |
Resurrects #20725, and #38833 somewhat.
In this PR,
code_block_guidelines_style
is added in CodeEdit. When set, lines appear between the start and end of a foldable code block. The line is appropriately indented.Multiples guidelines may stack on top of each other, within reason, and prefer to connect to a bottom parenthesis.
The colour of the guideline becomes slightly more noticeable when the caret is inside the code block:
It can be switched between "None", "Line" and "Line (Close)". This feature is set to "None" by default for the Editor. Its colors can be customised in the Editor Settings. (good luck doing that without making master crash).
Feedback is absolutely welcome.
Optional Todos(?)/Notes: