Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Support custom editors (#9950)

Jonny Burgera50cb6f9926f
diff --git a/packages/cli/src/test/config-reload.test.ts b/packages/cli/src/test/config-reload.test.ts
index ed2510872a..5ea14719a4 100644
--- a/packages/cli/src/test/config-reload.test.ts
+++ b/packages/cli/src/test/config-reload.test.ts
@@ -67,7 +67,7 @@ test('an invalid config reload keeps the previous configuration', async () => {
expect(ConfigInternals.getStudioPort()).toBe(4321);
writeConfig(
- `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(6789); Config.setDefaultEditor('zed');`,
+ `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(6789); Config.setDefaultEditor({type: 'custom', name: 'Acme Editor', executable: '/opt/acme/editor', arguments: ['--goto', '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%']});`,
);
expect(
await reloadConfig({
@@ -78,7 +78,12 @@ test('an invalid config reload keeps the previous configuration', async () => {
expect(
BrowserSafeApis.options.defaultEditorOption.getValue({commandLine: {}})
.value,
- ).toBe('zed');
+ ).toEqual({
+ type: 'custom',
+ name: 'Acme Editor',
+ executable: '/opt/acme/editor',
+ arguments: ['--goto', '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%'],
+ });
writeConfig(
`const {Config} = require('@remotion/cli/config'); Config.setStudioPort(7890);`,
diff --git a/packages/cli/src/test/config-reset.test.ts b/packages/cli/src/test/config-reset.test.ts
index 1446816015..658a7ead37 100644
--- a/packages/cli/src/test/config-reset.test.ts
+++ b/packages/cli/src/test/config-reset.test.ts
@@ -135,7 +135,12 @@ test('reset config options restores defaults before reloading config', async ()
test('the CLI editor flag takes precedence over Config.setDefaultEditor()', () => {
ConfigInternals.resetConfigOptions();
- Config.setDefaultEditor('cursor');
+ Config.setDefaultEditor({
+ type: 'custom',
+ name: 'Acme Editor',
+ executable: '/opt/acme/editor',
+ arguments: ['--goto', '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%'],
+ });
expect(
BrowserSafeApis.options.defaultEditorOption.getValue({
@@ -145,6 +150,14 @@ test('the CLI editor flag takes precedence over Config.setDefaultEditor()', () =
expect(() => Config.setDefaultEditor('invalid' as 'cursor')).toThrow(
'Config.setDefaultEditor() must be one of',
);
+ expect(() =>
+ Config.setDefaultEditor({
+ type: 'custom',
+ name: 'Acme Editor',
+ executable: '/opt/acme/editor',
+ arguments: ['--goto'],
+ }),
+ ).toThrow('Custom editor arguments must include %TARGET_PATH%');
});
test('bundler overrides can be fixed at Studio startup', async () => {
diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdx
index f4d93ecc17..eed4ff72d2 100644
--- a/packages/docs/docs/config.mdx
+++ b/packages/docs/docs/config.mdx
@@ -231,17 +231,7 @@ The [command line flag](/docs/cli/studio#--disable-interactivity) `--disable-int
<Options id="editor" />
-```ts twoslash title="remotion.config.ts"
-import {Config} from '@remotion/cli/config';
-// ---cut---
-Config.setDefaultEditor('cursor');
-```
-
-The supported editor IDs are `vscode`, `cursor`, `windsurf`, `zed`, `vscodium`, `webstorm`, and `sublime-text`. `vscode` also recognizes VS Code Insiders, and `zed` also recognizes Zed Preview.
-
-The editor is detected from its installation and does not need to be running. If the configured editor is not installed, Remotion prints a warning and falls back to automatic editor detection.
-
-The [command line flag](/docs/cli/studio#--editor) `--editor` will take precedence over this option.
+See [Opening files in a code editor](/docs/studio/open-in-editor) for built-in editor IDs, custom editor configuration, and platform support.
## ~~`setAllowHtmlInCanvasEnabled()`~~<AvailableFrom v="4.0.447" />
diff --git a/packages/docs/docs/studio/open-in-editor.mdx b/packages/docs/docs/studio/open-in-editor.mdx
new file mode 100644
index 0000000000..001c8b6d9a
--- /dev/null
+++ b/packages/docs/docs/studio/open-in-editor.mdx
@@ -0,0 +1,101 @@
+---
+image: /generated/articles-docs-studio-open-in-editor.png
+title: Setting the default code editor
+sidebar_label: Opening in code editor
+crumb: 'Remotion Studio'
+---
+
+# Open in code editor<AvailableFrom v="4.0.503" />
+
+Remotion Studio can quickly open various things in your code editor:
+
+- compositions
+- sequences
+- error stack frames
+
+If no preference was set, Remotion will try to detect an already running editor.
+
+## Setting your preferred editor
+
+### In the Studio
+
+In Remotion Studio, select `Configure default editor...` from the Remotion menu to choose from an installed editor. This also writes in the config file (see below).
+
+<img src="/img/configure-default-editor.png" alt="Configure default editor item in the Remotion menu" style={{width: '293px'}} />
+
+### In the config file
+
+Set the editor for your project using [`Config.setDefaultEditor()`](/docs/config#setdefaulteditor):
+
+```ts twoslash title="remotion.config.ts"
+import {Config} from '@remotion/cli/config';
+// ---cut---
+Config.setDefaultEditor('cursor');
+```
+
+The supported editor IDs are:
+- `vscode` (also recognizes Insiders)
+- `cursor`
+- `windsurf`
+- `zed` (also recognizes Zed Preview)
+- `vscodium`
+- `webstorm`
+- `sublime-text`.
+
+If the configured editor is not installed, Remotion prints a warning and falls back to automatic editor detection.
+If you work in a team with differing preferences, we recommend setting an environment variable and reading from `process.env`.
+
+### Via command line
+
+The [`--editor`](/docs/cli/studio#--editor) command line flag takes precedence over all other options.
+
+### Configuring a custom editor
+
+This works only in the config file.
+Pass a custom editor object if your editor is not built in:
+
+```ts twoslash title="remotion.config.ts"
+import {Config} from '@remotion/cli/config';
+// ---cut---
+Config.setDefaultEditor({
+ type: 'custom',
+ name: 'My Editor',
+ executable: process.env.REMOTION_EDITOR_PATH!,
+ arguments: ['--goto', '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%'],
+});
+```
+
+Use an environment variable for an absolute executable path if the configuration file is committed, because installation paths differ between computers.
+
+### `type`
+
+Must be `'custom'`.
+
+### `name`
+
+The name shown in Remotion Studio.
+
+### `executable`
+
+An executable path or a command on `PATH`. macOS `.app` bundles, Linux executables, and Windows `.exe` and `.com` files are supported.
+
+Windows scripts such as `.bat` and `.cmd` are not supported because they require a shell.
+
+### `arguments`
+
+An array containing one command-line argument per item. Do not add quotes around paths with spaces; each item is passed directly to the executable without shell parsing.
+
+At least one item must include `%TARGET_PATH%`. Remotion replaces these placeholders before launching the editor:
+
+| Placeholder | Value |
+| ----------------- | ------------------------------------------------------------------------------------------------------------- |
+| `%TARGET_PATH%` | Absolute source file or project directory path. Windows editors launched through WSL receive a relative path. |
+| `%LINE_NUMBER%` | One-based source line. |
+| `%COLUMN_NUMBER%` | One-based source column. |
+
+
+## See also
+
+- [`Config.setDefaultEditor()`](/docs/config#setdefaulteditor)
+- [`remotion studio`](/docs/cli/studio)
+- [Quick Switcher](/docs/studio/quick-switcher)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 331f2648f7..b1cbe7b138 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1334,6 +1334,7 @@ const sidebars: SidebarsConfig = {
label: 'Studio',
items: [
'studio/studio',
+ 'studio/open-in-editor',
'studio/shortcuts',
'studio/quick-switcher',
'studio/interactivity',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 3d29c9daa3..e42a5c8706 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -6976,6 +6976,15 @@ export const articles = [
noAi: false,
slug: 'studio/make-component-interactive',
},
+ {
+ id: 'studio/open-in-editor',
+ title: 'Setting the default code editor',
+ relativePath: 'docs/studio/open-in-editor.mdx',
+ compId: 'articles-docs-studio-open-in-editor',
+ crumb: 'Remotion Studio',
+ noAi: false,
+ slug: 'studio/open-in-editor',
+ },
{
id: 'studio/pause',
title: 'pause()',
diff --git a/packages/docs/static/generated/articles-docs-studio-open-in-editor.png b/packages/docs/static/generated/articles-docs-studio-open-in-editor.png
new file mode 100644
index 0000000000..c8ca2dcaf0
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-open-in-editor.png differ
diff --git a/packages/docs/static/img/configure-default-editor.png b/packages/docs/static/img/configure-default-editor.png
new file mode 100644
index 0000000000..fd365825cc
Binary files /dev/null and b/packages/docs/static/img/configure-default-editor.png differ
diff --git a/packages/renderer/src/client.ts b/packages/renderer/src/client.ts
index 9be8ce1620..8617c65b46 100644
--- a/packages/renderer/src/client.ts
+++ b/packages/renderer/src/client.ts
@@ -35,8 +35,17 @@ import {
} from './pixel-format';
import {validateOutputFilename} from './validate-output-filename';
export {AvailableOptions, TypeOfOption} from './options';
-export {defaultEditorIds} from './options/default-editor';
-export type {DefaultEditor} from './options/default-editor';
+export {
+ customEditorColumnNumberPlaceholder,
+ customEditorLineNumberPlaceholder,
+ customEditorTargetPathPlaceholder,
+ defaultEditorIds,
+} from './options/default-editor';
+export type {
+ BuiltInEditor,
+ CustomEditor,
+ DefaultEditor,
+} from './options/default-editor';
export {HardwareAccelerationOption} from './options/hardware-acceleration';
export {ProResProfile} from './options/prores-profile';
diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.ts
index 64209ac506..c203776b48 100644
--- a/packages/renderer/src/index.ts
+++ b/packages/renderer/src/index.ts
@@ -119,8 +119,17 @@ export type {ChromiumOptions} from './open-browser';
export {ChromeMode} from './options/chrome-mode';
export {ColorSpace} from './options/color-space';
export type {Concurrency} from './options/concurrency';
-export {defaultEditorIds} from './options/default-editor';
-export type {DefaultEditor} from './options/default-editor';
+export {
+ customEditorColumnNumberPlaceholder,
+ customEditorLineNumberPlaceholder,
+ customEditorTargetPathPlaceholder,
+ defaultEditorIds,
+} from './options/default-editor';
+export type {
+ BuiltInEditor,
+ CustomEditor,
+ DefaultEditor,
+} from './options/default-editor';
export type {DeleteAfter} from './options/delete-after';
export {OpenGlRenderer} from './options/gl';
export {NumberOfGifLoops} from './options/number-of-gif-loops';
diff --git a/packages/renderer/src/options/default-editor.tsx b/packages/renderer/src/options/default-editor.tsx
index d1619d8d46..4024f6163d 100644
--- a/packages/renderer/src/options/default-editor.tsx
+++ b/packages/renderer/src/options/default-editor.tsx
@@ -10,29 +10,98 @@ export const defaultEditorIds = [
'sublime-text',
] as const;
-export type DefaultEditor = (typeof defaultEditorIds)[number];
+export const customEditorTargetPathPlaceholder = '%TARGET_PATH%' as const;
+export const customEditorLineNumberPlaceholder = '%LINE_NUMBER%' as const;
+export const customEditorColumnNumberPlaceholder = '%COLUMN_NUMBER%' as const;
+
+export type BuiltInEditor = (typeof defaultEditorIds)[number];
+
+export type CustomEditor = {
+ readonly type: 'custom';
+ readonly name: string;
+ readonly executable: string;
+ readonly arguments: readonly string[];
+};
+
+export type DefaultEditor = BuiltInEditor | CustomEditor;
const cliFlag = 'editor' as const;
let defaultEditor: DefaultEditor | null = null;
-const validateDefaultEditor = (
+const validateBuiltInEditor = (
value: unknown,
source: string,
-): DefaultEditor | null => {
- if (value === null) {
- return null;
- }
-
+): BuiltInEditor => {
if (
typeof value !== 'string' ||
- !defaultEditorIds.includes(value as DefaultEditor)
+ !defaultEditorIds.includes(value as BuiltInEditor)
) {
throw new TypeError(
`${source} must be one of: ${defaultEditorIds.join(', ')}. Received: ${JSON.stringify(value)}`,
);
}
- return value as DefaultEditor;
+ return value as BuiltInEditor;
+};
+
+const validateCustomEditor = (value: unknown, source: string): CustomEditor => {
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
+ throw new TypeError(
+ `${source} must be a built-in editor ID or a custom editor object. Received: ${JSON.stringify(value)}`,
+ );
+ }
+
+ const editor = value as Partial<CustomEditor>;
+ if (editor.type !== 'custom') {
+ throw new TypeError(`${source}: Custom editors must have type "custom".`);
+ }
+
+ if (typeof editor.name !== 'string' || editor.name.trim() === '') {
+ throw new TypeError(`${source}: Custom editor name must not be empty.`);
+ }
+
+ if (
+ typeof editor.executable !== 'string' ||
+ editor.executable.trim() === ''
+ ) {
+ throw new TypeError(
+ `${source}: Custom editor executable must not be empty.`,
+ );
+ }
+
+ if (
+ !Array.isArray(editor.arguments) ||
+ !editor.arguments.every((argument) => typeof argument === 'string')
+ ) {
+ throw new TypeError(
+ `${source}: Custom editor arguments must be an array of strings.`,
+ );
+ }
+
+ if (
+ !editor.arguments.some((argument) =>
+ argument.includes(customEditorTargetPathPlaceholder),
+ )
+ ) {
+ throw new TypeError(
+ `${source}: Custom editor arguments must include ${customEditorTargetPathPlaceholder}.`,
+ );
+ }
+
+ return editor as CustomEditor;
+};
+
+const validateDefaultEditor = (
+ value: unknown,
+ source: string,
+): DefaultEditor | null => {
+ if (value === null) {
+ return null;
+ }
+
+ return typeof value === 'string'
+ ? validateBuiltInEditor(value, source)
+ : validateCustomEditor(value, source);
};
export const defaultEditorOption = {
@@ -45,13 +114,13 @@ export const defaultEditorOption = {
</>
),
ssrName: null,
- docLink: 'https://www.remotion.dev/docs/config#setdefaulteditor',
+ docLink: 'https://www.remotion.dev/docs/studio/open-in-editor',
type: null as DefaultEditor | null,
getValue: ({commandLine}) => {
const cliValue = commandLine[cliFlag];
if (cliValue !== undefined && cliValue !== null) {
return {
- value: validateDefaultEditor(cliValue, `--${cliFlag}`),
+ value: validateBuiltInEditor(cliValue, `--${cliFlag}`),
source: 'cli',
};
}
diff --git a/packages/studio-server/src/helpers/custom-editor.ts b/packages/studio-server/src/helpers/custom-editor.ts
new file mode 100644
index 0000000000..a58a7d5121
--- /dev/null
+++ b/packages/studio-server/src/helpers/custom-editor.ts
@@ -0,0 +1,264 @@
+import type {ChildProcess} from 'node:child_process';
+import {spawn} from 'node:child_process';
+import {accessSync, constants, existsSync, lstatSync} from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import type {CustomEditor, LogLevel} from '@remotion/renderer';
+import {
+ customEditorColumnNumberPlaceholder,
+ customEditorLineNumberPlaceholder,
+ customEditorTargetPathPlaceholder,
+ RenderInternals,
+} from '@remotion/renderer';
+
+type CustomEditorPathType = 'file' | 'directory' | 'symbolic-link' | null;
+
+export type CustomEditorResolutionContext = {
+ platform: NodeJS.Platform;
+ env: NodeJS.ProcessEnv;
+ currentWorkingDirectory: string;
+ inspectPath: (filePath: string) => CustomEditorPathType;
+ canExecute: (filePath: string) => boolean;
+};
+
+export type ResolvedCustomEditorExecutable = {
+ executable: string;
+ spawnAsMacApplication: boolean;
+};
+
+const defaultResolutionContext: CustomEditorResolutionContext = {
+ platform: process.platform,
+ env: process.env,
+ currentWorkingDirectory: process.cwd(),
+ inspectPath: (filePath) => {
+ try {
+ const stat = lstatSync(filePath);
+ if (stat.isSymbolicLink()) {
+ return 'symbolic-link';
+ }
+
+ if (stat.isFile()) {
+ return 'file';
+ }
+
+ return stat.isDirectory() ? 'directory' : null;
+ } catch {
+ return null;
+ }
+ },
+ canExecute: (filePath) => {
+ try {
+ accessSync(filePath, constants.X_OK);
+ return true;
+ } catch {
+ return false;
+ }
+ },
+};
+
+const getExecutableCandidates = ({
+ executable,
+ context,
+}: {
+ executable: string;
+ context: CustomEditorResolutionContext;
+}) => {
+ const pathApi = context.platform === 'win32' ? path.win32 : path.posix;
+ const hasDirectory =
+ pathApi.isAbsolute(executable) ||
+ executable.includes('/') ||
+ executable.includes('\\');
+ if (hasDirectory) {
+ return [
+ pathApi.isAbsolute(executable)
+ ? executable
+ : pathApi.resolve(context.currentWorkingDirectory, executable),
+ ];
+ }
+
+ const pathDirectories = (context.env.PATH ?? '')
+ .split(context.platform === 'win32' ? ';' : ':')
+ .filter(Boolean);
+ if (context.platform !== 'win32') {
+ return pathDirectories.map((directory) =>
+ pathApi.join(directory, executable),
+ );
+ }
+
+ const currentExtension = path.win32.extname(executable).toLowerCase();
+ const extensions = currentExtension
+ ? ['']
+ : (context.env.PATHEXT ?? '.COM;.EXE')
+ .split(';')
+ .map((extension) => extension.toLowerCase())
+ .filter((extension) => extension === '.com' || extension === '.exe');
+ return pathDirectories.flatMap((directory) =>
+ extensions.map((extension) =>
+ pathApi.join(directory, `${executable}${extension}`),
+ ),
+ );
+};
+
+export const resolveCustomEditorExecutable = (
+ editor: CustomEditor,
+ context: CustomEditorResolutionContext = defaultResolutionContext,
+): ResolvedCustomEditorExecutable | null => {
+ for (const candidate of getExecutableCandidates({
+ executable: editor.executable,
+ context,
+ })) {
+ const pathType = context.inspectPath(candidate);
+ if (
+ context.platform === 'darwin' &&
+ (pathType === 'directory' || pathType === 'symbolic-link') &&
+ candidate.toLowerCase().endsWith('.app')
+ ) {
+ return {executable: candidate, spawnAsMacApplication: true};
+ }
+
+ if (pathType !== 'file' && pathType !== 'symbolic-link') {
+ continue;
+ }
+
+ if (context.platform === 'win32') {
+ const extension = path.win32.extname(candidate).toLowerCase();
+ if (extension !== '.exe' && extension !== '.com') {
+ continue;
+ }
+ } else if (!context.canExecute(candidate)) {
+ continue;
+ }
+
+ return {executable: candidate, spawnAsMacApplication: false};
+ }
+
+ return null;
+};
+
+export const normalizeCustomEditorTargetPath = ({
+ targetPath,
+ platform,
+ release,
+ currentWorkingDirectory,
+}: {
+ targetPath: string;
+ platform: NodeJS.Platform;
+ release: string;
+ currentWorkingDirectory: string;
+}) => {
+ if (
+ platform === 'linux' &&
+ targetPath.startsWith('/mnt/') &&
+ /Microsoft/i.test(release)
+ ) {
+ return path.posix.relative(currentWorkingDirectory, targetPath);
+ }
+
+ return targetPath;
+};
+
+export const expandCustomEditorArguments = ({
+ argumentTemplates,
+ targetPath,
+ lineNumber,
+ columnNumber,
+}: {
+ argumentTemplates: readonly string[];
+ targetPath: string;
+ lineNumber: number;
+ columnNumber: number;
+}) => {
+ return argumentTemplates.map((argument) =>
+ argument
+ .replaceAll(customEditorTargetPathPlaceholder, targetPath)
+ .replaceAll(customEditorLineNumberPlaceholder, String(lineNumber))
+ .replaceAll(customEditorColumnNumberPlaceholder, String(columnNumber)),
+ );
+};
+
+export const launchCustomEditor = ({
+ editor,
+ resolvedExecutable,
+ targetPath,
+ lineNumber,
+ columnNumber,
+ logLevel,
+ spawnProcess = spawn,
+}: {
+ editor: CustomEditor;
+ resolvedExecutable: ResolvedCustomEditorExecutable;
+ targetPath: string;
+ lineNumber: number;
+ columnNumber: number;
+ logLevel: LogLevel;
+ spawnProcess?: typeof spawn;
+}): Promise<boolean> => {
+ if (
+ !existsSync(targetPath) ||
+ !Number.isInteger(lineNumber) ||
+ lineNumber <= 0
+ ) {
+ return Promise.resolve(false);
+ }
+
+ const safeColumnNumber =
+ Number.isInteger(columnNumber) && columnNumber > 0 ? columnNumber : 1;
+ const normalizedTargetPath = normalizeCustomEditorTargetPath({
+ targetPath,
+ platform: process.platform,
+ release: os.release(),
+ currentWorkingDirectory: process.cwd(),
+ });
+ const editorArguments = expandCustomEditorArguments({
+ argumentTemplates: editor.arguments,
+ targetPath: normalizedTargetPath,
+ lineNumber,
+ columnNumber: safeColumnNumber,
+ });
+ const command = resolvedExecutable.spawnAsMacApplication
+ ? 'open'
+ : resolvedExecutable.executable;
+ const args = resolvedExecutable.spawnAsMacApplication
+ ? ['-a', resolvedExecutable.executable, ...editorArguments]
+ : editorArguments;
+
+ return new Promise<boolean>((resolve) => {
+ let child: ChildProcess;
+ try {
+ child = spawnProcess(command, args, {
+ detached: true,
+ shell: false,
+ stdio: 'ignore',
+ });
+ } catch (error) {
+ RenderInternals.Log.error(
+ {indent: false, logLevel},
+ `Could not launch custom editor ${editor.name}:`,
+ error,
+ );
+ resolve(false);
+ return;
+ }
+
+ child.once('error', (error) => {
+ RenderInternals.Log.error(
+ {indent: false, logLevel},
+ `Could not launch custom editor ${editor.name}:`,
+ error,
+ );
+ resolve(false);
+ });
+ child.once('spawn', () => {
+ child.unref();
+ resolve(true);
+ });
+ child.on('exit', (exitCode) => {
+ if (exitCode) {
+ RenderInternals.Log.error(
+ {indent: false, logLevel},
+ `Custom editor ${editor.name} exited with code ${exitCode}.`,
+ );
+ }
+ });
+ });
+};
diff --git a/packages/studio-server/src/helpers/editor-registry.ts b/packages/studio-server/src/helpers/editor-registry.ts
index 57af0efb21..e055cf2104 100644
--- a/packages/studio-server/src/helpers/editor-registry.ts
+++ b/packages/studio-server/src/helpers/editor-registry.ts
@@ -3,13 +3,13 @@ import {existsSync} from 'node:fs';
import {homedir} from 'node:os';
import path from 'node:path';
import {promisify} from 'node:util';
-import type {DefaultEditor} from '@remotion/renderer';
+import type {BuiltInEditor} from '@remotion/renderer';
import {defaultEditorIds} from '@remotion/renderer';
const execFilePromise = promisify(execFile);
export type InstalledEditor = {
- id: DefaultEditor;
+ id: BuiltInEditor;
name: string;
process: string;
command: string;
@@ -42,7 +42,7 @@ export type EditorDiscoveryContext = {
pathExists: (filePath: string) => boolean;
findMacApplications: (bundleIdentifier: string) => Promise<readonly string[]>;
findWindowsApplications: (
- editor: DefaultEditor,
+ editor: BuiltInEditor,
) => Promise<readonly string[]>;
};
@@ -346,9 +346,9 @@ const editorDefinitions = {
},
],
},
-} satisfies Record<DefaultEditor, EditorDefinition>;
+} satisfies Record<BuiltInEditor, EditorDefinition>;
-export const getDefaultEditorName = (id: DefaultEditor) =>
+export const getDefaultEditorName = (id: BuiltInEditor) =>
editorDefinitions[id].darwin[0].name;
const findMacApplications = async (
@@ -380,7 +380,7 @@ const windowsDisplayNamePrefixes = {
vscodium: ['VSCodium'],
webstorm: ['WebStorm', 'JetBrains WebStorm'],
'sublime-text': ['Sublime Text'],
-} satisfies Record<DefaultEditor, readonly string[]>;
+} satisfies Record<BuiltInEditor, readonly string[]>;
const parseWindowsRegistryApplications = (
output: string,
@@ -455,7 +455,7 @@ const getWindowsRegistryApplications = () => {
return windowsRegistryApplications;
};
-const findWindowsApplications = async (editor: DefaultEditor) => {
+const findWindowsApplications = async (editor: BuiltInEditor) => {
const prefixes = windowsDisplayNamePrefixes[editor];
const applications = await getWindowsRegistryApplications();
return applications
@@ -481,7 +481,7 @@ const findDarwinEditor = async ({
variants,
context,
}: {
- id: DefaultEditor;
+ id: BuiltInEditor;
variants: readonly DarwinEditorVariant[];
context: EditorDiscoveryContext;
}): Promise<InstalledEditor | null> => {
@@ -558,7 +558,7 @@ const findExecutableEditor = ({
context,
additionalPaths,
}: {
- id: DefaultEditor;
+ id: BuiltInEditor;
variants: readonly ExecutableEditorVariant[];
context: EditorDiscoveryContext;
additionalPaths: readonly string[];
diff --git a/packages/studio-server/src/helpers/resolve-editor.ts b/packages/studio-server/src/helpers/resolve-editor.ts
index 5eb2b23919..5e31153586 100644
--- a/packages/studio-server/src/helpers/resolve-editor.ts
+++ b/packages/studio-server/src/helpers/resolve-editor.ts
@@ -1,28 +1,49 @@
-import type {DefaultEditor, LogLevel} from '@remotion/renderer';
+import type {
+ BuiltInEditor,
+ CustomEditor,
+ DefaultEditor,
+ LogLevel,
+} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
+import {
+ resolveCustomEditorExecutable,
+ type ResolvedCustomEditorExecutable,
+} from './custom-editor';
import {getAvailableEditors, getDefaultEditorName} from './editor-registry';
import type {InstalledEditor} from './editor-registry';
import {getDisplayNameForEditor, guessEditor} from './open-in-editor';
import type {ProcessAndCommand} from './open-in-editor';
-export type ResolvedEditor = ProcessAndCommand & {
- id: DefaultEditor | null;
- name: string;
-};
+export type ResolvedEditor =
+ | (ProcessAndCommand & {
+ type: 'built-in';
+ id: BuiltInEditor | null;
+ name: string;
+ })
+ | (ResolvedCustomEditorExecutable & {
+ type: 'custom';
+ id: 'custom';
+ name: string;
+ editor: CustomEditor;
+ });
type ResolveEditorDependencies = {
getInstalledEditors: () => Promise<readonly InstalledEditor[]>;
getLegacyEditors: () => Promise<readonly ProcessAndCommand[]>;
+ resolveCustomEditor: (
+ editor: CustomEditor,
+ ) => ResolvedCustomEditorExecutable | null;
warn: (message: string) => void;
- warnedEditors: Set<DefaultEditor>;
+ warnedEditors: Set<string>;
};
const legacyEditors = guessEditor();
-const warnedEditors = new Set<DefaultEditor>();
+const warnedEditors = new Set<string>();
const defaultDependencies: ResolveEditorDependencies = {
getInstalledEditors: getAvailableEditors,
getLegacyEditors: () => legacyEditors,
+ resolveCustomEditor: resolveCustomEditorExecutable,
warn: () => undefined,
warnedEditors,
};
@@ -45,13 +66,34 @@ export const resolveEditor = async (
...overrides,
};
- if (defaultEditor) {
+ if (defaultEditor && typeof defaultEditor === 'object') {
+ const resolvedExecutable = dependencies.resolveCustomEditor(defaultEditor);
+ if (resolvedExecutable) {
+ return {
+ ...resolvedExecutable,
+ type: 'custom',
+ id: 'custom',
+ name: defaultEditor.name,
+ editor: defaultEditor,
+ };
+ }
+
+ const warningId = `custom:${defaultEditor.executable}`;
+ if (!dependencies.warnedEditors.has(warningId)) {
+ dependencies.warnedEditors.add(warningId);
+ dependencies.warn(
+ `The executable for custom editor ${defaultEditor.name} (${defaultEditor.executable}) was not found or is not executable. Falling back to automatic editor detection.`,
+ );
+ }
+ }
+
+ if (typeof defaultEditor === 'string') {
const installedEditors = await dependencies.getInstalledEditors();
const installedEditor = installedEditors.find(
(editor) => editor.id === defaultEditor,
);
if (installedEditor) {
- return installedEditor;
+ return {...installedEditor, type: 'built-in'};
}
if (!dependencies.warnedEditors.has(defaultEditor)) {
@@ -69,6 +111,7 @@ export const resolveEditor = async (
return {
...legacyEditor,
+ type: 'built-in',
id: null,
name: getDisplayNameForEditor(legacyEditor.command) ?? legacyEditor.command,
};
diff --git a/packages/studio-server/src/preview-server/routes/default-editor.ts b/packages/studio-server/src/preview-server/routes/default-editor.ts
index c922d2fb8b..34d9fb65ef 100644
--- a/packages/studio-server/src/preview-server/routes/default-editor.ts
+++ b/packages/studio-server/src/preview-server/routes/default-editor.ts
@@ -1,5 +1,5 @@
import {readFileSync} from 'node:fs';
-import type {DefaultEditor} from '@remotion/renderer';
+import type {BuiltInEditor} from '@remotion/renderer';
import {defaultEditorIds} from '@remotion/renderer';
import type {
GetDefaultEditorInfoRequest,
@@ -18,7 +18,7 @@ export const updateDefaultEditorInConfig = ({
defaultEditor,
}: {
configContents: string;
- defaultEditor: DefaultEditor | null;
+ defaultEditor: BuiltInEditor | null;
}) => {
const ast = parseAst(configContents);
recast.types.visit(ast.program, {
@@ -57,16 +57,27 @@ export const getDefaultEditorInfoHandler: ApiHandler<
GetDefaultEditorInfoResponse
> = async ({getDefaultEditor}) => {
const installedEditors = await getAvailableEditors();
+ const configuredEditor = getDefaultEditor();
+ const customEditor =
+ configuredEditor && typeof configuredEditor === 'object'
+ ? configuredEditor
+ : null;
return {
- defaultEditor: getDefaultEditor(),
- installedEditors: installedEditors.map(({id, name}) => ({id, name})),
+ defaultEditor:
+ typeof configuredEditor === 'object' ? 'custom' : configuredEditor,
+ installedEditors: [
+ ...installedEditors.map(({id, name}) => ({id, name})),
+ ...(customEditor
+ ? [{id: 'custom' as const, name: customEditor.name}]
+ : []),
+ ],
};
};
export const updateDefaultEditorHandler: ApiHandler<
UpdateDefaultEditorRequest,
UpdateDefaultEditorResponse
-> = async ({input, configFile}) => {
+> = async ({input, configFile, getDefaultEditor}) => {
if (configFile === null || configFile === undefined) {
return {
success: false,
@@ -74,9 +85,24 @@ export const updateDefaultEditorHandler: ApiHandler<
};
}
+ if (input.defaultEditor === 'custom') {
+ const configuredEditor = getDefaultEditor();
+ if (!configuredEditor || typeof configuredEditor !== 'object') {
+ return {
+ success: false,
+ reason: 'No custom editor is configured.',
+ };
+ }
+
+ // The browser only knows the opaque "custom" ID. Keeping the existing
+ // config call untouched avoids exposing or rewriting its executable and
+ // arguments, which may have come from environment variables.
+ return {success: true};
+ }
+
if (
input.defaultEditor !== null &&
- !defaultEditorIds.includes(input.defaultEditor)
+ !defaultEditorIds.includes(input.defaultEditor as BuiltInEditor)
) {
return {
success: false,
@@ -99,7 +125,7 @@ export const updateDefaultEditorHandler: ApiHandler<
configFile,
updateDefaultEditorInConfig({
configContents,
- defaultEditor: input.defaultEditor,
+ defaultEditor: input.defaultEditor as BuiltInEditor | null,
}),
undefined,
);
diff --git a/packages/studio-server/src/preview-server/routes/open-in-editor.ts b/packages/studio-server/src/preview-server/routes/open-in-editor.ts
index b30b98a5ee..19c271ec97 100644
--- a/packages/studio-server/src/preview-server/routes/open-in-editor.ts
+++ b/packages/studio-server/src/preview-server/routes/open-in-editor.ts
@@ -4,6 +4,7 @@ import type {
OpenInEditorRequest,
OpenInEditorResponse,
} from '@remotion/studio-shared';
+import {launchCustomEditor} from '../../helpers/custom-editor';
import {launchEditor} from '../../helpers/open-in-editor';
import {resolveEditor} from '../../helpers/resolve-editor';
import type {ApiHandler} from '../api-types';
@@ -40,14 +41,28 @@ export const openInEditorHandler: ApiHandler<
return {success: false};
}
- const didOpen = await launchEditor({
- colNumber: stack.originalColumnNumber as number,
- editor,
- fileName: path.resolve(remotionRoot, stack.originalFileName as string),
- lineNumber: stack.originalLineNumber as number,
- vsCodeNewWindow: false,
- logLevel,
- });
+ const fileName = path.resolve(
+ remotionRoot,
+ stack.originalFileName as string,
+ );
+ const didOpen =
+ editor.type === 'custom'
+ ? await launchCustomEditor({
+ editor: editor.editor,
+ resolvedExecutable: editor,
+ targetPath: fileName,
+ lineNumber: stack.originalLineNumber as number,
+ columnNumber: stack.originalColumnNumber as number,
+ logLevel,
+ })
+ : await launchEditor({
+ colNumber: stack.originalColumnNumber as number,
+ editor,
+ fileName,
+ lineNumber: stack.originalLineNumber as number,
+ vsCodeNewWindow: false,
+ logLevel,
+ });
return {
success: didOpen,
diff --git a/packages/studio-server/src/test/custom-editor.test.ts b/packages/studio-server/src/test/custom-editor.test.ts
new file mode 100644
index 0000000000..08b1cc611b
--- /dev/null
+++ b/packages/studio-server/src/test/custom-editor.test.ts
@@ -0,0 +1,214 @@
+import {expect, test} from 'bun:test';
+import {
+ chmodSync,
+ existsSync,
+ mkdtempSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {tmpdir} from 'node:os';
+import path from 'node:path';
+import type {CustomEditor} from '@remotion/renderer';
+import {
+ expandCustomEditorArguments,
+ normalizeCustomEditorTargetPath,
+ resolveCustomEditorExecutable,
+ type CustomEditorResolutionContext,
+} from '../helpers/custom-editor';
+import {openInEditorHandler} from '../preview-server/routes/open-in-editor';
+
+const editor = (executable: string): CustomEditor => ({
+ type: 'custom',
+ name: 'Acme Editor',
+ executable,
+ arguments: ['%TARGET_PATH%'],
+});
+
+const makeResolutionContext = ({
+ platform,
+ env,
+ paths,
+ executablePaths = Object.keys(paths),
+}: {
+ platform: NodeJS.Platform;
+ env: NodeJS.ProcessEnv;
+ paths: Record<
+ string,
+ Exclude<ReturnType<CustomEditorResolutionContext['inspectPath']>, null>
+ >;
+ executablePaths?: readonly string[];
+}): CustomEditorResolutionContext => ({
+ platform,
+ env,
+ currentWorkingDirectory:
+ platform === 'win32' ? 'C:\\project' : '/home/project',
+ inspectPath: (filePath) => paths[filePath] ?? null,
+ canExecute: (filePath) => executablePaths.includes(filePath),
+});
+
+test('resolves commands, Windows executables, and macOS app bundles without a shell', () => {
+ expect(
+ resolveCustomEditorExecutable(
+ editor('acme'),
+ makeResolutionContext({
+ platform: 'linux',
+ env: {PATH: '/usr/local/bin:/usr/bin'},
+ paths: {'/usr/local/bin/acme': 'file'},
+ }),
+ ),
+ ).toEqual({
+ executable: '/usr/local/bin/acme',
+ spawnAsMacApplication: false,
+ });
+
+ expect(
+ resolveCustomEditorExecutable(
+ editor('acme'),
+ makeResolutionContext({
+ platform: 'win32',
+ env: {PATH: 'C:\\Tools', PATHEXT: '.CMD;.EXE'},
+ paths: {'C:\\Tools\\acme.exe': 'file'},
+ }),
+ ),
+ ).toEqual({
+ executable: 'C:\\Tools\\acme.exe',
+ spawnAsMacApplication: false,
+ });
+
+ expect(
+ resolveCustomEditorExecutable(
+ editor('/Applications/Acme Editor.app'),
+ makeResolutionContext({
+ platform: 'darwin',
+ env: {},
+ paths: {'/Applications/Acme Editor.app': 'directory'},
+ }),
+ ),
+ ).toEqual({
+ executable: '/Applications/Acme Editor.app',
+ spawnAsMacApplication: true,
+ });
+
+ expect(
+ resolveCustomEditorExecutable(
+ editor('C:\\Tools\\acme.cmd'),
+ makeResolutionContext({
+ platform: 'win32',
+ env: {},
+ paths: {'C:\\Tools\\acme.cmd': 'file'},
+ }),
+ ),
+ ).toBeNull();
+
+ expect(
+ resolveCustomEditorExecutable(
+ editor('/opt/acme/editor'),
+ makeResolutionContext({
+ platform: 'linux',
+ env: {},
+ paths: {'/opt/acme/editor': 'file'},
+ executablePaths: [],
+ }),
+ ),
+ ).toBeNull();
+
+ expect(
+ resolveCustomEditorExecutable(
+ editor('missing-editor'),
+ makeResolutionContext({
+ platform: 'linux',
+ env: {PATH: '/usr/bin'},
+ paths: {},
+ }),
+ ),
+ ).toBeNull();
+});
+
+test('expands each placeholder without reparsing argument tokens', () => {
+ expect(
+ expandCustomEditorArguments({
+ argumentTemplates: [
+ '--goto',
+ '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%',
+ '"%TARGET_PATH%"',
+ ],
+ targetPath: '/tmp/a project/with "quotes".tsx',
+ lineNumber: 12,
+ columnNumber: 4,
+ }),
+ ).toEqual([
+ '--goto',
+ '/tmp/a project/with "quotes".tsx:12:4',
+ '"/tmp/a project/with "quotes".tsx"',
+ ]);
+});
+
+test('uses a relative target path for Windows editors launched through WSL', () => {
+ expect(
+ normalizeCustomEditorTargetPath({
+ targetPath: '/mnt/c/Users/test/project/video.tsx',
+ platform: 'linux',
+ release: '5.15.0-Microsoft-standard-WSL2',
+ currentWorkingDirectory: '/mnt/c/Users/test/project',
+ }),
+ ).toBe('video.tsx');
+});
+
+test.skipIf(process.platform === 'win32')(
+ 'opens a source location through the route using the configured custom editor',
+ async () => {
+ const directory = mkdtempSync(
+ path.join(tmpdir(), 'remotion-custom-editor-'),
+ );
+ const executable = path.join(directory, 'acme editor');
+ const output = path.join(directory, 'received arguments.txt');
+ const source = path.join(directory, 'source file.tsx');
+ writeFileSync(
+ executable,
+ '#!/bin/sh\noutput="$1"\nshift\nprintf "%s\\n" "$@" > "$output"\n',
+ );
+ chmodSync(executable, 0o755);
+ writeFileSync(source, 'export const Component = () => null;\n');
+
+ try {
+ const response = await openInEditorHandler({
+ binariesDirectory: null,
+ configFile: null,
+ entryPoint: '',
+ getDefaultEditor: () => ({
+ type: 'custom',
+ name: 'Acme Editor',
+ executable,
+ arguments: [output, '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%'],
+ }),
+ input: {
+ stack: {
+ originalFileName: path.basename(source),
+ originalLineNumber: 12,
+ originalColumnNumber: 4,
+ } as never,
+ },
+ logLevel: 'error',
+ methods: {
+ addJob: () => undefined,
+ cancelJob: () => undefined,
+ removeJob: () => undefined,
+ },
+ publicDir: '',
+ remotionRoot: directory,
+ request: {} as never,
+ response: {} as never,
+ });
+
+ expect(response).toEqual({success: true});
+ for (let attempt = 0; attempt < 100 && !existsSync(output); attempt++) {
+ await Bun.sleep(10);
+ }
+
+ expect(readFileSync(output, 'utf8')).toBe(`${source}:12:4\n`);
+ } finally {
+ rmSync(directory, {force: true, recursive: true});
+ }
+ },
+);
diff --git a/packages/studio-server/src/test/default-editor-route.test.ts b/packages/studio-server/src/test/default-editor-route.test.ts
index 217d3e9f13..24cb34cefa 100644
--- a/packages/studio-server/src/test/default-editor-route.test.ts
+++ b/packages/studio-server/src/test/default-editor-route.test.ts
@@ -7,10 +7,27 @@ import {
setFileWatcherRegistry,
} from '../file-watcher';
import {
+ getDefaultEditorInfoHandler,
updateDefaultEditorHandler,
updateDefaultEditorInConfig,
} from '../preview-server/routes/default-editor';
+const apiHandlerContext = {
+ binariesDirectory: null,
+ configFile: null,
+ entryPoint: '',
+ logLevel: 'error' as const,
+ methods: {
+ addJob: () => undefined,
+ cancelJob: () => undefined,
+ removeJob: () => undefined,
+ },
+ publicDir: '',
+ remotionRoot: '',
+ request: {} as never,
+ response: {} as never,
+};
+
test('appends the default editor to the config on a new line', () => {
expect(
updateDefaultEditorInConfig({
@@ -68,6 +85,90 @@ test('preserves commented and string references to the setter', () => {
);
});
+test('exposes only an opaque ID and name for a configured custom editor', async () => {
+ const response = await getDefaultEditorInfoHandler({
+ ...apiHandlerContext,
+ getDefaultEditor: () => ({
+ type: 'custom',
+ name: 'Acme Editor',
+ executable: '/private/acme/editor',
+ arguments: ['--goto', '%TARGET_PATH%'],
+ }),
+ input: {},
+ });
+
+ expect(response.defaultEditor).toBe('custom');
+ expect(response.installedEditors).toContainEqual({
+ id: 'custom',
+ name: 'Acme Editor',
+ });
+ expect(JSON.stringify(response)).not.toContain('/private/acme/editor');
+ expect(JSON.stringify(response)).not.toContain('%TARGET_PATH%');
+});
+
+test('keeps the server-side custom editor definition when Studio selects it', async () => {
+ const directory = mkdtempSync(join(tmpdir(), 'remotion-default-editor-'));
+ const configFile = join(directory, 'remotion.config.ts');
+ const configContents = [
+ "import {Config} from '@remotion/cli/config';",
+ 'Config.setDefaultEditor({',
+ "\ttype: 'custom',",
+ "\tname: 'Acme Editor',",
+ '\texecutable: process.env.REMOTION_EDITOR_PATH!,',
+ "\targuments: ['%TARGET_PATH%'],",
+ '});',
+ '',
+ ].join('\n');
+ writeFileSync(configFile, configContents);
+
+ try {
+ const response = await updateDefaultEditorHandler({
+ ...apiHandlerContext,
+ configFile,
+ getDefaultEditor: () => ({
+ type: 'custom',
+ name: 'Acme Editor',
+ executable: '/resolved/acme/editor',
+ arguments: ['%TARGET_PATH%'],
+ }),
+ input: {defaultEditor: 'custom'},
+ });
+
+ expect(response).toEqual({success: true});
+ expect(readFileSync(configFile, 'utf8')).toBe(configContents);
+ } finally {
+ rmSync(directory, {force: true, recursive: true});
+ }
+});
+
+test('rejects custom editor definitions sent by the browser', async () => {
+ const directory = mkdtempSync(join(tmpdir(), 'remotion-default-editor-'));
+ const configFile = join(directory, 'remotion.config.ts');
+ writeFileSync(configFile, "import {Config} from '@remotion/cli/config';\n");
+
+ try {
+ const response = await updateDefaultEditorHandler({
+ ...apiHandlerContext,
+ configFile,
+ getDefaultEditor: () => null,
+ input: {
+ defaultEditor: {
+ type: 'custom',
+ executable: '/tmp/untrusted',
+ arguments: ['%TARGET_PATH%'],
+ } as never,
+ },
+ });
+
+ expect(response.success).toBe(false);
+ expect(readFileSync(configFile, 'utf8')).toBe(
+ "import {Config} from '@remotion/cli/config';\n",
+ );
+ } finally {
+ rmSync(directory, {force: true, recursive: true});
+ }
+});
+
test('removes the configured editor when selecting no preference', async () => {
const directory = mkdtempSync(join(tmpdir(), 'remotion-default-editor-'));
const configFile = join(directory, 'remotion.config.ts');
diff --git a/packages/studio-server/src/test/editor-registry.test.ts b/packages/studio-server/src/test/editor-registry.test.ts
index 15379c7183..f9a4f94fa7 100644
--- a/packages/studio-server/src/test/editor-registry.test.ts
+++ b/packages/studio-server/src/test/editor-registry.test.ts
@@ -1,6 +1,6 @@
import {expect, test} from 'bun:test';
import path from 'node:path';
-import type {DefaultEditor} from '@remotion/renderer';
+import type {BuiltInEditor} from '@remotion/renderer';
import {
discoverAvailableEditors,
getDefaultEditorName,
@@ -22,7 +22,7 @@ const makeContext = ({
paths: readonly string[];
env?: NodeJS.ProcessEnv;
macApplications?: Record<string, readonly string[]>;
- windowsApplications?: Partial<Record<DefaultEditor, readonly string[]>>;
+ windowsApplications?: Partial<Record<BuiltInEditor, readonly string[]>>;
}): EditorDiscoveryContext => {
const existingPaths = new Set(paths);
return {
@@ -126,13 +126,73 @@ test('uses the configured installed editor instead of legacy detection', async (
},
);
- expect(resolved).toEqual(cursor);
+ expect(resolved).toEqual({...cursor, type: 'built-in'});
expect(legacyDetectionCalls).toBe(0);
});
+test('resolves a custom editor without exposing it to built-in discovery', async () => {
+ let installedEditorDetectionCalls = 0;
+ const customEditor = {
+ type: 'custom',
+ name: 'Acme Editor',
+ executable: '/opt/acme/editor',
+ arguments: ['--goto', '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%'],
+ } as const;
+ const resolved = await resolveEditor(
+ {defaultEditor: customEditor, logLevel: 'info'},
+ {
+ getInstalledEditors: () => {
+ installedEditorDetectionCalls++;
+ return Promise.resolve([]);
+ },
+ resolveCustomEditor: () => ({
+ executable: '/opt/acme/editor',
+ spawnAsMacApplication: false,
+ }),
+ },
+ );
+
+ expect(installedEditorDetectionCalls).toBe(0);
+ expect(resolved).toEqual({
+ type: 'custom',
+ id: 'custom',
+ name: 'Acme Editor',
+ editor: customEditor,
+ executable: '/opt/acme/editor',
+ spawnAsMacApplication: false,
+ });
+});
+
+test('warns and falls back when a custom editor executable is unavailable', async () => {
+ const warnings: string[] = [];
+ const resolved = await resolveEditor(
+ {
+ defaultEditor: {
+ type: 'custom',
+ name: 'Acme Editor',
+ executable: '/missing/acme',
+ arguments: ['%TARGET_PATH%'],
+ },
+ logLevel: 'info',
+ },
+ {
+ getLegacyEditors: () =>
+ Promise.resolve([{command: 'code', process: 'code'}]),
+ resolveCustomEditor: () => null,
+ warn: (message) => warnings.push(message),
+ warnedEditors: new Set(),
+ },
+ );
+
+ expect(resolved?.name).toBe('VS Code');
+ expect(warnings).toEqual([
+ 'The executable for custom editor Acme Editor (/missing/acme) was not found or is not executable. Falling back to automatic editor detection.',
+ ]);
+});
+
test('warns once and falls back when the configured editor is unavailable', async () => {
const warnings: string[] = [];
- const warnedEditors = new Set<DefaultEditor>();
+ const warnedEditors = new Set<string>();
const dependencies = {
getInstalledEditors: () => Promise.resolve([]),
getLegacyEditors: () =>
@@ -155,6 +215,7 @@ test('warns once and falls back when the configured editor is unavailable', asyn
id: null,
name: 'VS Code',
process: 'code',
+ type: 'built-in',
});
expect(second).toEqual(first);
expect(warnings).toEqual([
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index 403e2e4507..55c087fa2c 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -1,9 +1,9 @@
import type {
AudioCodec,
+ BuiltInEditor,
ChromeMode,
Codec,
ColorSpace,
- DefaultEditor,
LogLevel,
PixelFormat,
StillImageFormat,
@@ -989,13 +989,14 @@ export type UpdatePublicLicenseResponse =
};
export type GetDefaultEditorInfoRequest = {};
+export type EditorPickerId = BuiltInEditor | 'custom';
export type GetDefaultEditorInfoResponse = {
- defaultEditor: DefaultEditor | null;
- installedEditors: {id: DefaultEditor; name: string}[];
+ defaultEditor: EditorPickerId | null;
+ installedEditors: {id: EditorPickerId; name: string}[];
};
export type UpdateDefaultEditorRequest = {
- defaultEditor: DefaultEditor | null;
+ defaultEditor: EditorPickerId | null;
};
export type UpdateDefaultEditorResponse =
| {
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 5c8d1ec944..418cc37516 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -50,6 +50,7 @@ export {
ElementInstallExpectedFileState,
ElementInstallRequest,
ElementInstallSource,
+ EditorPickerId,
FindInFileRequest,
FindInFileResponse,
GetDefaultEditorInfoRequest,
diff --git a/packages/studio/src/components/ConfigureDefaultEditorModal.tsx b/packages/studio/src/components/ConfigureDefaultEditorModal.tsx
index 464c4d9a8c..3ff3b439c3 100644
--- a/packages/studio/src/components/ConfigureDefaultEditorModal.tsx
+++ b/packages/studio/src/components/ConfigureDefaultEditorModal.tsx
@@ -1,5 +1,7 @@
-import type {DefaultEditor} from '@remotion/renderer';
-import type {GetDefaultEditorInfoResponse} from '@remotion/studio-shared';
+import type {
+ EditorPickerId,
+ GetDefaultEditorInfoResponse,
+} from '@remotion/studio-shared';
import React, {
useCallback,
useContext,
@@ -9,6 +11,7 @@ import React, {
} from 'react';
import {LIGHT_TEXT} from '../helpers/colors';
import {Checkmark} from '../icons/Checkmark';
+import {CustomEditorIcon} from '../icons/custom-editor';
import {ModalsContext} from '../state/modals';
import {callApi} from './call-api';
import {Row, Spacing} from './layout';
@@ -39,13 +42,36 @@ const comboBoxStyle: React.CSSProperties = {
width: '100%',
};
+const customEditorLabel: React.CSSProperties = {
+ display: 'inline-flex',
+ alignItems: 'center',
+ gap: 8,
+ maxWidth: '100%',
+ minWidth: 0,
+ color: 'inherit',
+ fontFamily: 'inherit',
+ fontSize: 'inherit',
+ lineHeight: 'inherit',
+};
+
+const customEditorName: React.CSSProperties = {
+ minWidth: 0,
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ color: 'inherit',
+ fontFamily: 'inherit',
+ fontSize: 'inherit',
+ lineHeight: 'inherit',
+};
+
const NO_PREFERENCE_ID = 'no-preference';
export const ConfigureDefaultEditorModal: React.FC = () => {
const {setSelectedModal} = useContext(ModalsContext);
const [editorInfo, setEditorInfo] =
useState<GetDefaultEditorInfoResponse | null>(null);
- const [selectedEditor, setSelectedEditor] = useState<DefaultEditor | null>(
+ const [selectedEditor, setSelectedEditor] = useState<EditorPickerId | null>(
null,
);
const [isSubmitting, setIsSubmitting] = useState(false);
@@ -70,7 +96,15 @@ export const ConfigureDefaultEditorModal: React.FC = () => {
return {
id: editor.id,
keyHint: null,
- label: editor.name,
+ label:
+ editor.id === 'custom' ? (
+ <span style={customEditorLabel}>
+ <CustomEditorIcon />
+ <span style={customEditorName}>{editor.name}</span>
+ </span>
+ ) : (
+ editor.name
+ ),
leftItem: selectedEditor === editor.id ? <Checkmark /> : null,
onClick: () => {
setSelectedEditor(editor.id);
diff --git a/packages/studio/src/icons/custom-editor.tsx b/packages/studio/src/icons/custom-editor.tsx
new file mode 100644
index 0000000000..a1a0f0f01a
--- /dev/null
+++ b/packages/studio/src/icons/custom-editor.tsx
@@ -0,0 +1,22 @@
+import React from 'react';
+import {CURRENT_COLOR} from '../helpers/colors';
+
+export const CustomEditorIcon: React.FC<{readonly size?: number}> = ({
+ size = 14,
+}) => (
+ <svg
+ focusable="false"
+ role="img"
+ viewBox="0 0 24 24"
+ style={{width: size, height: size, flexShrink: 0}}
+ >
+ <path
+ fill="none"
+ stroke={CURRENT_COLOR}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.8"
+ d="m8 8-4 4 4 4m8-8 4 4-4 4m-2-10-4 12"
+ />
+ </svg>
+);