aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmdline.c54
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;
}
}