Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4035292
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:04:46+00:00 2026-05-20T12:04:46+00:00

I use the BraceFoldingStrategy by Daniel Grünwald: public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document) { List<NewFolding> newFoldings

  • 0

I use the BraceFoldingStrategy by Daniel Grünwald:

public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
        {
            List<NewFolding> newFoldings = new List<NewFolding>();

            Stack<int> startOffsets = new Stack<int>();
            int lastNewLineOffset = 0;
            char openingBrace = this.OpeningBrace;
            char closingBrace = this.ClosingBrace;
            for (int i = 0; i < document.TextLength; i++) {
                char c = document.GetCharAt(i);
                if (c == openingBrace) {
                    startOffsets.Push(i);
                } else if (c == closingBrace && startOffsets.Count > 0) {
                    int startOffset = startOffsets.Pop();
                    // don't fold if opening and closing brace are on the same line
                    if (startOffset < lastNewLineOffset) {
                        newFoldings.Add(new NewFolding(startOffset, i + 1));
                    }
                } else if (c == '\n' || c == '\r') {
                    lastNewLineOffset = i + 1;
                }
            }
            newFoldings.Sort((a,b) => a.StartOffset.CompareTo(b.StartOffset));
            return newFoldings;
        }

This works as expected but one issue is remaining
enter image description here

There is always a last – icon on the last brace. I tried to remove that,but when I look at the list newFoldings I can see that there are only 3 foldings there. So where is the fourth coming from?

EDIT

According to Daniel Grünwald the problem is that I have to be using to different folding managers. However I can’t find any statement in my initialisation code where I set a second FoldingManager. Maybe any hints?

private void textEditor_Loaded(object sender, RoutedEventArgs e)
{
   LoadSourceCode();
   textEditor.Background = Brushes.Green;  
   textEditor.IsReadOnly = true;    
   textEditor.ShowLineNumbers = true;

   using (Stream s = this.GetType().Assembly.GetManifestResourceStream("Prototype_Concept_2.View.Layouts.CustomHighlighting.xshd"))
   {
      using (XmlTextReader reader = new XmlTextReader(s))
      {    
         textEditor.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
      }
    }

   (textEditor.TextArea as IScrollInfo).ScrollOwner.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
   (textEditor.TextArea as IScrollInfo).ScrollOwner.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;

   FoldingManager foldingManager = FoldingManager.Install(textEditor.TextArea);    
   BraceFoldingStrategy foldingStrategy = new BraceFoldingStrategy();    
   foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);

   TextArea txt = textEditor.TextArea;    
   ObservableCollection<UIElement> margins = txt.LeftMargins;

   foreach (UIElement margin in margins)    
   {    
      if ((margin as FoldingMargin) != null)
      {
         Contacts.AddPreviewContactDownHandler(margin as FoldingMargin, OnDown);
      }
   }

   Main.Children.Remove(textEditor);
   ScrollHost.Width = textEditor.Width;    
   ScrollHost.Height = textEditor.Height;    
   ScrollHost.Content = textEditor;
   textEditor.Background = Brushes.Transparent;
   ScrollHost.Background = Brushes.Transparent;    
}

EDIT 2

I checked that the currently installed FoldingManager has 3 foldings, but I still don’t know where the fourth folding is defined.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:04:47+00:00Added an answer on May 20, 2026 at 12:04 pm

    The simple BraceFoldingStrategy is in my experience too buggy to be really useful. There are multiple problems like broken indenting (I was getting extra folding margin every time tab was changed in AvalonDock – it may have been the very same problem you are facing), braces in strings being parsed as normal braces (it is even able to pair a string { with real }) etc., so I decided to drop it.

    Real code folding support requires real lexical (or better – syntactic) analysis information, use that if you can (you can find usage example in SharpDevelop 4.0 sources), but you have to have access to a parser for the language you are writing the editor for for that.

    I think code folding is not IDEs most important feature and I personally seldom ever use it (only with really big file with regions/large methods).

    I know this is not the answer you are hoping for (I would post this as a comment if it the post didn’t exceed the length limit). I will keep watching this (and hoping somebody provides a real answer) though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,
use Control::CLI; $cli = new Control::CLI('SSH'); $cli->connect(Host=>'10.10.10.10',Username=>'user',Password=>'pwd'); $cli->waitfor('>'); $cli->print('Show XXXXXXXXXXXXXXXXXXXX| grep Active'); @f=$cli->waitfor('>'); print
use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( $url ); say $mech->text; How could I
use strict; use Time::HiRes qw[gettimeofday tv_interval]; my $start_index = int(rand(50))+100;#this value is arbitrary for
Use Case: I have some repo on GitHub, someone forked it and added new
Use default: <input type=radio name=restype value=resdef onfocus=document.getElementById('resupload').disabled = true; document.getElementById('resadres').disabled = true; checked=checked /><br
use Parallel::ForkManager; use LWP::Simple; my $pm=new Parallel::ForkManager(10); our $a =0; @LINK=( 10,203, 20, 20
Use new MediaPlayer by Yahoo. Content parse automatic - greate, but I use ajax
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
Use case: A does something on his box and gots stuck. He asks B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.