Skip to content

Ticket #4872, #4873 and #4874: Fix 'insert control code' function.#5054

Open
peripherium wants to merge 1 commit intoMidnightCommander:masterfrom
peripherium:fix/control-sequence-from-keyboard
Open

Ticket #4872, #4873 and #4874: Fix 'insert control code' function.#5054
peripherium wants to merge 1 commit intoMidnightCommander:masterfrom
peripherium:fix/control-sequence-from-keyboard

Conversation

@peripherium
Copy link

@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
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
Member

zyv commented Mar 8, 2026

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

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>

lib/util.c (keycode_to_cntrl): Rename from ascii_alpha_to_cntrl.
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>
@peripherium peripherium force-pushed the fix/control-sequence-from-keyboard branch from 94db99e to fc84480 Compare March 9, 2026 10:35
@peripherium
Copy link
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
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.

if (parm == XCTRL ('q'))
{
int control_code;
quote = TRUE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an empty line after variable declaration.

utilunix__my_system_fork_child \
x_basename
x_basename \
util__keycode_to_cntrl
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this line upper to make this list sorted alphabetically.

lib - keycode_to_cntrl() function testing

Copyright (C) 2011-2026
Free Software Foundation, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Really 2011?


START_PARAMETRIZED_TEST (keycode_test, test_keycodes)
{
int actual_result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an empty line after variable declaration.

@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
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

3 participants