support line-by-line undo in text mode - gramscii - A simple editor for ASCII box-and-arrow charts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7f6e62f77bca73e49dfa260ff7ac75770d1363c8
 (DIR) parent f3100ddd486d6f39b0c97c9c492bb6020bf3caf1
 (HTM) Author: KatolaZ <katolaz@freaknet.org>
       Date:   Wed, 31 Jul 2019 11:49:06 +0100
       
       support line-by-line undo in text mode
       
       Diffstat:
         M draw.c                              |       7 +++++++
         M gramscii.1                          |       6 +++---
         M gramscii.h                          |       5 +++--
         M lineset.c                           |       5 +++++
       
       4 files changed, 18 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/draw.c b/draw.c
       @@ -77,10 +77,13 @@ void get_text(FILE *fc){
                int orig_x = x;
        
                redraw();
       +        copy_lines_to_ring(y, y, PRV_STATE);
                while((c=fgetc(fc))!=EOF && c != 27){
                        if(c=='\n'){
                                set_cur(BG);
       +                        copy_lines_to_ring(y,y, NEW_STATE);
                                y += 1;
       +                        copy_lines_to_ring(y, y, PRV_STATE);
                                x = orig_x;
                        }
                        else {
       @@ -95,6 +98,8 @@ void get_text(FILE *fc){
                        status_bar();
                        show_cursor();
                }
       +        if (modified)
       +                copy_lines_to_ring(y, y, NEW_STATE);
                mode=MOVE;
        }
        
       @@ -245,6 +250,7 @@ update_arrow:
                        show_cursor();
                }
                if (c == 'a' || c == '\n'){
       +                invalidate_undo();
                        draw_arrow(orig_x, orig_y, arrow, arrow_len, FIX);
                        modified = 1;
                }
       @@ -278,6 +284,7 @@ void erase(FILE *fc){
                int orig_x = x, orig_y = y;
                status_bar();
                show_cursor();
       +        invalidate_undo();
                while((c=fgetc(fc))!=EOF && c!=27 && c!= 'x' && c != '\n'){
                        if (!move_around(c, fc)) continue;
                        check_bound();
 (DIR) diff --git a/gramscii.1 b/gramscii.1
       @@ -534,10 +534,10 @@ gramscii currently manages only a fixed screen of the same size of the
        screen where it starts from. This will be changed in a future release to
        support scrolling and "virtual" screens of any (reasonable) size.
        .PP
       -gramscii currently does
       +Undo commands are only available in box, visual (cut, fill), and text
       +mode, and for copy/paste operations. gramscii currently does
        .B not
       -support "undo" commands for arrow, text, and erase mode. This will be
       -added soon.
       +support undo commands for arrow and erase mode. This will be fixed soon.
        .SH AUTHORS
        gramscii is written and maintained by Vincenzo "KatolaZ" Nicosia
        <katolaz@freaknet.org>. You can use, copy, modify, and redistribute
 (DIR) diff --git a/gramscii.h b/gramscii.h
       @@ -149,6 +149,8 @@ void get_arrow(FILE *fc);
        void erase(FILE *fc);
        void visual_box(FILE *fc);
        void paste();
       +void undo_change();
       +void redo_change();
        
        /** file-related functions **/
        void write_file(FILE *fc);
       @@ -165,7 +167,6 @@ void ensure_num_lines(lineset_t *ls, int n);
        void yank_region(int x1, int y1, int x2, int y2);
        void paste_region(int x1, int y1);
        void copy_lines_to_ring(int y1, int y2, int which);
       -void undo_change();
       -void redo_change();
       +void invalidate_undo();
        
        #endif
 (DIR) diff --git a/lineset.c b/lineset.c
       @@ -171,3 +171,8 @@ void copy_lines_to_ring(int y1, int y2, int which){
                }
        #endif        
        }
       +
       +void invalidate_undo(){
       +        if (undo_lst > undo_cur)
       +                undo_lst = undo_cur;
       +}