[Top][All Lists]

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

[Nano-devel] The undo feature

From: Erik Lundin
Subject: [Nano-devel] The undo feature
Date: Tue, 21 Oct 2014 19:36:15 +0200

I've been thinking about the whole undo feature in nano. Isn't it too
complex for the task at hand?

This is what it looks like right now:

typedef struct undo {
    ssize_t lineno;
    undo_type type;
        /* What type of undo this was. */
    size_t begin;
        /* Where did this action begin or end. */
    char *strdata;
        /* String type data we will use for copying the affected line
back. */
    int xflags;
        /* Some flag data we need. */

    /* Cut-specific stuff we need. */
    filestruct *cutbuffer;
        /* Copy of the cutbuffer. */
    filestruct *cutbottom;
        /* Copy of cutbottom. */
    bool mark_set;
        /* Was the marker set when we cut? */
    ssize_t mark_begin_lineno;
        /* copy copy copy */
    size_t mark_begin_x;
        /* Another shadow variable. */
    struct undo *next;
} undo;

First off. Lots of the variables here are tailored for the cut feature?
It all boils down to the fact that you can undo one or more actions in a
single undo. These actions can be added, changed or removed lines or a
mix of these (macros?). So why not simplify it?

typedef enum {
} subundo_type;

typedef struct subundo {
   subundo_type type;
   filestruct *line;
   size_t mark_begin_x;
   struct subundo *next;
} subundo;

typedef struct undo {
    undo_type type;
    struct subundo *actions;
    struct undo *next;
} undo;

I might have missed some important variable connected to the marking or
such. This is just an example :)

Then when adding a new undo first add it with:

Then before changing a line:
add_subundo(CHANGE, filestruct);

Where filestruct points to the line that needs to be saved. When adding
new lines we only need to save the line number in the filestruct.

This way you can add an unlimited amount of sequenced changes to a
single undo. This can be used with cut, added text, indenting,
whitespace to tabs, macros etc.

What do you think?

Erik Lundin <address@hidden>

reply via email to

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