PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Ctrl+Tab and Ctrl+Shift+Tab switch to the next and previous document (#2340) (#2353)
alexanderalberee4373521e6d
diff --git a/contributors/people.toml b/contributors/people.tomlindex 5bac68589..af8591c1a 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 = truediff --git a/crates/ui-egui/src/canvas/tabs_tests.rs b/crates/ui-egui/src/canvas/tabs_tests.rsindex 6d8a7adfa..4cc2bca0f 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.tsvindex db59bd815..517d135fd 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -2410,5 +2410,7 @@ fontWeight Italic KurzívaQuick Selection found nothing there Rychlý výběr zde nic nenašelObject Selection found nothing there — try a tighter rectangle Výběr objektu zde nic nenašel — zkuste těsnější obdélníkNo 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í dokumentW x H x Resolution Š x V x RozlišeníFront Image Přední obrazdiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 29afc7cfd..148c8293d 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -2449,5 +2449,7 @@ fontWeight Italic KursivQuick Selection found nothing there Die Schnellauswahl hat dort nichts gefundenObject Selection found nothing there — try a tighter rectangle Die Objektauswahl hat dort nichts gefunden — versuchen Sie ein engeres RechteckNo 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 DokumentW x H x Resolution B x H x AuflösungFront Image Vorderes Bilddiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex 3bd6157ff..b162476b7 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.tsvindex 3028a2ba6..7f8393468 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -2478,5 +2478,7 @@ fontWeight Italic CursivaQuick 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 ajustadoNo 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 anteriorW x H x Resolution An. x Al. x ResoluciónFront Image Imagen frontaldiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 55ddd1ba2..d4c9f7475 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -2829,5 +2829,7 @@ fontWeight Italic ItaliqueQuick Selection found nothing there La Sélection rapide n'a rien trouvé à cet endroitObject 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édentW x H x Resolution L x H x RésolutionFront Image Image de premier plandiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex fb21511d0..819cbc28e 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -2816,5 +2816,7 @@ fontWeight Italic MiringQuick Selection found nothing there Seleksi Cepat tidak menemukan apa pun di sanaObject Selection found nothing there — try a tighter rectangle Seleksi Objek tidak menemukan apa pun di sana — coba persegi panjang yang lebih rapatNo subject found — try a rectangle around the object Subjek tidak ditemukan — coba persegi panjang di sekitar objek+ Next Document Dokumen Berikutnya+ Previous Document Dokumen SebelumnyaW x H x Resolution L x T x ResolusiFront Image Gambar Depandiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex 1f1f5d87a..827a0ad22 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -2480,5 +2480,7 @@ fontWeight Italic CorsivoQuick 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ù strettoNo subject found — try a rectangle around the object Nessun soggetto trovato — prova un rettangolo attorno all'oggetto+ Next Document Documento successivo+ Previous Document Documento precedenteW x H x Resolution L x A x RisoluzioneFront Image Immagine in primo pianodiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 4cc38187a..830030b61 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.tsvindex 2030f0aa5..ee578dd2f 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.tsvindex 2eafbf96f..0a910321e 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -3589,5 +3589,7 @@ cameraRaw Whites WittenQuick Selection found nothing there Snelle selectie heeft daar niets gevondenObject Selection found nothing there — try a tighter rectangle Objectselectie heeft daar niets gevonden — probeer een krappere rechthoekNo subject found — try a rectangle around the object Geen onderwerp gevonden — probeer een rechthoek rond het object+ Next Document Volgend document+ Previous Document Vorig documentW x H x Resolution B x H x ResolutieFront Image Voorste afbeeldingdiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 8ffe96000..a1a27d3c1 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łoObject Selection found nothing there — try a tighter rectangle Zaznaczanie obiektu nic tam nie znalazło — spróbuj ciaśniejszego prostokątaNo 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 dokumentW x H x Resolution Szer. x Wys. x RozdzielczośćFront Image Obraz na wierzchudiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 7c674eb98..67f7c89e2 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álicoQuick Selection found nothing there A Seleção rápida não encontrou nada aliObject Selection found nothing there — try a tighter rectangle A Seleção de objeto não encontrou nada ali — tente um retângulo mais justoNo 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 anteriorW x H x Resolution L x A x ResoluçãoFront Image Imagem frontaldiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 0b1964433..07062d05a 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.tsvindex 4790bb760..78992b326 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.tsvindex 983156113..d180b17f3 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.tsvindex 38061c68b..231b39cce 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.rsindex ee757b257..5f7fd8674 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.rsindex 0245d99f0..7439d56ce 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