1. Routine folding: display and cursor movement issues
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 30, 2005
- 482 views
I've written some (experimental) code to implement folding. I just wonder if I am "doing it right" and/or if there is "a better way". I can't seem to google proper on this either ;-((. To begin with, when, say, a routine from line 8 to 12 inclusive is folded, I add an entry to the bookmark table (another goodie planned for 0.2.2), of {FOLD,8,12}. Easy. I also have code to update this as lines are inserted/deleted/etc. The "internal" struggle (as in conceptually) is how I display from line 1 to line 30 normally, but line 1 to 34 with a fold mark against line 8, and more critically how I cursor up/down from line 8 to line 13 and vice versa, as well as paging up and down, and opening the editor with eg the cursor on line 34 in the above described scenario - so I need to start with line 1 of display as line 1of the file, not line 4. (I plan to retain folds, btw). So my question is: how would you store the (run-time) info: a) a really packed table that is small but costs alot to scan, (in practice I probably have to keep that anyway), b) a full-on 1..length(filetext[currfile]) flag array (or two) that scans really easy but costs an arm and a leg to update, c) an array 1..visible lines (by default 1..len(f[c]), with significant overheads as per or perhaps even worse than b, d) some other scheme? Hopefully, Pete
2. Re: Routine folding: display and cursor movement issues
- Posted by Al Getz <Xaxo at aol.com> Aug 30, 2005
- 453 views
Pete Lomax wrote: > > > I've written some (experimental) code to implement folding. I just > wonder if I am "doing it right" and/or if there is "a better way". > > I can't seem to google proper on this either ;-((. > > To begin with, when, say, a routine from line 8 to 12 inclusive is > folded, I add an entry to the bookmark table (another goodie planned > for 0.2.2), of {FOLD,8,12}. Easy. I also have code to update this as > lines are inserted/deleted/etc. > > The "internal" struggle (as in conceptually) is how I display from > line 1 to line 30 normally, but line 1 to 34 with a fold mark against > line 8, and more critically how I cursor up/down from line 8 to line > 13 and vice versa, as well as paging up and down, and opening the > editor with eg the cursor on line 34 in the above described scenario > - so I need to start with line 1 of display as line 1of the file, not > line 4. (I plan to retain folds, btw). > > So my question is: how would you store the (run-time) info: > a) a really packed table that is small but costs alot to scan, > (in practice I probably have to keep that anyway), > b) a full-on 1..length(filetext[currfile]) flag array (or two) > that scans really easy but costs an arm and a leg to update, > c) an array 1..visible lines (by default 1..len(f[c]), with > significant overheads as per or perhaps even worse than b, > d) some other scheme? > > Hopefully, > Pete > > Hi there Pete, There are probably a ton of ways to do this right? One of the simplest is probably this: Assuming you hold the lines in a nested sequence like: { "line 1", "line 2", "......" } Let's say you want to show lines 1 to 30 normally, but lines 31 to 40 you wish to show 'folded'. Let's also assume you're satisfied with the marker "<->" to show a folded section. 1. Move lines 31 through 40 into a buffer with the same structure as the nested sequence above repeated n times. This is easy of course. Note bookmarks adjust={31,40-31+1} or whatever. You'll also have to keep a table of what goes where for later reconstruction for other operations such as file saves. 2. Insert a new line 31 as #FF&"<->" (first char=#FF). 3. Modify the display routine to look for 1st char=#FF. 4. Of course you also have to modify other routines that expect the full text, such as clipboard operations, file save, etc. 5. To reconstruct the text simply replace line 31 with the text saved to location [31] of the buffer. 6. While your at it, you may wish to modify the routines so that you can add other flags too as your program progresses. Some ideas. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
3. Re: Routine folding: display and cursor movement issues
- Posted by Greg Haberek <ghaberek at gmail.com> Aug 30, 2005
- 463 views
- Last edited Aug 31, 2005
Here's how I would tackle it, kinda. :)=20
-- this is pretty much pseudo-eu code -- i'm not sure how you display text, -- but this seems like a fairly straight- -- forward approach=20 constant TEXT = 1, FLAG = 2 constant FOLD_ON = 1, FOLD_OFF = 0 sequence textBuffer textBuffer[1][TEXT] = {"Line 1", "Line 2", ... } textBuffer[1][FLAG] = { FOLD_OFF, FOLD_OFF, ... } integer topLine, foldState topLine = 1 foldState = FOLD_OFF for i = topLine to length( textBuffer[1][TEXT] ) do -- check fold state if foldState = FOLD_OFF then -- display line i displayLine( textBuffer[1][TEXT][i] ) -- check fold flag if textBuffer[1][FLAG][i] = FOLD_ON then -- show fold button [+] on line i showFoldButton( i ) -- save fold state foldState = FOLD_ON end if elsif foldState = FOLD_ON then -- check fold flag if textBuffer[1][FLAG][i] = FOLD_OFF then -- display line i displayLine( textBuffer[1][TEXT][i] ) -- save fold state foldState = FOLD_OFF end if end if -- check for bottom of screen if textReachedBottom() then -- done exit end if end for
~Greg
4. Re: Routine folding: display and cursor movement issues
- Posted by Al Getz <Xaxo at aol.com> Aug 31, 2005
- 446 views
Hi again, To add to the previous post... In order to store line 31 you'll have to use a sparse matrix technique...that is, using another table store 1 in location 31 so you know the buffer location is [1] for line [31]. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"