Implement post editor image drops.

This commit is contained in:
2026-07-20 16:19:14 +02:00
parent 49447ef451
commit 29cdd016b8
15 changed files with 616 additions and 53 deletions

View File

@@ -218,6 +218,12 @@ impl PostEditorState {
self.mark_dirty();
}
pub fn insert_dropped_image(&mut self, media_path: &str) {
self.insert_markdown_at_cursor(&bds_core::engine::post::post_insert_media(
media_path, true, "",
));
}
pub fn set_editor_mode(&mut self, mode: &str) {
self.editor_mode = normalize_editor_mode(mode);
}
@@ -1218,6 +1224,17 @@ mod tests {
assert!(state.is_dirty);
}
#[test]
fn dropped_image_markdown_is_inserted_at_the_buffer_cursor() {
let mut state = sample_state();
state.editor_buffer.borrow_mut().set_cursor(0, 5);
state.insert_dropped_image("media/2026/07/media-1.png");
assert_eq!(state.content, "Hello![](/media/2026/07/media-1.png) world");
assert!(state.is_dirty);
}
#[test]
fn unsupported_default_mode_falls_back_to_markdown() {
let mut state = sample_state();