bugGNU nano - Bugs: bug #54032, cursor can get misplaced when...


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

bug #54032: cursor can get misplaced when undoing a cut of the magic line

Submitted by:  Benno Schulenberg <bens>
Submitted on:  Fri 01 Jun 2018 07:25:08 PM UTC  
Severity:  2 - Minor Status:  Fixed
Assigned to:  David Lawrence Ramsey <dolorous> Open/Closed:  Closed

Sun 08 Jul 2018 03:45:29 PM UTC, comment #4: 

Fixed in git, commit 20971e83, followed by an improvement of two relevant comments.

Benno Schulenberg <bens>
Project Administrator
Sat 07 Jul 2018 06:49:14 PM UTC, comment #3: 

Thanks for the patch.  Will test it more later on, and then apply.

Benno Schulenberg <bens>
Project Administrator
Sat 09 Jun 2018 10:37:05 PM UTC, comment #2: 

I've made an attempt at fixing this, since undoing/redoing cuts shows this problem, but undoing/redoing joins doesn't.  And if one type of minor text operation can handle it while another can't, I figure that's not so minor a problem.  When trying the latter operation (and quoting your description where it applies), we get:

To reproduce, run 'nano --ignore' and type:

word <Down> Backspace M-U

Note that it says: [ Undid action (line join) ], but nothing changes, obviously. Continue typing:


Now it says: [ Redid action (line join) ], and the cursor is placed again at the end of the line (as expected), just before the magic line. Continue typing:


Now the cursor jumps to the start of the magicline, and the cursor was there when the "line join" (Backspace) was done (as expected).


Also, if I follow your original instructions using ^K, but press ^^ before ^K (so that nano ends up undoing/redoing a cut of an empty marked region), the same problem occurs, so it's not just full line cuts that face this issue.

So, in order to fix this, we should take a cue from what line joins are doing.  It turns out that do_undo() and do_redo() have bits of special code to position the cursor properly when dealing with line joins in this case: the undo/redo operations don't change the text, but they do change the cursor position.

The same thing can be accomplished for cuts via minor adjustments to undo_cut() and redo_cut().  Currently, they handle such cuts by immediately returning if the cutbuffer is empty.  But, by not returning until just after the cursor is positioned in preparation for the cut, everything works as expected.  Even better, no new lines of code are required.

As for your expected behavior ("nano should simply ignore any attempt to cut the magic line: no undo item should be added for it"), that would be the ideal solution in the long term, but that's also more complicated to do since it involves fiddling with the undo stack, and I'm still trying to understand more of the undo code.  Not to mention, it would have to be done for the joining code as well as the cutting code.  At least this way, the problem is fixed without needing any new code.

The patch is against current git: 9a7ba5d.

(file #44340)

David Lawrence Ramsey <dolorous>
Project MemberIn charge of this item.
Sun 03 Jun 2018 09:27:36 AM UTC, comment #1: 

Too minor a bug.  Can't be bothered with it now.

Benno Schulenberg <bens>
Project Administrator
Fri 01 Jun 2018 07:25:08 PM UTC, original submission:  

To reproduce, run 'nano --ignore' and type:

word  <Down>  ^K  M-U

Note that it says: [ Undid action (text cut) ], but nothing changes, obviously.  Continue typing:

M-U  M-E  M-E

Now it says:  [ Redid action (text cut) ], but the cursor is not placed again on the magic line.  Continue typing:


Now the cursor jumps to the start of the line, but the cursor never was there when the "text cut" (^K) was done.

Expected behavior: nano should simply ignore any attempt to cut the magic line: no undo item should be added for it.

Benno Schulenberg <bens>
Project Administrator


Depends on the following items: None found

Items that depend on this one: None found


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

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-09-10 bens Open/ClosedOpen => Closed
    2018-07-08 bens StatusIn Progress => Fixed
    2018-07-07 bens StatusWont Fix => In Progress
        Assigned toNone => dolorous
    2018-06-09 dolorous Attached File- => Added 0001-undo-position-the-cursor-properly-when-we-undo-redo-.patch, #44340
    2018-06-03 bens StatusNone => Wont Fix

    Back to the top

    Powered by Savane 3.6