bugGNU nano - Bugs: bug #55305, undoing a multi-line cut can leave...

 
 

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

bug #55305: undoing a multi-line cut can leave an extra newline at EOF

Submitter:  Benno Schulenberg <bens>
Submitted:  Thu 27 Dec 2018 07:41:27 PM UTC
   
 
Severity:  3 - Normal Status:  Fixed
Assigned to:  dolorous Open/Closed:  Closed

Sun 30 Dec 2018 10:42:02 AM UTC, comment #3: 

Thanks for fixing this.  Both patches applied and pushed to master.  The fixing commit is 7e152f2a.

Benno Schulenberg <bens>
Group administrator
Thu 27 Dec 2018 10:33:15 PM UTC, comment #2: 

The attached two-patch set, against git b1b2369, should fix this.  It's in two steps, since one major design flaw needs to be fixed first.  Specifically, all the undo code checks for xflags values via assignments, but the way the xflags values are defined, they're supposed to be bitwise values; they should be handled the same way nano's global flags are.

The first patch changes all code involving xflags to use bitwise values.  This permits setting more than one xflags value at a time, which needs to be done in order to fix the problem.  (Other problems may eventually require this, as well, which is why it's done everywhere instead of just in one place; also, if new undo code gets copied from the old, this approach avoids causing the same problem again as a result.)

The second patch extends the WAS_FINAL_LINE xflags value (currently only used for ADD operations relating to the final line) to work in the CUT and CUT_TO_EOF operations relating to the final line: it's now set if the cut removes the final line of the text, which occurs with both marked cut and cut-to-eof.  When this flag is set and --nonewlines isn't used, undo_cut() will now properly remove the extra magicline left after the text is pasted in.  (It needs to be set regardless of whether the other cutting-related flags are set, which is why it's bitwise as a result of the first patch.)

(file #45754, file #45755)

David Lawrence Ramsey <dolorous>
Group Member
Thu 27 Dec 2018 09:20:41 PM UTC, comment #1: 

It doesn't only occur with cut-to-eof; the same thing happens with marked cutting.  To borrow from your example, run:

nano --ignore +21,42 README

Then type: ^^ ^W ^V ^K M-U ^S ^X. Then do a 'git diff' and see there is an extra newline at the end of the file.

David Lawrence Ramsey <dolorous>
Group Member
Thu 27 Dec 2018 07:41:27 PM UTC, original submission:  

To reproduce, run:

  nano --ignore +21,42 README

Then type:  M-T  M-U  ^S  ^X.  Then do a 'git diff' and see there is an extra newline at the end of the file.

When not using --nonewlines, doing a cut of rest-of-file in the middle of a line, does not only cut all text after the cursor but also causes a magic line to be added.  Apparently the undo command for M-T does not remove this extra line.

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 dolorous (Posted a comment)
  • -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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-25 bens Open/ClosedOpen Closed
    2018-12-30 bens StatusNone Fixed
        Assigned toNone dolorous
    2018-12-27 dolorous Attached File- Added 0001-undo-check-xflags-in-a-bitwise-manner.patch, #45754
        Attached File- Added 0002-undo-when-undoing-a-cut-don-t-add-an-extra-magicline.patch, #45755
    2018-12-27 dolorous Summaryundoing an M-T can leave an extra newline at EOF undoing a multi-line cut can leave an extra newline at EOF

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code