Skip to content

@jsvision/files / openFileInEditor

Function: openFileInEditor()

openFileInEditor(host, opts): object

Defined in: files/src/editor/open-file.ts:41

Open (or create) a file in a new editor window on the desktop.

Parameters

host

An object with a desktop to add the window to — the createApplication result works.

desktop

Pick<Desktop, "addWindow">

opts

OpenFileInEditorOptions

The editor options (fs required; omit fileName for an untitled buffer) plus rect.

Returns

object

The mounted window and its editor.

editor

editor: FileEditor

window

window: EditWindow

Example

ts
import { createApplication } from '@jsvision/ui';
import { resolveCapabilities } from '@jsvision/core';
import { openFileInEditor, nodeFileSystem } from '@jsvision/files';

const caps = resolveCapabilities({ env: process.env, platform: process.platform }).profile;
const app = createApplication({ caps });

const { window, editor } = openFileInEditor(app, {
  fs: nodeFileSystem,
  fileName: '/home/user/notes.txt',   // omit for an untitled buffer
  rect: { x: 2, y: 2, width: 60, height: 20 },
});
await editor.save();