Looks good in general, but I think folding should work when the cursor is
anywhere in the block, not just on the fold point (vim seems to work this way).
I played with it a little and came up with something like this:
```C
static gint prepare_fold(CmdParams *p)
{
/* foldparent of the next line */
gint line = SSM(p->sci, SCI_GETFOLDPARENT, p->line + 1, 0);
if (p->line == line)
; /* we are already on the fold point line */
else
{
/* foldparent of the current line */
line = SSM(p->sci, SCI_GETFOLDPARENT, p->line, 0);
}
if (line != -1)
{
/* move the cursor on the visible line before the fold */
gint pos = SSM(p->sci, SCI_POSITIONFROMLINE, line, 0);
SET_POS_NOX(p->sci, pos, TRUE);
}
return line;
}
void cmd_toggle_fold(CmdContext *c, CmdParams *p)
{
gint line = prepare_fold(p);
if (line != -1)
SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_TOGGLE);
}
```
If the code looks OK to you and works as expected, could you update all the
folding functions similarly to `cmd_toggle_fold()` above?
In addition, these aren't exactly "edit" commands and should be placed in a
separate file. Could you create `fold.c/h`, add them to `Makefile.am` and move
all these commands there?
--
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1327#issuecomment-2077794940
You are receiving this because you are subscribed to this thread.
Message ID: <geany/geany-plugins/pull/1327/[email protected]>