From 54c5ce389b4ba98ee583127f6b198b681f94d804 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 7 Oct 2019 18:08:42 -0700 Subject: [PATCH] Fixed paste next _again_ fixed the really horrible nonsense with ! marked files --- 4ed_edit.cpp | 2 +- 4ed_file.cpp | 11 ++++------- 4ed_file.h | 8 +++++++- 4ed_working_set.cpp | 18 ++++++++++++------ custom/4coder_clipboard.cpp | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/4ed_edit.cpp b/4ed_edit.cpp index 13714d69..3f497570 100644 --- a/4ed_edit.cpp +++ b/4ed_edit.cpp @@ -528,7 +528,7 @@ create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags) } if (file != 0 && HasFlag(flags, BufferCreate_JustChangedFile)){ - file->state.ignore_behind_os = 1; + file->state.save_state = FileSaveState_SavedWaitingForNotification; } if (file != 0 && HasFlag(flags, BufferCreate_AlwaysNew)){ diff --git a/4ed_file.cpp b/4ed_file.cpp index e8c1c5e7..d8d23bbf 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -168,16 +168,13 @@ save_file_to_name(Models *models, Editing_File *file, u8 *file_name){ String_Const_u8 saveable_string = buffer_stringify(scratch, buffer, Ii64(0, buffer_size(buffer))); File_Attributes new_attributes = system_save_file(scratch, (char*)file_name, saveable_string); - if (new_attributes.last_write_time > 0){ - if (using_actual_file_name){ - file->state.ignore_behind_os = 1; - } - file->attributes = new_attributes; + if (new_attributes.last_write_time > 0 && + using_actual_file_name){ + file->state.save_state = FileSaveState_SavedWaitingForNotification; + file_clear_dirty_flags(file); } LogEventF(log_string(M), scratch, file->id, 0, system_thread_get_id(), "save file [last_write_time=0x%llx]", new_attributes.last_write_time); - - file_clear_dirty_flags(file); } return(result); diff --git a/4ed_file.h b/4ed_file.h index b9441d41..b62e230f 100644 --- a/4ed_file.h +++ b/4ed_file.h @@ -50,6 +50,12 @@ struct Line_Layout_Key{ i64 line_number; }; +typedef i32 File_Save_State; +enum{ + FileSaveState_Normal, + FileSaveState_SavedWaitingForNotification, +}; + struct Editing_File_State{ Gap_Buffer buffer; @@ -59,7 +65,7 @@ struct Editing_File_State{ Text_Effect paste_effect; Dirty_State dirty; - u32 ignore_behind_os; + File_Save_State save_state; File_Edit_Positions edit_pos_most_recent; File_Edit_Positions edit_pos_stack[16]; diff --git a/4ed_working_set.cpp b/4ed_working_set.cpp index a6cd633e..ed9ed573 100644 --- a/4ed_working_set.cpp +++ b/4ed_working_set.cpp @@ -22,12 +22,18 @@ file_change_notification_check(Arena *scratch, Working_Set *working_set, Editing String_Const_u8 name = SCu8(file->canon.name_space, file->canon.name_size); File_Attributes attributes = system_quick_file_attributes(scratch, name); if (attributes.last_write_time > file->attributes.last_write_time){ - file_add_dirty_flag(file, DirtyState_UnloadedChanges); - if (file->external_mod_node.next == 0){ - LogEventF(log_string(M), &working_set->arena, file->id, 0, system_thread_get_id(), - "external modification [lwt=0x%llx]", attributes.last_write_time); - dll_insert_back(&working_set->has_external_mod_sentinel, &file->external_mod_node); - system_signal_step(0); + if (file->state.save_state == FileSaveState_SavedWaitingForNotification){ + file->state.save_state = FileSaveState_Normal; + file->attributes = attributes; + } + else{ + file_add_dirty_flag(file, DirtyState_UnloadedChanges); + if (file->external_mod_node.next == 0){ + LogEventF(log_string(M), &working_set->arena, file->id, 0, system_thread_get_id(), + "external modification [lwt=0x%llx]", attributes.last_write_time); + dll_insert_back(&working_set->has_external_mod_sentinel, &file->external_mod_node); + system_signal_step(0); + } } } file->attributes = attributes; diff --git a/custom/4coder_clipboard.cpp b/custom/4coder_clipboard.cpp index 20e29b29..035a3824 100644 --- a/custom/4coder_clipboard.cpp +++ b/custom/4coder_clipboard.cpp @@ -81,7 +81,7 @@ CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste Managed_Scope scope = view_get_managed_scope(app, view); no_mark_snap_to_cursor(app, scope); - Rewrite_Type *rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); + Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type); if (*rewrite == Rewrite_Paste){ Rewrite_Type *next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type); *next_rewrite = Rewrite_Paste;