diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-11-11 23:04:27 +0100 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-11-12 01:05:52 +0100 |
| commit | 6e006ee0e2d0beedd310218cab1d70cfc71ab154 (patch) | |
| tree | bddd73263efc21c6ef3af2a0d07f370ed2e8f40e /src/cmdline.c | |
| parent | 44073bac56ea37d7e995497e1719e376dc48abcf (diff) | |
fixed the command line's line end type: it was reset during command line replacement ({...})
* The line end type and tab mode is apparently a property of the document.
Therefore it was lost when exchanging the command line's document during command line replacement.
* Instead, the old command line is now stored in a string.
* During replacement we delete and append only the part of the command line that changed.
This ensures that we don't have to restyle the entire command line with every single
replacement (even if it is at the end of the command line).
Diffstat (limited to 'src/cmdline.c')
| -rw-r--r-- | src/cmdline.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/src/cmdline.c b/src/cmdline.c index 4b9c7a8..3483c8c 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -38,7 +38,6 @@ #include "file-utils.h" #include "interface.h" #include "view.h" -#include "doc.h" #include "expressions.h" #include "parser.h" #include "core-commands.h" @@ -69,19 +68,6 @@ teco_cmdline_t teco_cmdline = { .height = 1 }; -/* - * FIXME: Should perhaps be in doc.h. - * But which view should it be called on? - */ -static inline void -teco_doc_scintilla_unref(teco_doc_scintilla_t *doc) -{ - if (doc) - teco_cmdline_ssm(SCI_RELEASEDOCUMENT, 0, (sptr_t)doc); -} - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(teco_doc_scintilla_t, teco_doc_scintilla_unref); - /** * Last terminated command line. * This is not a teco_doc_scintilla_t since we have to return it as a string @@ -158,7 +144,7 @@ static gboolean teco_cmdline_insert(const gchar *data, gsize len, GError **error) { const teco_string_t src = {(gchar *)data, len}; - g_autoptr(teco_doc_scintilla_t) old_cmdline = NULL; + g_auto(teco_string_t) old_cmdline = {NULL, 0}; gsize repl_pc = 0; gsize effective_len = teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0); @@ -218,16 +204,22 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error) teco_undo_pop(teco_cmdline.pc); - //g_assert(old_cmdline == NULL); - old_cmdline = (teco_doc_scintilla_t *)teco_cmdline_ssm(SCI_GETDOCPOINTER, 0, 0); - teco_cmdline_ssm(SCI_ADDREFDOCUMENT, 0, (sptr_t)old_cmdline); - /* create new document in the command line view */ - teco_cmdline_ssm(SCI_SETDOCPOINTER, 0, 0); - teco_cmdline_ssm(SCI_ADDTEXT, new_cmdline.len, (sptr_t)new_cmdline.data); + /* + * We don't replace the command line's document, since that would + * reset the line end type and other configurable settings. + * Also, we don't clear the document to avoid unnecessary restylings + * if syntax highlighting is enabled on the command line. + */ + g_assert(old_cmdline.len == 0); + teco_string_init(&old_cmdline, macro, effective_len); + teco_cmdline_ssm(SCI_DELETERANGE, teco_cmdline.pc, + old_cmdline.len-teco_cmdline.pc); + teco_cmdline_ssm(SCI_ADDTEXT, new_cmdline.len-teco_cmdline.pc, + (sptr_t)new_cmdline.data+teco_cmdline.pc); + macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0); macro_len = effective_len = new_cmdline.len; teco_cmdline.machine.macro_pc = repl_pc = teco_cmdline.pc; - continue; } @@ -235,24 +227,30 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error) teco_error_add_frame_toplevel(); teco_error_display_short(tmp_error); - if (old_cmdline) { + if (old_cmdline.len > 0) { /* * Error during command-line replacement. * Replay previous command-line. - * This avoids deep copying. + * The commands leading up to the failed replacement + * will be left rubbed out. */ teco_undo_pop(repl_pc); - teco_cmdline_ssm(SCI_SETDOCPOINTER, 0, (sptr_t)old_cmdline); - old_cmdline = NULL; + /* + * May cause restyling of the command lines, + * but that's probably okay - it's just a fallback. + */ + teco_cmdline_ssm(SCI_CLEARALL, 0, 0); + teco_cmdline_ssm(SCI_ADDTEXT, old_cmdline.len, (sptr_t)old_cmdline.data); + teco_string_clear(&old_cmdline); + memset(&old_cmdline, 0, sizeof(old_cmdline)); teco_cmdline.machine.macro_pc = teco_cmdline.pc = repl_pc; - /* rubout cmdline replacement command */ + /* rub out cmdline replacement command */ teco_cmdline_ssm(SCI_GOTOPOS, --effective_len, 0); macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0); macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0); - continue; } } |
