-
-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
Code Folding #12950
Code Folding #12950
Conversation
... wow
…On Wed, Nov 15, 2017 at 2:05 PM, Ian ***@***.***> wrote:
Script Editor Code Folding
Fixes #2732 <#2732>
Allows collapsing/expanding code chunks
Code chunks are lines of text where the next line has more whitespace than
the first
[image: foldable]
<https://user-images.githubusercontent.com/10054226/32849350-e428a502-c9fc-11e7-9fbf-fad7e44d71fb.gif>
Implementation details:
TextEdit Text Line can now be hidden
Hidden lines are not drawn
Adds fold gutter similar to breakpoint gutter
Uses icon forward for lines that can fold and icon collapse for folded
lines. Mainly because I couldn't find anything better.
Editor bool setting Text Editor/Line Numbers/Code Folding
whitespace level is the number of ' ' spaces and '\t' tabs that come
before any other character. '#' comments at the beginning of the line are
ignored.
Property bool hiding_enabled enables/disables all code hiding. must be
enabled for all code folding features.
TextEdit set_line_hidden(int line, bool enabled) sets the hidden state of
a line.
TextEdit can_fold(int line) determines whether a line can be folded. The
whitespace level of the next must be higher than the first line
TextEdit fold_line(int line) folds this line. This just sets all lines
following this one to hidden if they are empty or has more whitespace.
trailing empty lines are unhidden.
TextEdit unfold_line(int line) unhides all lines below this line until
the next nonhidden line
TextEdit is_folded(int line) returns true if this line is not hidden and
the next line is hidden
Searching unfolds line with found text.
Edit menu and context menu items to fold and unfold line
Default shortcuts for fold line is Alt+Left, unfold line is Alt+Right
Smooth scrolling over hidden lines and page up/page down works (smooth
scrolling down over large sections of unhidden code could be better though)
Moving a line up/down unfolds hidden section
Centering viewport to cursor takes into account hidden lines
------------------------------
You can view, comment on, or merge this pull request online at:
#12950
Commit Summary
- TextEdit code folding
File Changes
- *M* editor/code_editor.cpp
<https://github.com/godotengine/godot/pull/12950/files#diff-0> (6)
- *M* editor/editor_settings.cpp
<https://github.com/godotengine/godot/pull/12950/files#diff-1> (1)
- *M* editor/plugins/script_text_editor.cpp
<https://github.com/godotengine/godot/pull/12950/files#diff-2> (64)
- *M* editor/plugins/script_text_editor.h
<https://github.com/godotengine/godot/pull/12950/files#diff-3> (5)
- *M* scene/gui/text_edit.cpp
<https://github.com/godotengine/godot/pull/12950/files#diff-4> (449)
- *M* scene/gui/text_edit.h
<https://github.com/godotengine/godot/pull/12950/files#diff-5> (32)
Patch Links:
- https://github.com/godotengine/godot/pull/12950.patch
- https://github.com/godotengine/godot/pull/12950.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#12950>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z2-ArNIrQ8zdiX-Fu-OnpKWQDUMFnks5s2xnpgaJpZM4QfQiW>
.
|
String tmp2 = tx->get_line(line2); | ||
tx->set_line(line2, tmp); | ||
tx->set_line(line1, tmp2); | ||
// static void swap_lines(TextEdit *tx, int line1, int line2) { |
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 guess this can be removed.
@Paulb23 and others will probably want to give this a check |
6d0ddcf
to
48c6a78
Compare
I think code chunks should also be determined by curly braces. This is needed for C-like languages like C# and for dictionaries in GDScript. |
Holly cow! :o |
Great job, very nice :) |
Nice job! Apologies for the wall of bullet points I don't want to scare you off :P But some feedback after playing around with it:
Bugs:
Extra:
|
@@ -1447,7 +1471,7 @@ void ScriptTextEditor::_color_changed(const Color &p_color) { | |||
code_editor->get_text_edit()->set_line(color_line, new_line); | |||
} | |||
|
|||
void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) { | |||
void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, int p_fold_state) { |
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.
Would be better if this was a bool, as it can't be half folded.
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.
Agreed.
scene/gui/text_edit.cpp
Outdated
@@ -3731,6 +3862,8 @@ void TextEdit::_update_caches() { | |||
cache.line_spacing = get_constant("line_spacing"); | |||
cache.row_height = cache.font->get_height() + cache.line_spacing; | |||
cache.tab_icon = get_icon("tab"); | |||
cache.folded_icon = get_icon("Collapse", "EditorIcons"); | |||
cache.can_fold_icon = get_icon("Forward", "EditorIcons"); |
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.
Could probably create new icons for code folding, or at least keep them separate by adding them here
scene/gui/text_edit.cpp
Outdated
if (!is_hiding_enabled()) | ||
return false; | ||
if (!draw_fold_gutter) | ||
return false; |
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.
It should still be possible to fold lines even if the gutter is disabled, could draw a marker on / behind the line to denote that its folded?
scene/gui/text_edit.cpp
Outdated
void TextEdit::set_hiding_enabled(int p_enabled) { | ||
hiding_enabled = p_enabled; | ||
if (!hiding_enabled) | ||
set_draw_fold_gutter(false); |
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.
Same here, hiding lines and the fold gutter should be unlinked.
scene/gui/text_edit.h
Outdated
@@ -325,6 +334,8 @@ class TextEdit : public Control { | |||
|
|||
int get_row_height() const; | |||
|
|||
// int _get_fold_offset(int p_line_from, int p_line_to) const; |
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.
Can be removed?
Awesome work! I think the icons should be swapped. It should be (Edit: Whoops, didn't see that Paulb23's already commented on this topic.) |
Love this! ditto on Noshyaar and Paulb's remark, icons should be the other way around :) |
48c6a78
to
0bf0e28
Compare
Thanks for all the great feedback! |
Is it working with word wrap? (assuming there is support for it, I know by experience the features might overlap, because visible lines and actual lines are no longer the same thing) |
Just a cosmetic suggestion. The arrows are big in my taste. Tiny triangles, like in the scene dock, maybe better. |
The arrows would be less intrusive if they had a slightly darker tone or
were semi transparent. I dont mind the size myself
…On 16 Nov 2017 14:05, "DriNeo" ***@***.***> wrote:
Just a cosmetic suggestion. The arrows are big in my taste. Tiny
triangles, like in the scene dock, maybe better.
Anyway it's a very nice improvement. Sorry if my english is rough.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#12950 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGMbVX9bCN5Z9Is4X2vLGVWScNKDNCVJks5s3EEtgaJpZM4QfQiW>
.
|
@blurymind yeap. @djrm the professional will take care of it, I think. |
scene/gui/text_edit.cpp
Outdated
void TextEdit::set_draw_fold_gutter(bool p_draw) { | ||
draw_fold_gutter = p_draw; | ||
if (draw_fold_gutter) | ||
set_hiding_enabled(true); |
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.
Missed this to disconnect gutter from folding :D
0bf0e28
to
4a98505
Compare
Fixes for smooth scrolling, last line folded, and others. Cursor now shape changes over icons. |
Great work, scrolling over the hidden lines feel a lot better! I noticed a few problems when "Scroll Past End Of File" is disabled and "Smooth Scrolling" is enabled.
|
64a0109
to
18df45d
Compare
18df45d
to
514392c
Compare
I am a fan of the new look. Really looks like it belongs now. I hope this makes it into beta. |
I think the folding icons are still too wide... |
there are two arrow icons that are smaller, and would be better in this case |
514392c
to
1e59169
Compare
Updated to use the smaller icons. Thanks! |
bool TextEdit::is_folded(int p_line) const { | ||
|
||
ERR_FAIL_INDEX_V(p_line, text.size(), false); | ||
if (p_line + 1 >= text.size() - 1) |
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.
This line should be p_line + 1 >= text.size()
else you can't unfold the last line.
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.
The last line isn't able to be folded. I determine whether a line is folded by seeing if this line isn't hidden and the next one is hidden, so the next line needs to be less than or equal to text.size() - 1
for that check.
There are few more scrolling bugs:
|
I vote to have this merged for the feature freeze asap and the remaining trivial bugs closed later. |
Yes please :) |
Alright, let's merge :) Please open issues for the known issues mentioned above which haven't been addressed yet. |
Script Editor Code Folding
Fixes #2732
Allows collapsing/expanding code chunks
Code chunks are lines of text where the next line has more whitespace than the first
Implementation details:
TextEdit Text Line can now be hidden
Hidden lines are not drawn
Adds fold gutter similar to breakpoint gutter
Uses icon forward for lines that can fold and icon collapse for folded lines. Mainly because I couldn't find anything better.
Editor bool setting
Text Editor/Line Numbers/Code Folding
whitespace level is the number of ' ' spaces and '\t' tabs that come before any other character. '#' comments at the beginning of the line are ignored.
Property bool hiding_enabled enables/disables all code hiding. must be enabled for all code folding features.
TextEdit set_line_hidden(int line, bool enabled)
sets the hidden state of a line.TextEdit can_fold(int line)
determines whether a line can be folded. The whitespace level of the next must be higher than the first lineTextEdit fold_line(int line)
folds this line. This just sets all lines following this one to hidden if they are empty or has more whitespace. trailing empty lines are unhidden.TextEdit unfold_line(int line)
unhides all lines below this line until the next nonhidden lineTextEdit is_folded(int line)
returns true if this line is not hidden and the next line is hiddenSearching unfolds line with found text.
Edit menu and context menu items to fold and unfold line
Default shortcuts for fold line is Alt+Left, unfold line is Alt+Right
Smooth scrolling over hidden lines and page up/page down works (smooth scrolling down over large sections of unhidden code could be better though)
Moving a line up/down unfolds hidden section
Centering viewport to cursor takes into account hidden lines