bugGNU nano - Bugs: bug #61702, Cut does not work as expected in...

 
 

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

bug #61702: Cut does not work as expected in menu prompts.

Submitted by:  Tasos Papastylianou <tpapastylianou>
Submitted on:  Sun 19 Dec 2021 03:13:03 PM UTC  
 
Severity:  3 - Normal Status:  None
Assigned to:  None Open/Closed:  Open

Mon 10 Jan 2022 04:43:05 PM UTC, comment #3: 

Dear Benno, please disregard the previous comment; my compilation chain was flawed. (rookie mistake).

Please find attached a final patch, which implements 'cut', 'zap', and 'do_toggle(CUT_FROM_CURSOR)' for menu prompts.

The only thing this implementation does 'not' do is show a statusline after a toggle (e.g. "Cut to end enabled/disabled"), as happens in the main editing mode. However, I think in the context of prompts this is probably a good thing anyway, since presumably someone using this toggle in a prompt knows what they're doing, and showing a statusline on top of a prompt is probably more clutter than anything.

Please let me know if you find this acceptable or if I'm missing something obvious in the code!

(file #52634)

Tasos Papastylianou <tpapastylianou>
Sun 09 Jan 2022 01:29:13 PM UTC, comment #2: 

To follow up from the previous comment; if I make the following change in global.c:

1023c1023
<       add_to_funcs(zap_text, MMAIN,
---
>       add_to_funcs(zap_text, MMOST,
1256c1256
<       add_to_sclist(MMAIN, "M-Del", ALT_DELETE, zap_text, 0);
---
>       add_to_sclist(MMOST, "M-Del", ALT_DELETE, zap_text, 0);

then I expected zap to work correctly in prompts when pressing Alt-Delete. But for some reason this is not the case.

However, if I bind a different shortcut to the 'zap' function separately in my nanorc, e.g.:

bind M-! zap all

then pressing M-! in the context of a prompt works as expected.

Is there something I'm missing with regards to the hard-coded Alt-Delete shortcut specifically?

Tasos Papastylianou <tpapastylianou>
Sat 08 Jan 2022 04:39:09 PM UTC, comment #1: 

I'm trying to familiarise myself a bit with the codebase, so that I can contribute a bit more usefully other than just open "I wish nano did X" requests. :)

In that vein, I am uploading a small patch for prompt.c which attempts to partially resolve this ticket.

I think the 'cut' side of things is fine, but I couldn't get the 'zap' equivalent function to work in that context. Any help would be appreciated :)

What this patch solves:
 - 'Cut' in prompts now inserts the 'answer' text into the cutbuffer rather than just delete it. If CUT_FROM_CURSOR is already enabled, then this has the intended effect within the prompt menu too.

What it does not solve:
 - I was unable to get the existing keybinding for 'zap' to work with the equivalent do_statusbar_zap_text function. I toyed a bit with trying to make zap present in more menus within global.c, but nothing I tried helped.
 - the cut-from-cursor toggle doesn't work from within the prompt context. It needs to be set from within the main window before entering the prompt.

In a sense this is enough for me, since I can work around it and achieve everything else I want with macros. But it doesn't feel very integrated unless "cut-from-cursor" and "zap" also work for these menus in the same way.

(file #52629)

Tasos Papastylianou <tpapastylianou>
Sun 19 Dec 2021 03:13:03 PM UTC, original submission:  

One can legally bind the 'cut' function in menus other than main. However, trying to use this does not work as expected (i.e. the cut contents are not stored in the
cutbuffer).

By contrast, the 'paste' function works as intended (i.e. pastes in the prompt).


Example use-case: create a macro to obtain the current filename:
 - Press Ctrl+O to open the writeout dialog
 - Cut the contents of the prompt, in order to obtain the current filename.
 - Cancel to exit the menu

The name of the current buffer is now stored in the cutbuffer.

A more elaborate example is in using this to create a 'reload' macro -- useful
when having the same file open in separate nano instances (e.g. split tmux panes),
and you want to update the right pane to show changes made in the left pane.

E.g. assume you have a file called "myfile". You could create the following macro:
Keystrokes:
1. ^R       # open insert menu
2. myfile   # i.e. type the file name
3. y        # in case the 'already open elsewhere, are you sure' dialogue comes up
4. M-U      # in case the 'already open elsewhere, are you sure' dialogue did NOT come up, and a 'y' was printed instead :p
5. M-<      # switch to the 'old' buffer
6. ^X       # exit without saving

Step 2 requires you to know the name of the file, and then the macro can only be used with that specific file only. If you had a way to 'cut' the name of the file from the writeout menu, you could expand this macro to detect the filename of the current buffer automatically, and reload the file without having to hardcode the name in the macro.

Tasos Papastylianou <tpapastylianou>

 

Attached Files
file #52634:  patch added by tpapastylianou (1KiB - application/octet-stream - final patch to differentiate between cutting vs zapping in the statusbar of menu prompts with working cut-from-cursor toggle)
file #52629:  prompt_c_patch added by tpapastylianou (609B - application/octet-stream - Patch to differentiate between cutting vs zapping in the statusbar of menu prompts)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tpapastylianou (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-01-10 tpapastylianou Attached File- => Added patch, #52634
    2022-01-08 tpapastylianou Attached File- => Added prompt_c_patch, #52629

    Back to the top


    Powered by Savane 3.7