bugGNU nano - Bugs: bug #61162, undoing a cut operation does not...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #61162: undoing a cut operation does not put anchors back where they were

Submitter:  Benno Schulenberg <bens>
Submitted:  Wed 15 Sep 2021 09:10:51 AM UTC
   
 
Severity:  2 - Minor Status:  Fixed
Assigned to:  bens Open/Closed:  Closed

Jump to the original submission

Thu 07 Oct 2021 07:32:48 AM UTC, comment #7: 

Released in nano-5.9.

Benno Schulenberg <bens>
Group administrator
Mon 20 Sep 2021 09:03:55 AM UTC, comment #6: 

Fixed in git, commit 189960c4, by copying any anchor into the cutbuffer so that it gets saved in the undo item, and wiping an inherited anchor when undoing a cut operation.

Benno Schulenberg <bens>
Group administrator
Fri 17 Sep 2021 08:15:28 AM UTC, comment #5: 

Improved patch is attached.

(file #51933)

Benno Schulenberg <bens>
Group administrator
Thu 16 Sep 2021 09:56:34 AM UTC, comment #4: 

(Morphing this issue into a more general bug report.)

To reproduce, run:

src/nano --line  +75 README

Place an anchor at the current line ("tar -xvf...") with <Alt+Insert>.

Now type: <Ctrl+Up> <Ctrl+Up> M-A
And then: <Ctrl+Down> <Ctrl+Down> <Ctrl+Down> ^K
See that the anchor has been inherited by the "You will need" line.

Now type: M-U
See that the anchor now is at the "How to compile" line (where the cut started) and did not return to its original line.

Expected behavior: when any operation that involves cutting text, any anchor that was in the cut text should be returned to the line where it actually was and not be left at the start of the cut.

Benno Schulenberg <bens>
Group administrator
Wed 15 Sep 2021 03:07:39 PM UTC, comment #3: 

Distinguishing between a placed anchor and an inherited anchor does not help either, because when such an inherited anchor is later among the lines of another cutting operation, then the anchor will not be copied into the cutbuffer, and thus not into the undo item, and would thus be absent when that cut is undone.  Not good.

Anyway, it can be made to work (mostly).  See attached patch.  The only defect (that I found so far) is that when lines are cut one-by-one and more than one of them has an anchor, only the anchor of the first one is preserved when undoing the cut.

(file #51922)

Benno Schulenberg <bens>
Group administrator
Wed 15 Sep 2021 10:51:21 AM UTC, comment #2: 

The mechanism proposed in the previous comment cannot work.  It will work when cutting a region, but will break down when cutting a bunch of lines line-by-line: when one of those lines has an anchor, this anchor, when the line is cut, will be inherited by the next line, and when that line is cut, will be inherited by the subsequent line... meaning that every line after the line that was actually anchored will have an anchor in the cutbuffer.  :|

This can only be solved by somehow differentiating real anchors from inherited anchors.  Real anchor = integer 1, inherited anchor = integer 2, and when copying a segment, mask the anchor with 1...

Benno Schulenberg <bens>
Group administrator
Wed 15 Sep 2021 09:25:34 AM UTC, comment #1: 

Doing an external spell check, or "formatting" the buffer (with M-F, on a HTML file, for example), or passing the entire buffer through an external command (sed s/a/AAA/, for example), will lose any anchors that were present in the buffer.  (Spell checking a region, or passing a region through an external command, will move any anchor that was present in the region to the start of the region, though.)

Those are sensible things to do.  Likewise, undoing a full justification should drop all anchors, as it cannot maintain them on their respective paragraphs.

It would be possible, though, to actually restore each anchor to its original position if anchors were copied into the cutbuffer (and thus get preserved in the corresponding undo item).  The only thing that needs to be done to prevent anchors from getting multiplied when pasting the cutbuffer is to make sure the Paste command clear any anchors in the pasted piece of text.

Benno Schulenberg <bens>
Group administrator
Wed 15 Sep 2021 09:10:51 AM UTC, original submission:  

To reproduce, run 'src/nano +44 README',
and type: Alt+Insert, M-/, Alt+PageUp
See that the anchor placed by the first keystroke is still present on the same paragraph it was placed in (although not on the same line).
Now type: M-U Alt+PageUp
See that the cursor jumps to the top text line of the buffer.  This is useles, this has nothing to do with the paragraph where the anchor was placed.  It is even annoying and counterproductive: it would have been better to drop the anchor completely when it cannot maintain its approximate position, so that the user won't pointlessly lose its current position.

Benno Schulenberg <bens>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-10-07 bens Open/ClosedOpen Closed
    2021-09-27 bens Summaryundoing a cut operation does not put anchors back where they werre undoing a cut operation does not put anchors back where they were
    2021-09-20 bens StatusIn Progress Fixed
    2021-09-17 bens Attached File- Added 0001-cutting-copy-anchors-into-the-cutbuffer-so-that-undo.patch, #51933
    2021-09-16 bens StatusNone In Progress
        Summaryundoing a full justification moves any anchor to the top undoing a cut operation does not put anchors back where they werre
    2021-09-15 bens Assigned toNone bens
    2021-09-15 bens Attached File- Added 0001-cutting-copy-anchors-into-the-cutbuffer-so-that-undo.patch, #51922

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code