W55: Shift-F3 raw viewer (MC parity)

MC's Shift-F3 opens the viewer in raw mode without magic/binary
detection. Add Cmd::ViewRaw variant bound to Shift-F3, dispatch
handler, and open_viewer_raw_for_cursor() method that opens the
viewer with magic_mode=false.

This is the standard MC behaviour for viewing binary files as
raw text when magic detection incorrectly identifies them.

Tests: 1416 pass, zero warnings.
This commit is contained in:
2026-07-07 13:11:30 +03:00
parent e28d575668
commit 74ea610745
3 changed files with 34 additions and 0 deletions
@@ -356,6 +356,29 @@ impl FileManager {
Ok(())
}
/// Open the viewer in raw mode (no magic/binary detection). MC
/// parity for Shift-F3. The viewer forces Text mode regardless of
/// file content.
pub fn open_viewer_raw_for_cursor(&mut self) -> Result<()> {
let p = self.active_panel().cursor_path();
if p.as_os_str().is_empty() {
self.status.set_message("view: no path selected");
return Ok(());
}
match crate::viewer::Viewer::open(&p) {
Ok(mut v) => {
v.magic_mode = false;
let _ = v.restore_cursor_position();
self.viewer = Some(v);
self.status.set_message(format!("Viewing {} (raw)", p.display()));
}
Err(e) => {
self.status.set_message(format!("view: {e}"));
}
}
Ok(())
}
/// Open the M-? Find dialog. The pattern input is pre-filled with
/// the cursor entry's name (so searching for the selected file's
/// pattern is the default); falls back to the default placeholder
@@ -109,6 +109,10 @@ impl FileManager {
self.open_viewer_for_cursor()?;
Ok(true)
}
Cmd::ViewRaw => {
self.open_viewer_raw_for_cursor()?;
Ok(true)
}
Cmd::UserMenu => {
self.open_user_menu_dialog()?;
Ok(true)
@@ -11,6 +11,8 @@ pub enum Cmd {
Edit,
/// F3 — open the file under the cursor in the viewer.
View,
/// Shift-F3 — view the cursor file in raw mode (no magic detection).
ViewRaw,
/// Descend into the directory under the cursor (or open a file).
/// If the cursor is on a directory, change into it. If on a
/// regular file, route to Edit. This is the historical "ENTER
@@ -315,6 +317,7 @@ impl Cmd {
Cmd::EditMenuFile => "Edit menu file",
Cmd::EditHighlightFile => "Edit highlighting file",
Cmd::ViewFile => "View file",
Cmd::ViewRaw => "View raw file",
Cmd::DisplayBits => "Display bits",
Cmd::LearnKeysDialog => "Learn keys",
Cmd::VfsSettings => "Virtual FS",
@@ -441,6 +444,10 @@ pub fn default_keymap() -> Keymap {
km.bind(F1, Cmd::Help);
km.bind(F2, Cmd::UserMenu);
km.bind(F3, Cmd::View);
km.bind(Key {
code: F3.code,
mods: crate::key::Modifiers::SHIFT,
}, Cmd::ViewRaw);
km.bind(F4, Cmd::Edit);
km.bind(F5, Cmd::Copy);
km.bind(F6, Cmd::Move);