From 360576b770cd04e4a72d2cd62fe8746674c8b127 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Sat, 14 Sep 2024 11:46:10 +1200 Subject: [PATCH] Save target config file when hitting save in color preview --- FOCUS-CHANGELOG.txt | 1 + src/editors.jai | 11 ++++++++++- src/widgets/color_preview.jai | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/FOCUS-CHANGELOG.txt b/FOCUS-CHANGELOG.txt index 403439bf4..4813b13e8 100644 --- a/FOCUS-CHANGELOG.txt +++ b/FOCUS-CHANGELOG.txt @@ -22,6 +22,7 @@ + The `delete_to_start_of_line` command will now delete to the indentation level first, not to the very start of the line right away + Many internal changes to reduce the memory footprint and improve the cache friendliness of internal data structures + Files larger than the limit of 2,147,483,647 bytes will now no longer be loaded with an error message rather than crashing + + Hitting save when in the color preview editor will save the target config file, instead of attempting to save the color preview sample text somewhere # RELEASES ================================================================== diff --git a/src/editors.jai b/src/editors.jai index fcdec1034..099cb2245 100644 --- a/src/editors.jai +++ b/src/editors.jai @@ -177,7 +177,7 @@ active_editor_handle_event :: (editor: *Editor, buffer: *Buffer, event: Input.Ev reset_search_results(*editor.search_bar); editor.refresh_selection = true; - case .save; save(editor.buffer_id); + case .save; save(editor, editors.active); case .save_all; save_all(); case .save_as; defer_action_save_as(editor.buffer_id); case .move_current_file; defer_action_move (editor.buffer_id); @@ -1770,6 +1770,15 @@ select_all_occurrences :: (using editor: *Editor, buffer: Buffer, search_str := return editor.search_whole_words; } +save :: (editor: Editor, editor_id: s64) { + buffer_id := editor.buffer_id; + + // When hitting save while in the color preview panel, save the target config file instead + if is_color_preview_panel(editor_id) then buffer_id = color_preview_get_target_buffer_id(); + + save(buffer_id); +} + save :: (buffer_id: s64) { buffer := *open_buffers[buffer_id]; if buffer.readonly || buffer.internal return; diff --git a/src/widgets/color_preview.jai b/src/widgets/color_preview.jai index 5b6b9bd35..78c02a145 100644 --- a/src/widgets/color_preview.jai +++ b/src/widgets/color_preview.jai @@ -64,6 +64,10 @@ is_color_preview_panel :: inline (editor_id: s64) -> bool { return editor_id == panel_editor_id; } +color_preview_get_target_buffer_id :: inline () -> s64 { + return target_buffer_id; +} + color_preview_lose_focus :: () { // Sometimes we might want to make the previously active editor active, e.g. when deciding on new buffer placement if editors.active != editors.left && editors.active != editors.right && editors.left >= 0 && editors.right >= 0 {