nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] The undo feature


From: Mark Majeres
Subject: Re: [Nano-devel] The undo feature
Date: Wed, 29 Oct 2014 16:30:20 -0700

On 10/29/14, Erik Lundin <address@hidden> wrote:
>
>> Erik,
>>
>> You must be overlooking the while loops in do_redo and do_undo for the
>> cases SPLIT_BEGIN and SPLIT_END.  If the position of the linked list
>> of undo objects ends up in the middle of SPLIT_BEGIN and SPLIT_END
>> then something terrible has gone wrong.  The scenario will not happen,
>> you do not need to worry about this.
>>
>> You only need to create an undo type for your function. something
>> similar to the SPLIT_BEGIN and SPIT_END pair.  You can then string
>> together functions that have already been developed and tested.
>>
>> --Mark Majeres
>
> Mark,
>
> Following your suggestions on the whitespace to tabs function on 5 rows
> that each have 16 spaces would look like this:
>
> SPLIT_BEGIN
> 16x UNDO(DEL)
> 1x UNDO(ADD)
> 16x UNDO(DEL)
> 1x UNDO(ADD)
> 16x UNDO(DEL)
> 1x UNDO(ADD)
> 16x UNDO(DEL)
> 1x UNDO(ADD)
> 16x UNDO(DEL)
> 1x UNDO(ADD)
> SPLIT_END
>
> The deletion and addition of data is in this case linked to a single
> change. There has to be even more markers to mark where one change
> begins and ends and where the set starts and ends. I don't think this is
> the optimal way of doing this.
>
> Another example is the search+replace all with newlines (which i think
> it should support).
>
> The text:
> 1. foo bar foo
> 2. foo bar foo
> 3. foo bar foo
> 4. foo bar foo
> 5. foo bar foo
>
> If you search for "bar" and replace it with "\nthis\nis\nnewlines\n",
> there would have to be a lot of complicated calculations on where the
> add_undo(ENTER) should be placed etc. And what about search+replace with
> submatches? Example: Replace "([a-z])(ar)" with "\n$1\ngo$2\n\n"

Erik,

If there is more than one character to remove then use do_cut_text()
instead of do_delete().  I don't know what you mean by 'even more
markers'.  Focus on a solution that works on one line.  Adding
multiple lines will only be a matter of creating an outer loop.

If you want new lines added in search/replace then you would start by
parsing the new string and replacing all of the '\n' with a call to
do_enter().  Prior to calling do_enter() set the value of current_x.
You may need to save the current_x prior to doing your work and then
reset it back to the original afterwards, the same may apply to the
variables that hold the marker positions.

The basic approach is to reuse the existing undo functions.  The
building blocks are in place, just try to use them without having to
create duplicate functionality.


--Mark Majeres



reply via email to

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