curves: Option/Alt+2..6 select the dialog's channel (#7325)

In the Curves dialog Option/Alt+2 selects the first channel entry (the
composite) and 3, 4, 5, 6 the following ones, whatever the document's
colour model. The keys are consumed so they reach nothing else.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
qvest-sselsandClaude Sonnet 5.5 committed 2026-10-31 10:51:15 +01:00
1 parent 422ca7beda
commit 2f550fafa1
1 file changed
+117
@@ -248,6 +248,44 @@ fn curves_mode_row(ui: &mut egui::Ui, v: &mut Value, key: &str, gray: bool) -> E
e
}
/// The channel position an Alt/Option+digit selects: 2 is the first channel (the composite),
/// 3 the next, and so on (#7325). Reads the physical key, which Option changes on macOS.
fn channel_for_key(event: &egui::Event) -> Option<usize> {
let egui::Event::Key { key, physical_key, pressed: true, modifiers, .. } = event else {
return None;
};
if !modifiers.alt || modifiers.command || modifiers.ctrl || modifiers.shift {
return None;
}
let digit = |k: egui::Key| match k {
egui::Key::Num2 => Some(0),
egui::Key::Num3 => Some(1),
egui::Key::Num4 => Some(2),
egui::Key::Num5 => Some(3),
egui::Key::Num6 => Some(4),
_ => None,
};
physical_key.and_then(digit).or_else(|| digit(*key))
}
/// Consumes this frame's Alt/Option+2..6 presses and selects that entry of the channel popup.
fn select_channel_by_key(ui: &egui::Ui, id: egui::Id, count: usize) {
let picked = ui.input_mut(|i| {
let mut last = None;
i.events.retain(|e| match channel_for_key(e) {
Some(n) => {
last = Some(n);
false
}
None => true,
});
last
});
if let Some(n) = picked.filter(|&n| n < count) {
ui.data_mut(|d| d.insert_temp(id, n));
}
}
pub(super) fn curves(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {
let t = Tokens::get(ui.ctx());
let space = space_of(v);
@@ -255,6 +293,9 @@ pub(super) fn curves(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {
let state_id = cx.mem.with("curves");
let mut st: CurveUi = ui.data(|d| d.get_temp(state_id)).unwrap_or_default();
let isolated = cx.isolated_curve.as_ref();
if cx.dialog {
select_channel_by_key(ui, cx.mem.with("curves-ch"), isolated.map_or(chans.len(), |_| 1));
}
let ch = if let Some(iso) = isolated {
channel_picker_opts(ui, cx.mem.with("curves-ch"), &[(0, iso.name.as_str())], tl!("Channel:"), iso.translate)
} else {
@@ -518,3 +559,79 @@ mod polyline_tests {
println!("{iterations} polylines: old 4096 samples {old:?}; direct 256 samples {miss:?}; cached screen line {hit:?}");
}
}
#[cfg(test)]
mod channel_key_tests {
use super::*;
use egui::{Event, Key, Modifiers};
fn press(key: Key, modifiers: Modifiers) -> Event {
Event::Key { key, physical_key: Some(key), pressed: true, repeat: false, modifiers }
}
fn cx(dialog: bool, gray: bool) -> EditorCx {
EditorCx {
mem: egui::Id::unique("channel-key-test"),
hist: None,
gray,
swatches: [[0.0; 3], [1.0; 3]],
gradients: Vec::new(),
dialog,
dynamic_color_sliders: false,
isolated_curve: None,
}
}
/// Runs one frame of the Curves editor with `events`; returns the selected channel and how
/// many key events were left unconsumed.
fn frame(ctx: &egui::Context, v: &mut Value, cx: &EditorCx, events: Vec<Event>) -> (usize, usize) {
let mut left = 0;
let mut output = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| {
curves(ui, v, cx);
left = ui.input(|i| i.events.iter().filter(|e| matches!(e, Event::Key { .. })).count());
});
output.textures_delta.clear();
(ctx.data(|d| d.get_temp(cx.mem.with("curves-ch"))).unwrap_or(0), left)
}
#[test]
fn alt_digits_select_rgb_channels_by_position() {
let cx = cx(true, false);
for (key, want) in [(Key::Num3, 1), (Key::Num4, 2), (Key::Num5, 3), (Key::Num2, 0), (Key::Num6, 0)] {
let ctx = egui::Context::default();
let mut v = json!({});
let (ch, left) = frame(&ctx, &mut v, &cx, vec![press(key, Modifiers::ALT)]);
assert_eq!(ch, want, "{key:?}");
assert_eq!(left, 0, "{key:?} is consumed");
}
}
#[test]
fn alt_digits_cover_cmyk_and_ignore_keys_past_the_list() {
let cx = cx(true, false);
let cmyk = || json!({"cyan": {}, "black": {}});
for (key, want) in [(Key::Num2, 0), (Key::Num3, 1), (Key::Num6, 4)] {
let ctx = egui::Context::default();
let (ch, _) = frame(&ctx, &mut cmyk(), &cx, vec![press(key, Modifiers::ALT)]);
assert_eq!(ch, want, "{key:?}");
}
// Gray lists one channel: Alt+3 does nothing.
let gray = self::cx(true, true);
let ctx = egui::Context::default();
let (ch, _) = frame(&ctx, &mut json!({}), &gray, vec![press(Key::Num3, Modifiers::ALT)]);
assert_eq!(ch, 0);
}
#[test]
fn other_modifiers_and_the_properties_panel_leave_the_keys_alone() {
let ctx = egui::Context::default();
let dialog = cx(true, false);
for m in [Modifiers::NONE, Modifiers::COMMAND, Modifiers::ALT | Modifiers::SHIFT, Modifiers::ALT | Modifiers::COMMAND] {
let (ch, left) = frame(&ctx, &mut json!({}), &dialog, vec![press(Key::Num3, m)]);
assert_eq!((ch, left), (0, 1), "{m:?}");
}
let panel = cx(false, false);
let (ch, left) = frame(&ctx, &mut json!({}), &panel, vec![press(Key::Num3, Modifiers::ALT)]);
assert_eq!((ch, left), (0, 1));
}
}