Skip to content

Tickets #4872, #4873 and #4874: fix 'insert control code' function#5054

Merged
zyv merged 2 commits intoMidnightCommander:masterfrom
peripherium:fix/control-sequence-from-keyboard
Mar 14, 2026
Merged

Tickets #4872, #4873 and #4874: fix 'insert control code' function#5054
zyv merged 2 commits intoMidnightCommander:masterfrom
peripherium:fix/control-sequence-from-keyboard

Conversation

@peripherium
Copy link
Copy Markdown
Contributor

@peripherium peripherium commented Mar 8, 2026

The previous implementation used ascii_alpha_to_cntrl(), which assumed
alphabetic input and did not properly validate key codes returned by the
terminal libraries. The function has been renamed to keycode_to_cntrl()
and extended to correctly validate and convert key codes.

Changes:

The function is used both in the Insert literal dialog in mcedit and in the mc command line.

Checklist

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@github-actions github-actions Bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Mar 8, 2026
@github-actions github-actions Bot added this to the Future Releases milestone Mar 8, 2026
@zyv
Copy link
Copy Markdown
Member

zyv commented Mar 8, 2026

Since you are fixing keycode_to_cntrl, could you please add a test for it? Thank you!

@zyv zyv requested a review from egmontkob March 8, 2026 14:22
@zyv
Copy link
Copy Markdown
Member

zyv commented Mar 8, 2026

@egmontkob adding you, since this PR fixes 3 issues that you have reported...

@peripherium peripherium force-pushed the fix/control-sequence-from-keyboard branch from 94db99e to fc84480 Compare March 9, 2026 10:35
@peripherium
Copy link
Copy Markdown
Contributor Author

I initially didn't add a test for this function because the previous implementation didn't have one, so I assumed that adding a test was not required.

In the meantime, I have taken a closer look at the test suite and added the requested test here.

If this test is not sufficient or needs adjustments, please let me know.

Copy link
Copy Markdown
Contributor

@mc-worker mc-worker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lib/widget/input.c
Comment thread tests/lib/Makefile.am Outdated
Comment thread tests/lib/util__keycode_to_cntrl.c
Comment thread tests/lib/util__keycode_to_cntrl.c Outdated
@zyv zyv added area: mcedit mcedit, the built-in text editor and removed needs triage Needs triage by maintainers labels Mar 9, 2026
@zyv zyv modified the milestones: Future Releases, 4.9.0 Mar 9, 2026
@peripherium peripherium force-pushed the fix/control-sequence-from-keyboard branch from fc84480 to 74024a5 Compare March 10, 2026 06:31
Copy link
Copy Markdown
Contributor

@egmontkob egmontkob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message is duplicated.

Comment thread lib/util.c Outdated
Comment thread lib/util.c
Comment thread lib/util.h Outdated
Comment thread lib/util.c Outdated
Comment thread lib/util.c Outdated
Copy link
Copy Markdown
Contributor

@egmontkob egmontkob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested now, and it indeed fixes those three bugs, thanks!

@peripherium peripherium force-pushed the fix/control-sequence-from-keyboard branch from 74024a5 to d97eeee Compare March 11, 2026 08:46
@peripherium
Copy link
Copy Markdown
Contributor Author

I included the lowercase characters because I thought it would be user-friendly: even if shift wasn't pressed during input, the corresponding control code can be entered via the dialog. However, this is a bit inconsistent with the last inserted condition, according to which ch == '?' returns 0x7f. Should I remove the conditions with the lowercase characters from the code?

@egmontkob
Copy link
Copy Markdown
Contributor

Lowercase letters are absolutely fine, in fact, expected; the user probably won't bother pressing Shift.

What's unnecessary IMHO is support the characters "surrounding" the lowercase letters in the ASCII table: ` { | } ~. Here it's absolutely reasonable that the user will instead press @ [ \ ] ^ (or _ which didn't have a counterpart).

@zyv zyv changed the title Ticket #4872, #4873 and #4874: Fix 'insert control code' function. Tickets #4872, #4873 and #4874: fix 'insert control code' function Mar 11, 2026
@peripherium peripherium force-pushed the fix/control-sequence-from-keyboard branch from d97eeee to 0a7f477 Compare March 12, 2026 08:23
@peripherium
Copy link
Copy Markdown
Contributor Author

Originally I allowed characters from ´ to ~ because I assumed someone looking at the ASCII table might wonder why those printable characters were excluded.

However, if this is not intuitive and could instead confuse future readers, then it doesn't belong in the code. So I removed it and restricted the range to a-z.

@peripherium peripherium force-pushed the fix/control-sequence-from-keyboard branch from 0a7f477 to 7ecbdc1 Compare March 13, 2026 08:17
@peripherium
Copy link
Copy Markdown
Contributor Author

The commit message is duplicated.

Sorry about the duplicated commit message - that must have slipped in during the amend commits while I was updating the patch. I've fixed the commit message now.

Please let me know if there is anything else in the patch that should be improved.

Copy link
Copy Markdown
Contributor

@egmontkob egmontkob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just very quickly skimming through it this time, it looks good, thank you!

(Super minor nitpicking: you add an extra newline to the end of tests/lib/Makefile.am which already has enough (some will say that already has more than enough.))

Let's wait for Andrew's review as well.

Copy link
Copy Markdown
Contributor

@mc-worker mc-worker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please begin the commit message with following line:

Ticket #4872, #4873, #4874: fix 'insert control code' function.

Comment thread lib/util.c Outdated
Comment thread lib/util.h Outdated
@mc-worker
Copy link
Copy Markdown
Contributor

  1. Not all test are passed. util__keycode_to_cntrl.log is attached.
    util__keycode_to_cntrl.log

  2. In editor, I use a paste of \t via "Insert literal" dialog (ctrl-q) very often. It doesn't work anymore.

@peripherium peripherium force-pushed the fix/control-sequence-from-keyboard branch from 7ecbdc1 to d04a605 Compare March 14, 2026 07:22
@peripherium
Copy link
Copy Markdown
Contributor Author

I completely forgot to adjust the test after changing the keycode_to_cntrl() function. Thanks for pointing that out. I've already implemented all the other changes (especially in Makefile.am).

@zyv zyv force-pushed the fix/control-sequence-from-keyboard branch from d04a605 to 798a138 Compare March 14, 2026 12:11
Copy link
Copy Markdown
Member

@zyv zyv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the code now, and I’m very happy about the test. Thank you very much! How about the others?

…der#4874: fix 'insert control code' function

Validate input key codes, ignore special keys returned by get_key_code().

Fix handling of KEY_M_CTRL combinations and extend mapping for
'@', '[', '\', ']', '^', '_'.

Fixes: MidnightCommander#4872
Fixes: MidnightCommander#4873
Fixes: MidnightCommander#4874

Signed-off-by: Manuel Einfalt <einfalt1@proton.me>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
@zyv zyv force-pushed the fix/control-sequence-from-keyboard branch from 798a138 to ef07299 Compare March 14, 2026 12:14
…of the callers

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
@egmontkob
Copy link
Copy Markdown
Contributor

Looked good to me the last time, won't check it again :P Thanks!

@zyv zyv merged commit 1796996 into MidnightCommander:master Mar 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcedit mcedit, the built-in text editor prio: medium Has the potential to affect progress

4 participants