+467
Under review

Code Folding

Alexander Blach (Developer) 14 years ago updated 4 weeks ago 22 5 duplicates
See http://en.wikipedia.org/wiki/Code_folding

Allow the user to selectively hide and display sections of a currently-edited file.
Duplicates 5
+10
That would be really great because of the ipads screen size!
+2
this would be extremely helpful when editing XML files
I edit large yaml files that it would be very helpful to be ale to fold. Thank you for a great app.
That's really important feature for every code editor and it will be just great if you implement it.
That would be great when editing JavaScript too if you could have minus symbols next to the line number when braces are found so that you could click the minus to fold the code between matching braces and then if needed click a plus button to re show the code. Doing it based on the current language's idea of a code unit/group (such as braces in C or JavaScript) would allow you to fold loops, if statements, switch statements or even complete functions which would be great.
+1 here too... jQuery Mobile sites work best when all "pages" are incorporated into a single file (core page transition animations etc). when on the desktop I use code folding to fold the sections(pages) I am not working on.. And just view the current page. 
Much agreed on this, especially due to the size of mobile screens. Textastic has always come up with innovative solutions— specifically thinking of the swipe-to-symbol keyboard row, so something along those lines would be fantastic.
-1
I would really like this feature as well.
It's a pretty basic feature for most code editors - though with that said, most editors have a terrible 'folder' in that it does not fold certain functions accurately.
I am working in Lua (Corona SDK) and it would be very beneficial to have the option to fold my functions and conditional statements.

Please update Textastic to include this feature. 
+3
If you add folding, I'd like to suggest having an automatic mode to fold All, or all those outside of the current view.
+2
can you add this feature to mac version too. please

Visual studio does this an I really miss it
Some love scrolling, some others don't :) that would be a great feature (one more, yes!)
Looks like this feature request has been out there a LONG time. And best I can tell it isn't available yet. Is there a plan for it in the near future? At least, by mortal human measure.
Ideally, the folding rules could be read in from tmbundles to work with any language.
please add code collapsing feature, it will greatly help to deal with code with many lines
+3

Like that, may be show an option «Show folding panel» (like «Show line numbers»)

Image 160

+7

Love the app, but this is a big pain point for me. Is there any update on this request?

how’re we making out on this request? It’s been an amazing feature option for over a decade now lol

in fact… here’s most of the code needed… I’ll be making a plug-in for jailbroken ios if you guys aren’t going to implement it

Feel free to do that. There would be much more needed to implement this efficiently and for all supported languages. 


Just running a regex on the whole text on potentially every keystroke would not be how I'd approach this. 


Also, one of the biggest problems for me is how to do a touch-friendly UI for expanding/collapsing and have big enough touch targets on small iPhone screens while not interfering with text selection.

#import <objc/runtime.h>

#import <Foundation/Foundation.h>

%hook MyTextEditorClass

// Helper function to identify foldable sections in Objective-C++ code

- (NSArray *)findFoldableSectionsInText:(NSString *)text {

NSMutableArray *foldableSections = [NSMutableArray array];

// Regular expressions to detect Objective-C and C++ blocks

NSString *objcClassRegex = @"@interface\\s+(\\w+)\\s*\\{";

NSString *cppClassRegex = @"class\\s+(\\w+)\\s*\\{";

NSString *functionRegex = @"(\\w+)\\s+\\w+::?\\w*\\s*\\(.*\\)\\s*\\{";

NSError *error = nil;

// Detect Objective-C classes

NSRegularExpression *objcClassExpr = [NSRegularExpression regularExpressionWithPattern:objcClassRegex options:0 error:&error];

[objcClassExpr enumerateMatchesInString:text options:0 range:NSMakeRange(0, [text length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {

[foldableSections addObject:@{@"type": @"objc_class", @"range": NSStringFromRange(result.range)}];

}];

// Detect C++ classes

NSRegularExpression *cppClassExpr = [NSRegularExpression regularExpressionWithPattern:cppClassRegex options:0 error:&error];

[cppClassExpr enumerateMatchesInString:text options:0 range:NSMakeRange(0, [text length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {

[foldableSections addObject:@{@"type": @"cpp_class", @"range": NSStringFromRange(result.range)}];

}];

// Detect functions

NSRegularExpression *functionExpr = [NSRegularExpression regularExpressionWithPattern:functionRegex options:0 error:&error];

[functionExpr enumerateMatchesInString:text options:0 range:NSMakeRange(0, [text length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {

[foldableSections addObject:@{@"type": @"function", @"range": NSStringFromRange(result.range)}];

}];

return foldableSections;

}

// Hook into the method that renders text (or any method that handles text view updates)

- (void)renderTextWithFolding {

NSString *text = [self getText]; // This method should retrieve the text content from the editor view

// Find foldable sections

NSArray *foldableSections = [self findFoldableSectionsInText:text];

// For each foldable section, we could either hide it or show a "fold" button in the UI

for (NSDictionary *section in foldableSections) {

NSString *type = section[@"type"];

NSRange range = NSRangeFromString(section[@"range"]);

// Example: For foldable class blocks, we might hide the content or add a UI fold button

if ([type isEqualToString:@"objc_class"] || [type isEqualToString:@"cpp_class"]) {

[self addFoldButtonForRange:range];

} else if ([type isEqualToString:@"function"]) {

[self addFoldButtonForRange:range];

}

}

}

// Helper function to add a fold button (UI interaction logic)

- (void)addFoldButtonForRange:(NSRange)range {

// Assuming you have access to the text view/UI, add a button or visual cue for the fold action

// This could involve adding a small "v" icon or something to represent folding

// Example: insert a UI button for collapsing/expanding at a specific position

[self insertFoldButtonAtPosition:range.location];

}

// Helper function to insert a fold button at a specific position

- (void)insertFoldButtonAtPosition:(NSUInteger)position {

// Insert a fold button in the UI at the given text position (this will depend on how your app is rendering text)

// This might involve adding a button or some UI element at the position in the text view

}

%end