Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Delete and Fill Selection on the selection tools' right-click menu (#1286) (#1331)

BFlat3e8d78844158
diff --git a/crates/engine/src/edit_menu_cmds.rs b/crates/engine/src/edit_menu_cmds.rs
index 8b27b25b7..64768b0d8 100644
--- a/crates/engine/src/edit_menu_cmds.rs
+++ b/crates/engine/src/edit_menu_cmds.rs
@@ -322,8 +322,17 @@ fn rect_param(p: &Value, key: &str, cmd: &str) -> Result<Rect> {
}
fn content_aware_fill(s: &mut Session, p: &Value) -> Result<Value> {
+ content_aware_fill_as(s, p, "edit.contentAwareFill", "Content-Aware Fill")
+}
+
+/// Delete and Fill Selection (#1286): Photoshop's one-click removal from the selection-tool
+/// context menu. Content-Aware Fill with its default settings into the layer, no dialog.
+fn delete_and_fill(s: &mut Session, _: &Value) -> Result<Value> {
+ content_aware_fill_as(s, &json!({}), "edit.deleteAndFillSelection", "Delete and Fill Selection")
+}
+
+fn content_aware_fill_as(s: &mut Session, p: &Value, cmd: &'static str, label: &'static str) -> Result<Value> {
use photocraft_algo::content_aware::{FillOptions, color_level, fill_with, rotation_level};
- let cmd = "edit.contentAwareFill";
let id = pixel_layer(s).map_err(EngineError::Other)?;
let st = s.active().ok_or(EngineError::NoDocument)?;
let doc = st.doc.clone();
@@ -365,7 +374,6 @@ fn content_aware_fill(s: &mut Session, p: &Value) -> Result<Value> {
let fmt = surf.format();
let n = fmt.channels();
let (w, h) = (window.width() as usize, window.height() as usize);
- let label = "Content-Aware Fill";
// A background job when started with `Session::start` (#210): reading the window and the
// PatchMatch fill run on a worker against the document snapshot, cancellable per row band.
crate::jobs::run(
@@ -957,6 +965,7 @@ pub fn specs() -> Vec<CommandSpec> {
can_caf,
content_aware_fill
),
+ spec!("edit.deleteAndFillSelection", "Delete and Fill Selection", [], None, "{}", can_caf, delete_and_fill),
spec!(
"edit.contentAwareScale",
"Content-Aware Scale",
diff --git a/crates/engine/src/edit_menu_cmds/tests.rs b/crates/engine/src/edit_menu_cmds/tests.rs
index a3444e834..921a8a49c 100644
--- a/crates/engine/src/edit_menu_cmds/tests.rs
+++ b/crates/engine/src/edit_menu_cmds/tests.rs
@@ -135,6 +135,30 @@ fn content_aware_fill_removes_object_at_all_depths() {
}
}
+#[test]
+fn delete_and_fill_selection_removes_the_object_in_one_step() {
+ // #1286: Content-Aware Fill's defaults, no dialog, one history step named for the command.
+ for depth in [8, 16, 32] {
+ let mut s = blob_session(depth);
+ let base = s.active().unwrap().active_layer.unwrap();
+ assert!(s.is_enabled("edit.deleteAndFillSelection"));
+ let r = s.execute("edit.deleteAndFillSelection", json!({})).unwrap();
+ assert_eq!(r["layer"].as_u64(), Some(base.0), "fills the layer itself");
+ assert!(r["filled"].as_u64().unwrap() > 100);
+ let v = px(&s, 30, 20);
+ assert!(!(v[0] > 0.9 && v[1] < 0.1), "depth {depth}: red left: {v:?}");
+ assert_eq!(s.active().unwrap().history.undo_label(), Some("Delete and Fill Selection"));
+ s.undo();
+ assert_eq!(px(&s, 30, 20)[1], 0.0, "undo restores the blob");
+ }
+ // Parameters are ignored, never a crash; nothing selected greys it out and refuses.
+ let mut s = blob_session(8);
+ assert!(s.execute("edit.deleteAndFillSelection", json!({"output": 7, "sampling": [1]})).is_ok());
+ s.execute("select.deselect", json!({})).unwrap();
+ assert!(!s.is_enabled("edit.deleteAndFillSelection"));
+ assert!(s.execute("edit.deleteAndFillSelection", json!({})).is_err());
+}
+
#[test]
fn content_aware_fill_outputs_and_sampling() {
let mut s = blob_session(8);
diff --git a/crates/ui-egui/src/canvas_tool_menu.rs b/crates/ui-egui/src/canvas_tool_menu.rs
index 72d7d1991..2f7816400 100644
--- a/crates/ui-egui/src/canvas_tool_menu.rs
+++ b/crates/ui-egui/src/canvas_tool_menu.rs
@@ -35,8 +35,8 @@ pub const TRANSFORM_MENU: &[Row] = &[
];
/// Photoshop's selection-tool context menu with an active selection, in its order. Its Generative
-/// Fill and Delete and Fill Selection rows have no PhotoCraft command and are left out. Rows
-/// stay visible and grey out exactly like their menu-bar twins.
+/// Fill row has no PhotoCraft command and is left out. Rows stay visible and grey out exactly like
+/// their menu-bar twins.
pub const SELECTION_MENU: &[Row] = &[
Some(("Deselect", "select.deselect")),
Some(("Select Inverse", "select.inverse")),
@@ -55,6 +55,7 @@ pub const SELECTION_MENU: &[Row] = &[
Some(("Distort", "edit.transform.distort")),
Some(("Perspective", "edit.transform.perspective")),
None,
+ Some(("Delete and Fill Selection", "edit.deleteAndFillSelection")),
Some(("Fill…", "edit.fill")),
Some(("Stroke…", "edit.stroke")),
Some(("Content-Aware Fill…", "edit.contentAwareFill")),
@@ -440,6 +441,7 @@ mod tests {
Some("Distort"),
Some("Perspective"),
None,
+ Some("Delete and Fill Selection"),
Some("Fill…"),
Some("Stroke…"),
Some("Content-Aware Fill…"),
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index cd0b4d35a..0eb5e8e30 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -107,6 +107,7 @@
Fill… Vyplnit…
Stroke… Tah…
Content-Aware Fill… Výplň s ohledem na obsah…
+ Delete and Fill Selection Odstranit a vyplnit výběr
Content-Aware Scale Změna velikosti s ohledem na obsah
Puppet Warp Loutková deformace
Perspective Warp Perspektivní deformace
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 3b056ea6d..0601fd0ca 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -103,6 +103,7 @@
Fill… Füllen…
Stroke… Nachziehen…
Content-Aware Fill… Inhaltsbasiert füllen…
+ Delete and Fill Selection Auswahl löschen und füllen
Content-Aware Scale Inhaltsbasiert skalieren
Puppet Warp Marionetten-Verkrümmung
Perspective Warp Perspektivisch verkrümmen
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 771026bf6..4d2f46a84 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -99,6 +99,7 @@
Fill… Rellenar…
Stroke… Contornear…
Content-Aware Fill… Relleno de contenido…
+ Delete and Fill Selection Eliminar y rellenar selección
Content-Aware Scale Escalado de contenido
Puppet Warp Deformación de clavos
Perspective Warp Deformación en perspectiva
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index 240355721..76bd2d140 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -105,6 +105,7 @@
Fill… Remplir…
Stroke… Contourner…
Content-Aware Fill… Remplissage d'après le contenu…
+ Delete and Fill Selection Supprimer et remplir la sélection
Content-Aware Scale Mise à l'échelle d'après le contenu
Puppet Warp Déformation par épingles
Perspective Warp Déformation de la perspective
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index b27a1dda2..a4db1cb31 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -98,6 +98,7 @@
Fill… Isi…
Stroke… Stroke…
Content-Aware Fill… Isi Content-Aware…
+ Delete and Fill Selection Hapus dan Isi Seleksi
Content-Aware Scale Skala Content-Aware
Puppet Warp Puppet Warp
Perspective Warp Perspective Warp
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 0636a91e8..cffe2d267 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -99,6 +99,7 @@
Fill… Riempi…
Stroke… Traccia…
Content-Aware Fill… Riempimento in base al contenuto…
+ Delete and Fill Selection Elimina e riempi selezione
Content-Aware Scale Scala in base al contenuto
Puppet Warp Altera marionetta
Perspective Warp Altera prospettiva
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index d9c784ee1..8e62c8a08 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -103,6 +103,7 @@
Fill… 塗りつぶし…
Stroke… 境界線を描く…
Content-Aware Fill… コンテンツに応じた塗りつぶし…
+ Delete and Fill Selection 選択範囲を削除して塗りつぶし
Content-Aware Scale コンテンツに応じた拡大・縮小
Puppet Warp パペットワープ
Perspective Warp 遠近法ワープ
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 38f7f1d6a..9147e7b72 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -95,6 +95,7 @@
Fill… 채우기…
Stroke… 획…
Content-Aware Fill… 내용 인식 채우기…
+ Delete and Fill Selection 선택 영역 삭제 및 채우기
Content-Aware Scale 내용 인식 비율
Puppet Warp 퍼펫 뒤틀기
Perspective Warp 원근 뒤틀기
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index 7fac44b70..8ab6dbcc8 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -102,6 +102,7 @@
Fill… Preencher…
Stroke… Traçado…
Content-Aware Fill… Preenchimento sensível ao conteúdo…
+ Delete and Fill Selection Excluir e preencher seleção
Content-Aware Scale Escala sensível ao conteúdo
Puppet Warp Distorção de marionete
Perspective Warp Distorção de perspectiva
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 48b3897ee..be0a5691d 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -82,6 +82,7 @@
Fill… Выполнить заливку…
Stroke… Обвести…
Content-Aware Fill… Заливка с учётом содержимого…
+ Delete and Fill Selection Удалить и заполнить выделение
Define Brush Preset… Определить кисть…
Define Pattern… Определить паттерн…
Define Custom Shape… Определить свою фигуру…
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index f8675e124..329d86369 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -99,6 +99,7 @@
Fill… 填充…
Stroke… 描边…
Content-Aware Fill… 内容识别填充…
+ Delete and Fill Selection 删除并填充选区
Content-Aware Scale 内容识别缩放
Puppet Warp 操控变形
Perspective Warp 透视变形
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 35b5744f6..030c046fd 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -107,6 +107,7 @@
Fill… 填滿…
Stroke… 筆畫…
Content-Aware Fill… 內容感知填滿…
+ Delete and Fill Selection 刪除並填滿選取範圍
Content-Aware Scale 內容感知縮放
Puppet Warp 操控彎曲
Perspective Warp 透視彎曲