From e3498abfd8d95dbd083ccfd1d386f9ad37044a43 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 26 Apr 2025 17:46:28 +0300 Subject: support folding via F1 and clicks in the folding margin * Set up the folding margin in the currently empty margin column after the line number. On Gtk, this meant resetting all the marker symbols and their foreground/background colors as well as the margin's colors themselves. This looks like a bug. It's not necessary on Scinterm, which apparently uses the default/linenumber styles by default. Perhaps we should try upgrading Scintilla? * The folding state is considered not to be directly controlled by the language (just like the scroll position and zoom level). That's why we can directly control it by clicking on the margin column. * F1 can be used to toggle all folds globally. * The only support within the C core necessary for folding is to make sure that the current line is unfolded after every keypress. * We might add custom folding commands to the language later on (e.g. F+, F-). In this case, the key macros will have to be changed of course. --- fallback.teco_ini | Bin 2118 -> 2148 bytes lib/color.tes | 7 +++++++ lib/fnkeys.tes | 23 +++++++++++++++++++++++ src/interface-curses/interface.c | 3 +++ src/interface-gtk/interface.c | 3 +++ 5 files changed, 36 insertions(+) diff --git a/fallback.teco_ini b/fallback.teco_ini index edd8b7f..954b070 100644 Binary files a/fallback.teco_ini and b/fallback.teco_ini differ diff --git a/lib/color.tes b/lib/color.tes index f732848..dcf2065 100644 --- a/lib/color.tes +++ b/lib/color.tes @@ -79,4 +79,11 @@ !* Set up brace lightning *! :M[color.bracelight],34M[color.set] :M[color.error],35M[color.set] + + !* Configure fold margin *! + :M[color.linenumber]U.fU.b + Q.b,1ESSETFOLDMARGINCOLOUR Q.b,1ESSETFOLDMARGINHICOLOUR + 10000++,30ESMARKERDEFINE Q.f,30ESMARKERSETFORE Q.b,30ESMARKERSETBACK + 10000+-,31ESMARKERDEFINE Q.f,31ESMARKERSETFORE Q.b,31ESMARKERSETBACK + (2^*30 # 2^*31),2ESSETMARGINMASKN 0,2ESSETMARGINTYPEN } diff --git a/lib/fnkeys.tes b/lib/fnkeys.tes index 3fd0701..3445342 100644 --- a/lib/fnkeys.tes +++ b/lib/fnkeys.tes @@ -116,6 +116,12 @@ @[ CLOSE]{(EX)} 1U[ CLOSE] +!* + * F1 toggles __all__ folds. + *! +@[ F1]{(2ESFOLDALL{-14D}} +1U[ F1] + !* * Zoom with F9/F10 if function keys are enabled. * This is automatically rubbed out. @@ -136,9 +142,26 @@ * Ctrl+right click: Insertion beginning of line * Scroll wheel: scrolls (faster with shift) * Ctrl+scroll wheel: zoom (GTK-only) + * + * Also, you can click on the folding margin to toggle folds. *! @[MOUSE]{ -2EJESCHARPOSITIONFROMPOINTU.p + + -2EJU.x ESGETMARGINLEFTU.r + ESGETMARGINS< + Q.rU.l Q.iESGETMARGINWIDTHN%.r + Q.x-Q.l+1"> Q.x-Q.r"< !* mouse within margin i *! + Q.iESGETMARGINMASKN&(-33554432)"N !* folding margin *! + -EJ-2"= !* mouse released *! + Q.pESLINEFROMPOSITIONESTOGGLEFOLD + {-9D} + ' + ' + 1; !* handle like click in text area *! + ' ' + %.i> + -4EJ&2"N Q.pESLINEFROMPOSITIONESPOSITIONFROMLINEU.p ' 1,Q.pESWORDSTARTPOSITION:U.#ws 1,Q.pESWORDENDPOSITION:U.#we diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index a71ca20..e3013fb 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -2134,6 +2134,9 @@ teco_interface_event_loop_iter(void) */ if (teco_interface_current_view == last_view) teco_interface_ssm(SCI_SETFIRSTVISIBLELINE, last_vpos, 0); + /* also unfold automatically */ + sptr_t dot = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + teco_interface_ssm(SCI_ENSUREVISIBLE, teco_interface_ssm(SCI_LINEFROMPOSITION, dot, 0), 0); teco_interface_ssm(SCI_SCROLLCARET, 0, 0); teco_interface_refresh(); diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index 045f9d7..06abe61 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -1429,6 +1429,9 @@ teco_interface_input_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) if (event->type == GDK_KEY_PRESS) { if (teco_interface_current_view == last_view) teco_interface_ssm(SCI_SETFIRSTVISIBLELINE, last_vpos, 0); + /* also unfold automatically */ + sptr_t dot = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + teco_interface_ssm(SCI_ENSUREVISIBLE, teco_interface_ssm(SCI_LINEFROMPOSITION, dot, 0), 0); teco_interface_ssm(SCI_SCROLLCARET, 0, 0); } -- cgit v1.2.3