Quoting Randy Kramer <[EMAIL PROTECTED]>: > So: > > I need to have a way to mark text in the textBuf as being folded. (This is > in addition to the need to keep track of areas of text which can be > folded--that part I intend to do with rangesets or a variation of > rangesets (although, in this new approach, rangesets won't need to deal > with zero length ranges).)
Yes, you can't fold nothing. > One way to mark currently folded text in the textBuf could be using the > 32-bit Style mask which, based on this line of code in textDisp.c: > > textBuffer *styleBuf = textD->styleBuffer; > > ..., is like a parallel textBuf(fer) storing the style information for each > character of text in the textBuf? That's right: each byte matches a style index, the bottom 8bits of the style mask given below. Beware though: if you haven't applied highlighting, you get no style buffer. The style index gives you a style record, saying something like "Comment style", foreground=grey, background=<none>, bold font, italic font. That's used to draw the corresponding matching text. > ... I would consider using an additional bit (or 2, > more on that later) to add a "hidden for folding" flag to the 32-Bit Style > mask: > > > /* If you use both 32-Bit Style mask layout: > > Bits > > +----------------+----------------+----------------+----------------+ > > |1F1E1D1C1B1A1918|1716151413121110| F E D C B A 9 8| 7 6 5 4 3 2 1 0| > > |3130292827262524|2322212019181716|151413121110 9 8| 7 6 5 4 3 2 1 0| > > +----------------+----------------+----------------+----------------+ > > | r r| r r r r b b b b| b b b b H 1 2 F| s s s s s s s s| > > +----------------+----------------+----------------+----------------+ > > The text display widget would then be modified so that if text was marked > as "hidden for folding", it would not be displayed. No: the style buffer doesn't give this whole style value. It's built on the fly (see styleOfPos()) from the style buffer entry of a position, along with other rendering factors: whether this is the end of line (F for "fill to the right"), primary/secondary selection (1, 2), bracket-matching highlighting (H), character-value-based backlighting (b) and rangeset index. All this is broken down again (in drawString()) how best to draw the next segment of text. For folding, though, you're not going to draw normal buffer text (you may want to draw a placeholder, for which a bit in the style mask might well be appropriate). Note (in redisplayLine()) that drawString() is called with a length of similarly-styled text. This would be, I reckon, where a look at the folded ranges, would tell you where a fold-marker (or nothing!) should be drawn. In other words, a folded fold is not a style; it just never gets displayed. In this way you don't have to scan every character of folded text just to find where visibility gets turned on again. You must, however, account for missing character positions and line numbers, and manage column positions and mouse-position-to-text-position mapping given these jumps in the position sequence. > Another thing that the styleBuf would then be used for is, generally > speaking, navigation. For example, when we needed to move the cursor, for > example, down one line, the navigation routines would be modified so that > they checked the styleBuf and ignored all characters that were flagged > "hidden for folding". Same argument. Cheers, Tony -- NEdit Develop mailing list - [email protected] http://www.nedit.org/mailman/listinfo/develop
