Summary
ToptalMinifierReplaceCommand captures the selection offsets (start, end) before the asynchronous API request and applies the result at those same offsets when the response arrives (toptal_minifier_apply_replace). If the buffer changes while the request is in flight (typing, another plugin, undo, an external reload), the minified text is written over whatever now occupies those offsets, corrupting the file, and the original selection stays untouched.
Repro (ToptalMinifier, Sublime Text 4200; network replaced by a stub that returns MIN after 1.5 s, using the package's own command class and its real toptal_minifier_apply_replace command)
Buffer alpha\nbeta\ngamma\n, select beta, run the in-place replace command; while the request is pending, insert a line at the top of the buffer.
Result after the response:
'// heaMINline added meanwhile\nalpha\nbeta\ngamma\n'
MIN replaced 4 characters at offsets 6-10 of the new text (inside the freshly typed header line) and beta was never replaced.
Suggested fix
Record view.change_count() before the request and, in apply_result, refuse to apply (show "buffer changed, minified result discarded/copied to clipboard") if it changed; or track the region with a view.add_regions key (regions follow edits) and replace that region instead of stored offsets.
Summary
ToptalMinifierReplaceCommandcaptures the selection offsets (start,end) before the asynchronous API request and applies the result at those same offsets when the response arrives (toptal_minifier_apply_replace). If the buffer changes while the request is in flight (typing, another plugin, undo, an external reload), the minified text is written over whatever now occupies those offsets, corrupting the file, and the original selection stays untouched.Repro (ToptalMinifier, Sublime Text 4200; network replaced by a stub that returns
MINafter 1.5 s, using the package's own command class and its realtoptal_minifier_apply_replacecommand)Buffer
alpha\nbeta\ngamma\n, selectbeta, run the in-place replace command; while the request is pending, insert a line at the top of the buffer.Result after the response:
MINreplaced 4 characters at offsets 6-10 of the new text (inside the freshly typed header line) andbetawas never replaced.Suggested fix
Record
view.change_count()before the request and, inapply_result, refuse to apply (show "buffer changed, minified result discarded/copied to clipboard") if it changed; or track the region with aview.add_regionskey (regions follow edits) and replace that region instead of stored offsets.