mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Improvements to auto grid images (#29317)
This PR is a follow-up to ea1473e532. When we initially added the experimental feature for automatically adding `[grid]` to images, we add the [grid] surrounding images after all the uploads have been completed.
This can lead to confusion when `[grid]` is delayed to be added in the composer, as users may try to add grid manually leading to breakage. This also leads to issues with Discourse AI's automatic image caption feature.
**In this PR**: we simply move the logic to be added when the images are uploaded and processing. This way, `[grid]` surrounding images is added immediately. We also apply a fix for an edge-case to prevent images from being wrapped in `[grid]` when they are already inside `[grid]` tags.
This commit is contained in:
@@ -244,5 +244,43 @@ describe "Uploading files in the composer", type: :system do
|
||||
%r{!\[.*?\]\(upload://.*?\).*!\[.*?\]\(upload://.*?\).*!\[.*?\]\(upload://.*?\)}m,
|
||||
)
|
||||
end
|
||||
|
||||
it "does not automatically wrap images in [grid] tags when uploading inside an existing [grid]" do
|
||||
visit "/new-topic"
|
||||
expect(composer).to be_opened
|
||||
|
||||
composer.fill_content("[grid]\n\n[/grid]")
|
||||
composer.move_cursor_after("[grid]\n")
|
||||
|
||||
file_path_1 = file_from_fixtures("logo.png", "images").path
|
||||
file_path_2 = file_from_fixtures("logo.jpg", "images").path
|
||||
file_path_3 = file_from_fixtures("downsized.png", "images").path
|
||||
attach_file([file_path_1, file_path_2, file_path_3]) do
|
||||
composer.click_toolbar_button("upload")
|
||||
end
|
||||
expect(composer).to have_no_in_progress_uploads
|
||||
expect(composer.composer_input.value).to match(
|
||||
%r{\[grid\].*!\[.*?\]\(upload://.*?\).*!\[.*?\]\(upload://.*?\).*!\[.*?\]\(upload://.*?\).*?\[/grid\]}m,
|
||||
)
|
||||
end
|
||||
|
||||
it "automatically wraps images in [grid] when site language is different" do
|
||||
SiteSetting.default_locale = "es"
|
||||
|
||||
visit "/new-topic"
|
||||
expect(composer).to be_opened
|
||||
|
||||
file_path_1 = file_from_fixtures("logo.png", "images").path
|
||||
file_path_2 = file_from_fixtures("logo.jpg", "images").path
|
||||
file_path_3 = file_from_fixtures("downsized.png", "images").path
|
||||
attach_file([file_path_1, file_path_2, file_path_3]) do
|
||||
composer.click_toolbar_button("upload")
|
||||
end
|
||||
|
||||
expect(composer).to have_no_in_progress_uploads
|
||||
expect(composer.composer_input.value).to match(
|
||||
%r{\[grid\].*!\[.*?\]\(upload://.*?\).*!\[.*?\]\(upload://.*?\).*!\[.*?\]\(upload://.*?\).*?\[/grid\]}m,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user