@@ -94,10 +94,11 @@ local validate_fs_entry = function(x)
94
94
eq (type (x .path ), ' string' )
95
95
end
96
96
97
- local validate_confirm_args = function (ref_msg_pattern )
97
+ local validate_confirm_args = function (ref_msg_pattern , can_cancel )
98
+ if can_cancel == nil then can_cancel = true end
98
99
local args = child .lua_get (' _G.confirm_args' )
99
100
expect .match (args [1 ], ref_msg_pattern )
100
- if args [2 ] ~= nil then eq (args [2 ], ' &Yes\n &No' ) end
101
+ if args [2 ] ~= nil then eq (args [2 ], ' &Yes\n &No' .. ( can_cancel and ' \n &Cancel ' or ' ' ) ) end
101
102
if args [3 ] ~= nil then eq (args [3 ], 1 ) end
102
103
if args [4 ] ~= nil then eq (args [4 ], ' Question' ) end
103
104
end
@@ -926,7 +927,7 @@ T['open()']['properly closes currently opened explorer with pending file system
926
927
-- Should mention modified buffers and ask for confirmation
927
928
mock_confirm (1 )
928
929
open (path_2 )
929
- validate_confirm_args (' pending file system actions.*Close without sync' )
930
+ validate_confirm_args (' pending file system actions.*Close without sync' , false )
930
931
931
932
-- Should trigger proper event for closing explorer
932
933
eq (child .lua_get (' _G.had_close_event' ), true )
@@ -1075,7 +1076,7 @@ T['refresh()']['handles presence of pending file system actions'] = function()
1075
1076
child .lua (' MiniFiles.refresh({ content = { filter = _G.hide_dotfiles }, windows = { width_focus = 30 } })' )
1076
1077
child .expect_screenshot ()
1077
1078
1078
- validate_confirm_args (' pending file system actions.*Update buffers without sync' )
1079
+ validate_confirm_args (' pending file system actions.*Update buffers without sync' , false )
1079
1080
1080
1081
-- On no confirm should not update buffers, but still apply other changes
1081
1082
type_keys (' o' , ' new-file-2' , ' <Esc>' )
@@ -1111,7 +1112,7 @@ T['synchronize()']['can update external file system changes'] = function()
1111
1112
validate_cur_line (1 )
1112
1113
1113
1114
vim .fn .mkdir (join_path (temp_dir , ' aaa' ))
1114
- synchronize ()
1115
+ eq ( synchronize (), true )
1115
1116
child .expect_screenshot ()
1116
1117
1117
1118
-- Cursor should be "sticked" to current entry
@@ -1124,14 +1125,31 @@ T['synchronize()']['can apply file system actions'] = function()
1124
1125
open (temp_dir )
1125
1126
type_keys (' i' , ' new-file' , ' <Esc>' )
1126
1127
1127
- local new_file_path = join_path (temp_dir , ' new-file' )
1128
1128
mock_confirm (1 )
1129
1129
1130
1130
validate_tree (temp_dir , {})
1131
- synchronize ()
1131
+ eq ( synchronize (), true )
1132
1132
validate_tree (temp_dir , { ' new-file' })
1133
1133
end
1134
1134
1135
+ T [' synchronize()' ][' can cancel synchronization' ] = function ()
1136
+ local temp_dir = make_temp_dir (' temp' , {})
1137
+
1138
+ open (temp_dir )
1139
+ type_keys (' i' , ' new-file' , ' <Esc>' )
1140
+
1141
+ child .fn .writefile ({ ' ' }, join_path (temp_dir , ' aaa' ))
1142
+
1143
+ mock_confirm (3 )
1144
+
1145
+ validate_tree (temp_dir , { ' aaa' })
1146
+ eq (synchronize (), false )
1147
+ -- Should not apply file system changes, not sync external changes, and keep
1148
+ -- buffers as is
1149
+ validate_tree (temp_dir , { ' aaa' })
1150
+ eq (get_lines (), { ' new-file' })
1151
+ end
1152
+
1135
1153
T [' synchronize()' ][' should follow cursor on current entry path' ] = function ()
1136
1154
local temp_dir = make_temp_dir (' temp' , { ' dir/' , ' file' })
1137
1155
@@ -1256,7 +1274,7 @@ T['close()']['checks for pending file system actions'] = function()
1256
1274
mock_confirm (2 )
1257
1275
eq (close (), false )
1258
1276
child .expect_screenshot ()
1259
- validate_confirm_args (' pending file system actions.*Close without sync' )
1277
+ validate_confirm_args (' pending file system actions.*Close without sync' , false )
1260
1278
1261
1279
-- - Should not trigger close event (as there was no closing)
1262
1280
eq (child .lua_get (' _G.had_close_event' ), vim .NIL )
0 commit comments