nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH 3/3] filtering: pair the cut and the insert, so they


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 3/3] filtering: pair the cut and the insert, so they can be undone together
Date: Thu, 17 May 2018 12:11:44 +0200

---
 src/nano.h |  2 +-
 src/text.c | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/nano.h b/src/nano.h
index 15eadd5d..1bd8cf6e 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -178,7 +178,7 @@ typedef enum {
 #ifdef ENABLE_COMMENT
        COMMENT, UNCOMMENT, PREFLIGHT,
 #endif
-       CUT, CUT_TO_EOF, PASTE, INSERT, OTHER
+       CUT, CUT_TO_EOF, PASTE, INSERT, COUPLE_START, COUPLE_END, OTHER
 } undo_type;
 
 /* Structure types. */
diff --git a/src/text.c b/src/text.c
index fada958f..e7d6c792 100644
--- a/src/text.c
+++ b/src/text.c
@@ -800,6 +800,15 @@ void do_undo(void)
                cutbuffer = oldcutbuffer;
                cutbottom = oldcutbottom;
                break;
+       case COUPLE_START:
+               undidmsg = _("filtering");
+               break;
+       case COUPLE_END:
+               openfile->current_undo = openfile->current_undo->next;
+               do_undo();
+               do_undo();
+               do_undo();
+               return;
        case INDENT:
                handle_indent_action(u, TRUE, TRUE);
                undidmsg = _("indent");
@@ -962,6 +971,15 @@ void do_redo(void)
                free_filestruct(u->cutbuffer);
                u->cutbuffer = NULL;
                break;
+       case COUPLE_START:
+               openfile->current_undo = u;
+               do_redo();
+               do_redo();
+               do_redo();
+               return;
+       case COUPLE_END:
+               redidmsg = _("filtering");
+               break;
        case INDENT:
                handle_indent_action(u, FALSE, TRUE);
                redidmsg = _("indent");
@@ -1162,6 +1180,8 @@ bool execute_command(const char *command)
                if (ISSET(MULTIBUFFER))
                        switch_to_prev_buffer();
 
+               add_undo(COUPLE_START);
+
                if (has_selection || !ISSET(MULTIBUFFER)) {
                        if (!has_selection) {
                                openfile->current = openfile->fileage;
@@ -1211,6 +1231,9 @@ bool execute_command(const char *command)
        else
                read_file(stream, 0, "pipe", TRUE);
 
+       if (should_pipe)
+               add_undo(COUPLE_END);
+
        if (wait(NULL) == -1)
                nperror("wait");
 
@@ -1377,6 +1400,8 @@ void add_undo(undo_type action)
                u->lineno += cutbottom->lineno - cutbuffer->lineno;
                break;
        case INSERT:
+       case COUPLE_START:
+       case COUPLE_END:
                break;
        case INDENT:
        case UNINDENT:
@@ -1537,6 +1562,8 @@ fprintf(stderr, "  >> Updating an undo... action = %d\n", 
action);
        case INSERT:
                u->mark_begin_lineno = openfile->current->lineno;
                u->mark_begin_x = openfile->current_x;
+       case COUPLE_START:
+       case COUPLE_END:
                break;
        default:
                statusline(ALERT, "Wrong undo update type -- please report a 
bug");
-- 
2.17.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]