From ee4373521e6d323de22e67ecf4529117ff4d62ba Mon Sep 17 00:00:00 2001 From: alexanderalber <90604107+alexanderalber@users.noreply.github.com> Date: Sat, 10 Oct 2026 20:00:26 +0200 Subject: [PATCH] Ctrl+Tab and Ctrl+Shift+Tab switch to the next and previous document (#2340) (#2353) * Ctrl+Tab and Ctrl+Shift+Tab switch to the next and previous document (#2340) Photoshop's document-cycling keys, on macOS too (Cmd+Tab belongs to the system). They follow the tab order and wrap around at either end, and they reach the documents even while a field or widget has the keyboard focus, since nothing edits with Ctrl+Tab. Plain Tab still hides the panels. generated with Claude Code * Contributors: add my name for the About window generated with Claude Code --------- Co-authored-by: Brandon Thomas --- contributors/people.toml | 5 +++ crates/ui-egui/src/canvas/tabs_tests.rs | 54 +++++++++++++++++++++++++ crates/ui-egui/src/i18n/cs.tsv | 2 + crates/ui-egui/src/i18n/de.tsv | 2 + crates/ui-egui/src/i18n/el.tsv | 2 + crates/ui-egui/src/i18n/es.tsv | 2 + crates/ui-egui/src/i18n/fr.tsv | 2 + crates/ui-egui/src/i18n/id.tsv | 2 + crates/ui-egui/src/i18n/it.tsv | 2 + crates/ui-egui/src/i18n/ja.tsv | 2 + crates/ui-egui/src/i18n/ko.tsv | 2 + crates/ui-egui/src/i18n/nl.tsv | 2 + crates/ui-egui/src/i18n/pl.tsv | 2 + crates/ui-egui/src/i18n/pt-br.tsv | 2 + crates/ui-egui/src/i18n/ru.tsv | 2 + crates/ui-egui/src/i18n/uk.tsv | 2 + crates/ui-egui/src/i18n/zh-hans.tsv | 2 + crates/ui-egui/src/i18n/zh-hant.tsv | 2 + crates/ui-egui/src/menus.rs | 14 +++++++ crates/ui-egui/src/shortcut_dispatch.rs | 6 ++- 20 files changed, 110 insertions(+), 1 deletion(-) diff --git a/contributors/people.toml b/contributors/people.toml index 5bac685899..af8591c1a9 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -75,6 +75,11 @@ real_name = "Ahmed Moussa" display_name = "Ahmed Moussa" sync_github_name = false +[people.alexanderalber] +real_name = "Alexander Alber" +display_name = "Alexander Alber" +sync_github_name = false + [people.Erica4fr] sync_github_name = true diff --git a/crates/ui-egui/src/canvas/tabs_tests.rs b/crates/ui-egui/src/canvas/tabs_tests.rs index 6d8a7adfa6..4cc2bca0f0 100644 --- a/crates/ui-egui/src/canvas/tabs_tests.rs +++ b/crates/ui-egui/src/canvas/tabs_tests.rs @@ -112,3 +112,57 @@ fn saved_document_tabs_track_file_identity() { assert!(h.state().session.active().unwrap().is_dirty()); } } + +/// What a Ctrl press reports: on Windows and Linux Ctrl is also the command key, on macOS it isn't. +fn ctrl() -> egui::Modifiers { + egui::Modifiers { ctrl: true, command: !cfg!(target_os = "macos"), ..egui::Modifiers::NONE } +} + +/// #2340: Ctrl+Tab shows the next document's tab and Ctrl+Shift+Tab the previous one, wrapping +/// around at either end, as in Photoshop. Plain Tab still hides the panels instead. +#[test] +fn ctrl_tab_cycles_through_the_document_tabs() { + let mut h = harness(3, ThemeKind::Pro); + let active = |h: &Harness<'_, PhotocraftApp>| h.state().session.active_index(); + assert_eq!(active(&h), Some(2), "the last new document is active"); + let press = |h: &mut Harness<'_, PhotocraftApp>, shift: bool| { + h.key_press_modifiers(if shift { ctrl() | egui::Modifiers::SHIFT } else { ctrl() }, egui::Key::Tab); + h.run_steps(2); + }; + press(&mut h, false); + assert_eq!(active(&h), Some(0), "Ctrl+Tab on the last tab wraps to the first"); + press(&mut h, false); + assert_eq!(active(&h), Some(1)); + press(&mut h, true); + assert_eq!(active(&h), Some(0), "Ctrl+Shift+Tab goes back"); + press(&mut h, true); + assert_eq!(active(&h), Some(2), "and wraps to the last tab"); + assert!(h.state().ui.panels.dock, "Ctrl+Tab doesn't hide the panels"); + // Tab order is document order, so a dragged tab is cycled through at its new place. + h.state_mut().session.move_document(0, 2); + h.state_mut().session.set_active(1); + press(&mut h, false); + assert_eq!(h.state().session.active().unwrap().doc.name, "ch1-p01.png"); + h.key_press(egui::Key::Tab); + h.run_steps(2); + assert_eq!(active(&h), Some(2), "plain Tab doesn't switch documents"); + assert!(!h.state().ui.panels.dock, "plain Tab hides the panels"); +} + +/// One document: Ctrl+Tab stays on it quietly; a focused widget or text field doesn't keep the key. +#[test] +fn ctrl_tab_with_one_document_or_a_focused_field() { + let mut h = harness(1, ThemeKind::Pro); + h.key_press_modifiers(ctrl(), egui::Key::Tab); + h.run_steps(2); + assert_eq!(h.state().session.active_index(), Some(0)); + assert!(crate::shortcut_dispatch::take_log(&h.ctx).iter().all(|(_, o)| *o == crate::shortcut_dispatch::Outcome::Ran), "no disabled-shortcut report"); + use crate::shortcut_dispatch::Focus; + for (key, sc) in [("Ctrl+Tab", "window.nextDocument"), ("Ctrl+Shift+Tab", "window.previousDocument")] { + let parsed = crate::shortcuts::parse(key).unwrap(); + assert!(Focus::Widget.allows(&parsed) && Focus::Text.allows(&parsed), "{key} reaches {sc} from a focused field"); + let bound = crate::shortcut_dispatch::bindings(h.state()).into_iter().find(|(_, s)| *s == parsed).map(|(id, _)| id); + assert_eq!(bound.as_deref(), Some(sc)); + } + assert!(!Focus::Widget.allows(&crate::shortcuts::parse("Tab").unwrap()), "a focused widget keeps plain Tab"); +} diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index db59bd8154..517d135fda 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -2410,5 +2410,7 @@ fontWeight Italic Kurzíva Quick Selection found nothing there Rychlý výběr zde nic nenašel Object Selection found nothing there — try a tighter rectangle Výběr objektu zde nic nenašel — zkuste těsnější obdélník No subject found — try a rectangle around the object Nebyl nalezen žádný objekt — zkuste obdélník kolem objektu + Next Document Další dokument + Previous Document Předchozí dokument W x H x Resolution Š x V x Rozlišení Front Image Přední obraz diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 29afc7cfd6..148c8293d0 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -2449,5 +2449,7 @@ fontWeight Italic Kursiv Quick Selection found nothing there Die Schnellauswahl hat dort nichts gefunden Object Selection found nothing there — try a tighter rectangle Die Objektauswahl hat dort nichts gefunden — versuchen Sie ein engeres Rechteck No subject found — try a rectangle around the object Kein Motiv gefunden — versuchen Sie ein Rechteck um das Objekt + Next Document Nächstes Dokument + Previous Document Vorheriges Dokument W x H x Resolution B x H x Auflösung Front Image Vorderes Bild diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 3bd6157fff..b162476b72 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -3518,5 +3518,7 @@ fontWeight Thin Πολύ λεπτά Quick Selection found nothing there Η Γρήγορη επιλογή δεν βρήκε τίποτα εκεί Object Selection found nothing there — try a tighter rectangle Η Επιλογή αντικειμένου δεν βρήκε τίποτα εκεί — δοκιμάστε ένα πιο στενό ορθογώνιο No subject found — try a rectangle around the object Δεν βρέθηκε θέμα — δοκιμάστε ένα ορθογώνιο γύρω από το αντικείμενο + Next Document Επόμενο έγγραφο + Previous Document Προηγούμενο έγγραφο W x H x Resolution Π x Υ x Ανάλυση Front Image Μπροστινή εικόνα diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 3028a2ba6d..7f83934683 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -2478,5 +2478,7 @@ fontWeight Italic Cursiva Quick Selection found nothing there Selección rápida no encontró nada ahí Object Selection found nothing there — try a tighter rectangle Selección de objeto no encontró nada ahí — pruebe un rectángulo más ajustado No subject found — try a rectangle around the object No se encontró ningún sujeto — pruebe un rectángulo alrededor del objeto + Next Document Documento siguiente + Previous Document Documento anterior W x H x Resolution An. x Al. x Resolución Front Image Imagen frontal diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 55ddd1ba2a..d4c9f7475a 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -2829,5 +2829,7 @@ fontWeight Italic Italique Quick Selection found nothing there La Sélection rapide n'a rien trouvé à cet endroit Object Selection found nothing there — try a tighter rectangle La Sélection d'objet n'a rien trouvé à cet endroit — essayez un rectangle plus serré No subject found — try a rectangle around the object Aucun sujet trouvé — essayez un rectangle autour de l'objet + Next Document Document suivant + Previous Document Document précédent W x H x Resolution L x H x Résolution Front Image Image de premier plan diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index fb21511d0e..819cbc28e9 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -2816,5 +2816,7 @@ fontWeight Italic Miring Quick Selection found nothing there Seleksi Cepat tidak menemukan apa pun di sana Object Selection found nothing there — try a tighter rectangle Seleksi Objek tidak menemukan apa pun di sana — coba persegi panjang yang lebih rapat No subject found — try a rectangle around the object Subjek tidak ditemukan — coba persegi panjang di sekitar objek + Next Document Dokumen Berikutnya + Previous Document Dokumen Sebelumnya W x H x Resolution L x T x Resolusi Front Image Gambar Depan diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 1f1f5d87ab..827a0ad225 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -2480,5 +2480,7 @@ fontWeight Italic Corsivo Quick Selection found nothing there Selezione rapida non ha trovato nulla lì Object Selection found nothing there — try a tighter rectangle Selezione oggetto non ha trovato nulla lì — prova un rettangolo più stretto No subject found — try a rectangle around the object Nessun soggetto trovato — prova un rettangolo attorno all'oggetto + Next Document Documento successivo + Previous Document Documento precedente W x H x Resolution L x A x Risoluzione Front Image Immagine in primo piano diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 4cc38187af..830030b61c 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -3430,5 +3430,7 @@ fontWeight Italic 斜体 Quick Selection found nothing there クイック選択ではそこに何も見つかりませんでした Object Selection found nothing there — try a tighter rectangle オブジェクト選択ではそこに何も見つかりませんでした — より狭い長方形で試してください No subject found — try a rectangle around the object 被写体が見つかりません — オブジェクトを囲む長方形を試してください + Next Document 次のドキュメント + Previous Document 前のドキュメント W x H x Resolution 幅 x 高さ x 解像度 Front Image 前面の画像 diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 2030f0aa5a..ee578dd2f2 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -2988,5 +2988,7 @@ fontWeight Italic 기울임 Quick Selection found nothing there 빠른 선택으로 해당 위치에서 아무것도 찾지 못했습니다 Object Selection found nothing there — try a tighter rectangle 개체 선택으로 해당 위치에서 아무것도 찾지 못했습니다 — 더 좁은 사각형을 사용해 보세요 No subject found — try a rectangle around the object 피사체를 찾을 수 없습니다 — 개체 주위에 사각형을 그려 보세요 + Next Document 다음 문서 + Previous Document 이전 문서 W x H x Resolution 폭 x 높이 x 해상도 Front Image 전면 이미지 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 2eafbf96fb..0a910321e5 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -3589,5 +3589,7 @@ cameraRaw Whites Witten Quick Selection found nothing there Snelle selectie heeft daar niets gevonden Object Selection found nothing there — try a tighter rectangle Objectselectie heeft daar niets gevonden — probeer een krappere rechthoek No subject found — try a rectangle around the object Geen onderwerp gevonden — probeer een rechthoek rond het object + Next Document Volgend document + Previous Document Vorig document W x H x Resolution B x H x Resolutie Front Image Voorste afbeelding diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 8ffe96000b..a1a27d3c1a 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -3430,5 +3430,7 @@ cameraRaw Roughness Chropowatość Quick Selection found nothing there Szybkie zaznaczanie nic tam nie znalazło Object Selection found nothing there — try a tighter rectangle Zaznaczanie obiektu nic tam nie znalazło — spróbuj ciaśniejszego prostokąta No subject found — try a rectangle around the object Nie znaleziono obiektu — spróbuj prostokąta wokół obiektu + Next Document Następny dokument + Previous Document Poprzedni dokument W x H x Resolution Szer. x Wys. x Rozdzielczość Front Image Obraz na wierzchu diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 7c674eb98b..67f7c89e27 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -2837,5 +2837,7 @@ fontWeight Italic Itálico Quick Selection found nothing there A Seleção rápida não encontrou nada ali Object Selection found nothing there — try a tighter rectangle A Seleção de objeto não encontrou nada ali — tente um retângulo mais justo No subject found — try a rectangle around the object Nenhum assunto encontrado — tente um retângulo ao redor do objeto + Next Document Próximo documento + Previous Document Documento anterior W x H x Resolution L x A x Resolução Front Image Imagem frontal diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 0b1964433e..07062d05ac 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -2694,6 +2694,8 @@ fontWeight Italic Курсив Missing delete command Отсутствует команда удаления Invalid delete command Недопустимая команда удаления Layer deleted, but confirmation preference could not be saved: {error} Слой удалён, но не удалось сохранить настройку подтверждения: {error} + Next Document Следующий документ + Previous Document Предыдущий документ W x H x Resolution Ш x В x Разрешение Front Image Изображение переднего плана Swaps height and width Меняет местами высоту и ширину diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 4790bb760f..78992b326b 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -3517,5 +3517,7 @@ cameraRaw Masking Маскування Quick Selection found nothing there Швидке виділення нічого тут не знайшло Object Selection found nothing there — try a tighter rectangle Виділення об'єктів нічого тут не знайшло — спробуйте вужчий прямокутник No subject found — try a rectangle around the object Об'єкт не знайдено — спробуйте прямокутник навколо об'єкта + Next Document Наступний документ + Previous Document Попередній документ W x H x Resolution Ш x В x Роздільна здатність Front Image Зображення переднього плану diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 9831561136..d180b17f3c 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -2418,5 +2418,7 @@ fontWeight Italic 斜体 Quick Selection found nothing there 快速选择在该处未找到任何内容 Object Selection found nothing there — try a tighter rectangle 对象选择在该处未找到任何内容 — 请尝试更紧凑的矩形 No subject found — try a rectangle around the object 未找到主体 — 请尝试在对象周围绘制矩形 + Next Document 下一个文档 + Previous Document 上一个文档 W x H x Resolution 宽 x 高 x 分辨率 Front Image 前面的图像 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 38061c68bd..231b39cce5 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -2387,5 +2387,7 @@ fontWeight Italic 斜體 Quick Selection found nothing there 快速選取在該處找不到任何內容 Object Selection found nothing there — try a tighter rectangle 物件選取在該處找不到任何內容 — 請嘗試更緊密的矩形 No subject found — try a rectangle around the object 找不到主體 — 請嘗試在物件周圍繪製矩形 + Next Document 下一個文件 + Previous Document 上一個文件 W x H x Resolution 寬 x 高 x 解析度 Front Image 前面的影像 diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index ee757b2575..5f7fd8674e 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -63,6 +63,9 @@ pub const UI_COMMANDS: &[(&str, &str, &[&str], Option<&str>)] = &[ ("window.togglePanels", "Show/Hide All Panels", &[], Some("Tab")), ("window.toggle.dock", "Show/Hide Panels", &[], Some("Shift+Tab")), ("window.toggle.options", "Options", &["Window"], None), + // Photoshop's Ctrl+Tab and Ctrl+Shift+Tab, on macOS too (⌘Tab belongs to the system, #2340). + ("window.nextDocument", "Next Document", &[], Some("Ctrl+Tab")), + ("window.previousDocument", "Previous Document", &[], Some("Ctrl+Shift+Tab")), ("window.theme.toggle", "Next Appearance Mode", &["Window"], None), ("window.theme.pro", "Pro Theme", &["Window", "Theme"], None), ("window.theme.proMedium", "Pro Medium Gray Theme", &["Window", "Theme"], None), @@ -511,6 +514,15 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id: } Ok(Value::Null) } + "window.nextDocument" | "window.previousDocument" => { + // Tabs are in document order, so the next tab is the next document, wrapping around. + let n = app.session.documents().len(); + let at = app.session.active_index().ok_or("no document open")?; + let to = if id == "window.nextDocument" { (at + 1) % n } else { (at + n - 1) % n }; + app.session.set_active(to); + app.jobs.focus = None; + Ok(json!({"document": to})) + } t if t.starts_with("window.toggle.") => { // A shown but collapsed dock group is expanded rather than hidden (#129). if let Some(g) = crate::dock::Group::from_key(&t["window.toggle.".len()..]).filter(|g| g.shown(&app.ui.panels) && app.ui.dock.is_collapsed(*g)) { @@ -595,6 +607,8 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> bool { } i if i.starts_with("window.toggle.") => true, "window.togglePanels" => true, + // With one document open the key stays quiet, as in Photoshop, rather than reporting why. + "window.nextDocument" | "window.previousDocument" => app.session.active().is_some(), i if panel_alias(i).is_some() || workspace_name(i).is_some() => true, i if proof_preset(i).is_some() => app.session.active().is_some(), // "Custom…" is the full Proof Setup dialog. diff --git a/crates/ui-egui/src/shortcut_dispatch.rs b/crates/ui-egui/src/shortcut_dispatch.rs index 0245d99f0b..7439d56ce8 100644 --- a/crates/ui-egui/src/shortcut_dispatch.rs +++ b/crates/ui-egui/src/shortcut_dispatch.rs @@ -140,9 +140,13 @@ impl Focus { /// May `sc` fire with this focus? A focused widget keeps its navigation keys (arrows, ↩, /// Space, Esc…, plus ⌫ / Delete when it claimed them); a text field keeps everything but ⌘ shortcuts (minus its own editing - /// ones: select all, clipboard, undo) and the function keys. + /// ones: select all, clipboard, undo) and the function keys. Ctrl+Tab and Ctrl+Shift+Tab switch + /// documents whatever has focus, as in Photoshop: no widget or text field edits with them (#2340). pub fn allows(self, sc: &KeyboardShortcut) -> bool { let k = sc.logical_key; + if k == Key::Tab && sc.modifiers.ctrl { + return true; + } let function = matches!( k, Key::F1