Skip to content

Commit 91fffcb

Browse files
fix: add confirmation
1 parent f510002 commit 91fffcb

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/extension/preview.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,31 +182,37 @@ parentPort.onMessage('previewDiff', previewDiff)
182182
parentPort.onMessage('dismissDiff', dismissDiff)
183183
parentPort.onMessage('search', refreshDiff)
184184
parentPort.onMessage('commitChange', onCommitChange)
185-
parentPort.onMessage(
186-
'applyEdit',
187-
async function onApplyEdit(payload: ChildToParent['applyEdit']) {
188-
const workspaceEdit = new WorkspaceEdit()
185+
parentPort.onMessage('applyEdit', onApplyEdit)
189186

190-
for (const { filePath, replacements } of payload) {
191-
const documentUri = workspaceUriFromFilePath(filePath)!
187+
async function onApplyEdit(payload: ChildToParent['applyEdit']) {
188+
const confirmed = await window.showInformationMessage(
189+
'Replace all occurrences across all files?',
190+
{ modal: true },
191+
'Replace',
192+
)
193+
if (confirmed !== 'Replace') {
194+
return
195+
}
196+
for (const { filePath, replacements } of payload) {
197+
const workspaceEdit = new WorkspaceEdit()
198+
const documentUri = workspaceUriFromFilePath(filePath)!
192199

193-
for (const { range, text } of replacements) {
194-
workspaceEdit.replace(
195-
documentUri,
196-
new Range(
197-
range.start.line,
198-
range.start.column,
199-
range.end.line,
200-
range.end.column,
201-
),
202-
text,
203-
)
204-
}
200+
for (const { range, text } of replacements) {
201+
workspaceEdit.replace(
202+
documentUri,
203+
new Range(
204+
range.start.line,
205+
range.start.column,
206+
range.end.line,
207+
range.end.column,
208+
),
209+
text,
210+
)
205211
}
206-
207212
await workspace.applyEdit(workspaceEdit)
208-
},
209-
)
213+
await workspace.save(documentUri)
214+
}
215+
}
210216

211217
async function onCommitChange(payload: ChildToParent['commitChange']) {
212218
const { filePath, inputValue, rewrite } = payload

src/webview/SearchSidebar/SearchWidgetContainer/SearchWidget.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const styles = stylex.create({
4141
},
4242
replaceAll: {
4343
height: 24,
44+
marginRight: -2,
4445
},
4546
})
4647

@@ -61,7 +62,7 @@ function ReplaceBar() {
6162
title="Replace All"
6263
appearance="icon"
6364
disabled={disabled}
64-
onClick={() => replaceAll()}
65+
onClick={replaceAll}
6566
{...stylex.props(styles.replaceAll)}
6667
>
6768
<VscReplaceAll />

0 commit comments

Comments
 (0)