-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Code folding #14593
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
Open
DubrovinEIu
wants to merge
17
commits into
helix-editor:master
Choose a base branch
from
DubrovinEIu:code-folding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code folding #14593
+7,115
−401
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added the new method `update_positions_with_helper` for `ChangeSet` Added the new module `text_folding::transaction`
Created RopeSlice extension RopeSliceFoldExt Created functions nth_prev_folded_grapheme_boundary, nth_next_folded_grapheme_boundary
Modified movement functions: move_horizontally move_vertically move_vertically_visual word_move move_paragraph
Added fold decoration to display folded lines. Embedded fold updating and removal when applying a transaction and selection movement.
Needed to fold comments.
Replaced CharMatcher with GraphemeMatcher. Therefore the line ending search utilizes the regular function of char searching. The function "find_char_line_ending" has been removed.
commands list: extend_line extend_line_above extend_line_below open_below goto_last_line extend_to_last_line paste_after
A new attribute has appeared - "fold_textobjects". It determines which text objects will be folded when a document is opened. When a split occurs, the folds are copied.
would it make sense to add toggle-fold command too? |
Added the command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #1840
Screencast.From.2025-10-13.16-37-20.mp4
New user-level items
Introduced text folding commands:
fold
(default key-mapping iszf
)unfold
(default key-mapping iszF
):fold
:unfold
Added the field
fold_textobjects
toeditor
(default list is empty, try to add some of the following available textobjects: class, function, comment)Added the style
ui.virtual.fold-decoration
Commands that ignore folded text
The following commands behave as if there is no folded text.
Move word:
move_next_word_start
move_prev_word_start
move_prev_word_end
move_next_word_end
move_next_long_word_start
move_prev_long_word_start
move_prev_long_word_end
move_next_long_word_end
move_next_sub_word_start
move_prev_sub_word_start
move_prev_sub_word_end
move_next_sub_word_end
Extend word:
extend_next_word_start
extend_prev_word_start
extend_next_word_end
extend_prev_word_end
extend_next_long_word_start
extend_prev_long_word_start
extend_prev_long_word_end
extend_next_long_word_end
extend_next_sub_word_start
extend_prev_sub_word_start
extend_prev_sub_word_end
extend_next_sub_word_end
Move paragraph:
goto_prev_paragraph
goto_next_paragraph
Find char:
find_till_char
find_next_char
extend_till_char
extend_next_char
till_prev_char
find_prev_char
extend_till_prev_char
extend_prev_char
Extend line:
extend_line
extend_line_above
extend_line_below
Open:
open_below
To last line:
goto_last_line
extend_to_last_line
Paste:
paste_after
Goto TS object:
NOTE: the commands skip only entire folded TS objects
goto_next_function
goto_prev_function
goto_next_class
goto_prev_class
goto_next_parameter
goto_prev_parameter
goto_next_comment
goto_prev_comment
goto_next_test
goto_prev_test
goto_next_xml_element
goto_prev_xml_element
goto_next_entry
goto_prev_entry
To word:
goto_word
extend_to_word
Actions that create folds
Split:
NOTE: commands copy folds to the new view
hsplit
vsplit
:hsplit
:vsplit
File:
NOTE: when a new buffer is opened the specified text objects in the field
fold_textobjects
are folded.file_picker
file_explorer
hx -- src/main.rs
will open the file and fold the text objects defined infold_textobjects
)Accompanying changes
CharMatcher
withGraphemeMatcher
.For more details, check the commit f320270.
TextObjectQuery::capture_nodes_any
(issue "Match around comment" not selecting full commented block made of line comments #11087)Also, the fix was pushed as PR Fixed matching around comment #14591.
Speech
Fold primitives have been implemented, including all components related to rendering and text processing.
However, user-items are currently in draft form. Perhaps someone could suggest more convenient commands. Therefore, the documentation has not yet been written.
I suggest applying this PR in order for master-users to test the new feature and open an issue related to text folding.
Check the commit history for details. I have been trying to make it readable, consistent, and organized.
Start by reading the top-level documentation of the
text_folding
module.Planned improvements
Enable language-specific text folding.