@@ -157,25 +157,36 @@ M.move_node = function(source, destination, callback, using_root_directory)
157
157
)
158
158
local _ , name = utils .split_path (source )
159
159
get_unused_name (destination or source , using_root_directory , function (dest )
160
- create_all_parents (dest )
161
- loop .fs_rename (source , dest , function (err )
162
- if err then
163
- log .error (" Could not move the files from" , source , " to" , dest , " :" , err )
164
- return
165
- end
166
- vim .schedule (function ()
167
- rename_buffer (source , dest )
168
- end )
169
- vim .schedule (function ()
170
- events .fire_event (events .FILE_MOVED , {
171
- source = source ,
172
- destination = dest ,
173
- })
174
- if callback then
175
- callback (source , dest )
160
+ local function move_file ()
161
+ create_all_parents (dest )
162
+ loop .fs_rename (source , dest , function (err )
163
+ if err then
164
+ log .error (" Could not move the files from" , source , " to" , dest , " :" , err )
165
+ return
176
166
end
167
+ vim .schedule (function ()
168
+ rename_buffer (source , dest )
169
+ end )
170
+ vim .schedule (function ()
171
+ events .fire_event (events .FILE_MOVED , {
172
+ source = source ,
173
+ destination = dest ,
174
+ })
175
+ if callback then
176
+ callback (source , dest )
177
+ end
178
+ end )
177
179
end )
178
- end )
180
+ end
181
+ local event_result = events .fire_event (events .BEFORE_FILE_MOVE , {
182
+ source = source ,
183
+ destination = dest ,
184
+ callback = move_file ,
185
+ }) or {}
186
+ if event_result .handled then
187
+ return
188
+ end
189
+ move_file ()
179
190
end , ' Move "' .. name .. ' " to:' )
180
191
end
181
192
@@ -530,14 +541,26 @@ M.rename_node = function(path, callback)
530
541
log .info (" Renamed " .. new_name .. " successfully" )
531
542
end )
532
543
533
- loop .fs_rename (path , destination , function (err )
534
- if err then
535
- log .warn (" Could not rename the files" )
536
- return
537
- else
538
- complete ()
539
- end
540
- end )
544
+ local function fs_rename ()
545
+ loop .fs_rename (path , destination , function (err )
546
+ if err then
547
+ log .warn (" Could not rename the files" )
548
+ return
549
+ else
550
+ complete ()
551
+ end
552
+ end )
553
+ end
554
+
555
+ local event_result = events .fire_event (events .BEFORE_FILE_RENAME , {
556
+ source = path ,
557
+ destination = destination ,
558
+ callback = fs_rename ,
559
+ }) or {}
560
+ if event_result .handled then
561
+ return
562
+ end
563
+ fs_rename ()
541
564
end )
542
565
end
543
566
0 commit comments