Skip to content

The swiss army knife of lossless video/audio editing

Make template editor edits undoable with native undo

Claude3c1b6a4eb148
diff --git a/src/renderer/src/components/FileNameTemplateEditor.tsx b/src/renderer/src/components/FileNameTemplateEditor.tsx
index 6e3af3ae..016f5a33 100644
--- a/src/renderer/src/components/FileNameTemplateEditor.tsx
+++ b/src/renderer/src/components/FileNameTemplateEditor.tsx
@@ -125,6 +125,13 @@ function FileNameTemplateEditor(opts: {
}, [open]);
const reset = useCallback(() => {
+ // edit through the input so that native undo works. This goes through onChange and the debounce, so that the saved template always follows the text (also after an undo)
+ const input = inputRef.current;
+ if (input != null) {
+ input.focus();
+ input.select();
+ if (document.execCommand('insertText', false, defaultTemplate)) return;
+ }
setTemplate(defaultTemplate);
setText(defaultTemplate);
}, [defaultTemplate, setTemplate]);
@@ -143,6 +150,11 @@ function FileNameTemplateEditor(opts: {
const toInsert = variable === segTagsExample ? `${segTagsExample} ?? ''` : variable;
+ // insert through the input so that native undo works
+ input!.focus();
+ input!.setSelectionRange(startPos, endPos);
+ if (document.execCommand('insertText', false, formatVariable(toInsert))) return;
+
const newValue = `${text.slice(0, startPos)}${`${formatVariable(toInsert)}${text.slice(endPos)}`}`;
setText(newValue);
}, [text]);