Skip to content

Commit b8e8745

Browse files
fix default tool logic in gr.ImageEditor (#13379)
* fix default tool logic * add changeset * add regression test * fix test --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent 55b2660 commit b8e8745

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

.changeset/moody-sheep-press.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@gradio/imageeditor": patch
3+
"gradio": patch
4+
---
5+
6+
fix:fix default tool logic in gr.ImageEditor

js/imageeditor/shared/ImageEditor.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,12 @@
371371
ready = true;
372372
if (sources.length > 0) {
373373
handle_tool_change({ tool: "image" });
374-
} else {
374+
} else if (brush_options) {
375375
handle_tool_change({ tool: "draw" });
376+
} else if (eraser_options) {
377+
handle_tool_change({ tool: "erase" });
378+
} else {
379+
handle_tool_change({ tool: "image" });
376380
}
377381
crop.set_subtool("crop");
378382
});

test/components/test_image_editor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ def test_component_functions(self):
7777
"fixed_canvas": False,
7878
}
7979

80+
def test_brush_false_eraser_false_config(self):
81+
editor = gr.ImageEditor(
82+
brush=False,
83+
eraser=False,
84+
transforms=("crop",),
85+
sources=("upload", "clipboard"),
86+
layers=False,
87+
)
88+
config = editor.get_config()
89+
assert config["brush"] is False
90+
assert config["eraser"] is False
91+
assert config["transforms"] == ["crop"]
92+
8093
def test_process_example(self):
8194
test_image_path = "test/test_files/bus.png"
8295
image_editor = gr.ImageEditor()

0 commit comments

Comments
 (0)