Skip to content

@jsvision/files / FileEditor

Class: FileEditor

Defined in: files/src/editor/file-editor.ts:46

The file-bound editor (load/save/saveAs, .bak backups, modified-close prompts).

Example

ts
import { FileEditor, nodeFileSystem } from '@jsvision/files';

const editor = new FileEditor({ fs: nodeFileSystem, fileName: '/home/user/notes.txt' });
editor.loadFile();          // empty + valid if the file does not exist yet
editor.setText('hello\n');
const saved = await editor.save(); // true on success; writes notes.txt (and notes.bak)

Extends

  • Editor

Constructors

Constructor

new FileEditor(options): FileEditor

Defined in: files/src/editor/file-editor.ts:54

Parameters

options

FileEditorOptions

Returns

FileEditor

Overrides

Editor.constructor

Properties

autoIndentOn

autoIndentOn: boolean

Defined in: ui/dist/editor/editor.d.ts:76

Inherited from

Editor.autoIndentOn


bounds

bounds: Rect

Defined in: ui/dist/view/view.d.ts:61

Parent-relative integer rect; written by the layout pass — read it in draw/hit-testing.

Inherited from

Editor.bounds


canRedo

readonly canRedo: Signal<boolean>

Defined in: ui/dist/editor/editor.d.ts:61

Inherited from

Editor.canRedo


canUndo

readonly canUndo: Signal<boolean>

Defined in: ui/dist/editor/editor.d.ts:60

Whether an undo / redo step is available.

Inherited from

Editor.canUndo


castsShadow

castsShadow: boolean

Defined in: ui/dist/view/view.d.ts:73

When true, the renderer paints a drop shadow on the cells just below and to the right of this view, in paint order (a later sibling's shadow falls over an earlier one). Default false. The Desktop sets it per window.

Inherited from

Editor.castsShadow


centered

centered: boolean

Defined in: ui/dist/view/view.d.ts:80

When true, the layout pass recentres this view within its parent after layout — origin = (parent - self) / 2 on both axes. Intended for absolutely-placed views (a modal dialog, a message box) whose size is fixed and whose origin would otherwise be placed by the caller. Default false; Dialog sets it when centered.

Inherited from

Editor.centered


curPos

readonly curPos: Signal<{ col: number; line: number; }>

Defined in: ui/dist/editor/editor.d.ts:49

The caret as 1-based {line, col} (col is the visual column).

Inherited from

Editor.curPos


curPtr

curPtr: number

Defined in: ui/dist/editor/editor.d.ts:70

Inherited from

Editor.curPtr


curY

curY: number

Defined in: ui/dist/editor/editor.d.ts:79

Inherited from

Editor.curY


delta

readonly delta: object

Defined in: ui/dist/editor/editor.d.ts:63

The scroll offset, as a pair of signals — also the value channel for scroll bars: a bar bound to delta.x/delta.y scrolls the editor on any write (clamped to the content).

x

readonly x: Signal<number>

y

readonly y: Signal<number>

Inherited from

Editor.delta


doReplace

doReplace: boolean

Defined in: ui/dist/editor/editor.d.ts:149

Inherited from

Editor.doReplace


drawLine

drawLine: number

Defined in: ui/dist/editor/editor.d.ts:80

Inherited from

Editor.drawLine


drawPtrP

drawPtrP: number

Defined in: ui/dist/editor/editor.d.ts:81

Inherited from

Editor.drawPtrP


eolKind

eolKind: LineEnding

Defined in: ui/dist/editor/editor.d.ts:69

Inherited from

Editor.eolKind


fileName

readonly fileName: Signal<string | undefined>

Defined in: files/src/editor/file-editor.ts:48

The bound path, as a reactive signal so a window title can track it (a "save as" retitles).


focusable

focusable: boolean

Defined in: ui/dist/editor/editor.d.ts:43

Whether this view can receive keyboard focus. Effective focusability also requires the view to be visible and enabled with no hidden/disabled ancestor. Default false; the focus manager drives the state.focused flag.

Inherited from

Editor.focusable


hasSelection

readonly hasSelection: Signal<boolean>

Defined in: ui/dist/editor/editor.d.ts:54

Whether any text is currently selected.

Inherited from

Editor.hasSelection


indicator

indicator: IndicatorTarget | null

Defined in: ui/dist/editor/editor.d.ts:103

Inherited from

Editor.indicator


insertMode

readonly insertMode: Signal<boolean>

Defined in: ui/dist/editor/editor.d.ts:56

true = insert mode, false = overwrite mode; the Insert key toggles it.

Inherited from

Editor.insertMode


keyBindings

readonly keyBindings: EditorKeyBindings

Defined in: ui/dist/editor/editor.d.ts:85

Inherited from

Editor.keyBindings


layout

layout: LayoutProps

Defined in: ui/dist/view/view.d.ts:65

Layout props for this view (direction, size, padding, absolute placement, …).

Inherited from

Editor.layout


limitY

limitY: number

Defined in: ui/dist/editor/editor.d.ts:82

Inherited from

Editor.limitY


lineCount

readonly lineCount: Signal<number>

Defined in: ui/dist/editor/editor.d.ts:58

The number of lines in the buffer.

Inherited from

Editor.lineCount


modified

readonly modified: Signal<boolean>

Defined in: ui/dist/editor/editor.d.ts:47

Whether the buffer has unsaved changes since it was last loaded or saved.

Inherited from

Editor.modified


normalRole

protected normalRole: keyof Theme

Defined in: ui/dist/editor/editor.d.ts:105

The normal/selected theme roles; Memo overrides them to the gray-dialog palette.

Inherited from

Editor.normalRole


options

readonly options: EditorOptions

Defined in: ui/dist/editor/editor.d.ts:90

Inherited from

Editor.options


overwrite

overwrite: boolean

Defined in: ui/dist/editor/editor.d.ts:75

Inherited from

Editor.overwrite


postProcess

postProcess: boolean

Defined in: ui/dist/view/view.d.ts:90

Take part in the post-process sweep (after the focused view sees the event).

Inherited from

Editor.postProcess


preProcess

preProcess: boolean

Defined in: ui/dist/editor/editor.d.ts:45

Sees keys before app chrome so the focused editor can claim the WordStar Ctrl-Q/Ctrl-K prefixes.

Inherited from

Editor.preProcess


promptOnReplace

promptOnReplace: boolean

Defined in: ui/dist/editor/editor.d.ts:147

Inherited from

Editor.promptOnReplace


replaceAllFlag

replaceAllFlag: boolean

Defined in: ui/dist/editor/editor.d.ts:148

Inherited from

Editor.replaceAllFlag


replaceStr

replaceStr: string

Defined in: ui/dist/editor/editor.d.ts:145

Inherited from

Editor.replaceStr


searchOpts

searchOpts: SearchOptions

Defined in: ui/dist/editor/editor.d.ts:146

Inherited from

Editor.searchOpts


selectedRole

protected selectedRole: keyof Theme

Defined in: ui/dist/editor/editor.d.ts:106

Inherited from

Editor.selectedRole


selecting

selecting: boolean

Defined in: ui/dist/editor/editor.d.ts:74

Inherited from

Editor.selecting


selEndP

selEndP: number

Defined in: ui/dist/editor/editor.d.ts:73

Inherited from

Editor.selEndP


state

readonly state: ViewState

Defined in: ui/dist/view/view.d.ts:63

Draw-against flags. The object reference is fixed; individual fields mutate (e.g. focused).

Inherited from

Editor.state


undoStack

readonly undoStack: UndoStack

Defined in: ui/dist/editor/editor.d.ts:93

Inherited from

Editor.undoStack


vBar

vBar: GadgetBar | null

Defined in: ui/dist/editor/editor.d.ts:102

Inherited from

Editor.vBar

Methods

accelerators()

accelerators(): readonly string[]

Defined in: ui/dist/view/view.d.ts:104

The Alt+hotkey accelerator characters (lowercase) this view claims in its focus scope, for duplicate-accelerator detection. The base returns none; accelerator-bearing widgets (Button/Label/CheckGroup/RadioGroup) override it to report their ~X~ hotkey(s).

Returns

readonly string[]

The claimed accelerator chars, or an empty list when the view claims none.

Inherited from

Editor.accelerators


attachGadgets()

attachGadgets(h?, v?, ind?): void

Defined in: ui/dist/editor/editor.d.ts:140

Wire up the scroll bars and line/column indicator that display and drive this editor.

Parameters

h?

GadgetBar

v?

GadgetBar

ind?

IndicatorTarget

Returns

void

Inherited from

Editor.attachGadgets


bind()

bind<T>(reader, apply?, opts?): void

Defined in: ui/dist/view/view.d.ts:192

Bind a reactive value to a redraw. Creates an effect (owned by this view's scope) that reads reader() — subscribing to whatever signals it touches — runs the optional apply(value), then requests a frame: a repaint by default, or a reflow when { relayout: true }. It re-runs automatically whenever those signals change, and is disposed when the view unmounts.

Call it from onMount, not the constructor — the view's scope only exists once mounted, so a pre-mount bind throws rather than silently dropping the binding.

Type Parameters

T

T

Parameters

reader

() => T

Reads the reactive source; the signals it reads become dependencies.

apply?

(v) => void

Optional: apply the read value to the widget (e.g. store it in a field).

opts?

Pass { relayout: true } when the change affects layout, so it reflows instead of just repainting.

relayout?

boolean

Returns

void

Example

ts
import { signal } from '@jsvision/ui';

const count = signal(0);
// `status` is a View whose draw() reads count():
status.onMount(() => {
  status.bind(() => count()); // repaint the status line whenever `count` changes
});

Inherited from

Editor.bind


copy()

copy(): void

Defined in: ui/dist/editor/editor.d.ts:159

Copy the selection to the shared clipboard editor (and the OS clipboard when supported).

Returns

void

Inherited from

Editor.copy


cut()

cut(): void

Defined in: ui/dist/editor/editor.d.ts:161

Cut the selection to the shared clipboard editor, as one undo step.

Returns

void

Inherited from

Editor.cut


deleteSelect()

deleteSelect(): void

Defined in: ui/dist/editor/editor.d.ts:186

Returns

void

Inherited from

Editor.deleteSelect


derived()

protected derived<T>(fn): () => T

Defined in: ui/dist/view/view.d.ts:214

Create a stable derived accessor owned by this view's scope. The returned () => T keeps the same identity for the life of the view, so it is safe to build in the constructor and hand to child views before this view mounts. The backing computed is created lazily under the view's own scope, so it is always owned and disposed at unmount — unlike a bare computed() in the constructor, which would run before any scope exists, leak, and warn.

Reads behave sensibly across the lifecycle:

  • Before mount: evaluates fn() directly (correct current value, nothing persisted). Good for a pre-mount natural-size measure.
  • After mount: builds and memoizes a computed(fn) under the view's scope.
  • After an unmount→remount: the memo is keyed to the scope it was built under, so a remounted view (which gets a fresh scope) re-derives under the new scope instead of returning the previous mount's disposed, now-frozen computed — keeping a Show/For-remounted widget reactive.

Type Parameters

T

T

Parameters

fn

() => T

The derivation (pure; the signals it reads become the computed's dependencies).

Returns

A stable accessor; call it to read the derived value.

() => T

Inherited from

Editor.derived


desiredCaret()

desiredCaret(): Point | null

Defined in: ui/dist/editor/editor.d.ts:142

The hardware-caret cell (view-local) while focused and in view, else null.

Returns

Point | null

Inherited from

Editor.desiredCaret


doSearchReplace()

doSearchReplace(): Promise<number>

Defined in: ui/dist/editor/editor.d.ts:157

Returns

Promise<number>

Inherited from

Editor.doSearchReplace


draw()

draw(ctx): void

Defined in: ui/dist/editor/editor.d.ts:203

Paint the visible rows.

Parameters

ctx

DrawContext

Returns

void

Inherited from

Editor.draw


execute()

execute(action): void

Defined in: ui/dist/editor/editor.d.ts:138

Run one editor action programmatically — the same operations the keymap triggers.

Parameters

action

EditorAction

The action to run (e.g. 'lineDown', 'undo', 'textEnd', 'selectAll').

Returns

void

Example

ts
editor.setText('hello world');
editor.execute('textEnd'); // caret to end of buffer

Inherited from

Editor.execute


find()

find(): Promise<void>

Defined in: ui/dist/editor/editor.d.ts:151

Open the Find dialog and search for the first match. Resolves when the interaction is done.

Returns

Promise<void>

Inherited from

Editor.find


focusSignal()

focusSignal(): Signal<void>

Defined in: ui/dist/view/view.d.ts:122

Subscribe to this view's focus changes. Reading the returned signal inside a bind/effect re-runs that effect whenever this view gains or loses focus — including from another view (e.g. a Label repainting when the control it labels is focused). The signal notifies on every poke even without a value change. Lazy: the backing signal is created on first call.

Returns

Signal<void>

A signal that ticks whenever this view gains or loses focus.

Example

ts
// Inside a widget's onMount, repaint whenever `other` view's focus changes:
this.onMount(() => this.bind(() => other.focusSignal()()));

Inherited from

Editor.focusSignal


getMousePtr()

getMousePtr(local): number

Defined in: ui/dist/editor/editor.d.ts:197

Parameters

local

Point

Returns

number

Inherited from

Editor.getMousePtr


getText()

getText(range?): string

Defined in: ui/dist/editor/editor.d.ts:119

The full buffer content, or the text in a [from, to) range — returned verbatim.

Parameters

range?

Optional half-open buffer-offset range; omit for the whole buffer.

from

number

to

number

Returns

string

The requested text.

Inherited from

Editor.getText


insertText()

insertText(text): void

Defined in: ui/dist/editor/editor.d.ts:128

Insert text at the caret, replacing any selection; line endings are normalized to the buffer's kind, as if typed.

Parameters

text

string

The text to insert.

Returns

void

Inherited from

Editor.insertText


invalidate()

invalidate(): void

Defined in: ui/dist/view/view.d.ts:167

Request a repaint of this view. A no-op before the view is mounted (the first frame paints everything).

Returns

void

Inherited from

Editor.invalidate


invalidateLayout()

invalidateLayout(): void

Defined in: ui/dist/view/view.d.ts:169

Request a reflow (re-run layout, then repaint). Use this when a change affects size/position, not just pixels.

Returns

void

Inherited from

Editor.invalidateLayout


loadFile()

loadFile(): void

Defined in: files/src/editor/file-editor.ts:63

Load the bound file into the buffer. A missing file yields an empty, valid buffer; no error.

Returns

void


measure()?

optional measure(available): Size2D

Defined in: ui/dist/view/view.d.ts:67

Optional intrinsic-size hook for auto sizing — return the size this view wants for available.

Parameters

available

Size2D

Returns

Size2D

Inherited from

Editor.measure


onCleanup()

onCleanup(fn): void

Defined in: ui/dist/view/view.d.ts:230

Register a teardown callback that runs once when this view unmounts. Requires a mounted view — so call it from within onMount. Use it to release anything the view acquired (a timer, an external subscription).

Parameters

fn

() => void

The teardown callback.

Returns

void

Inherited from

Editor.onCleanup


onEvent()

onEvent(ev): void

Defined in: ui/dist/editor/editor.d.ts:205

Handle a dispatched event (keys, mouse/wheel, paste, and editing commands).

Parameters

ev

DispatchEvent

Returns

void

Inherited from

Editor.onEvent


onMount()

onMount(fn): void

Defined in: ui/dist/view/view.d.ts:222

Register a callback to run once when the view becomes live (after its first layout gives it bounds). This is where to call bind, since the view's reactive scope exists by then. Registering after the view is already live runs the callback immediately.

Parameters

fn

() => void

Post-mount setup.

Returns

void

Inherited from

Editor.onMount


paste()

paste(): void

Defined in: ui/dist/editor/editor.d.ts:163

Paste the shared clipboard editor's selection at the caret, as one undo step.

Returns

void

Inherited from

Editor.paste


redo()

redo(): void

Defined in: ui/dist/editor/editor.d.ts:167

Redo the most recently undone edit.

Returns

void

Inherited from

Editor.redo


replace()

replace(): Promise<number>

Defined in: ui/dist/editor/editor.d.ts:153

Open the Replace dialog and run the replace loop; resolves with the number of replacements made.

Returns

Promise<number>

Inherited from

Editor.replace


save()

save(): Promise<boolean>

Defined in: files/src/editor/file-editor.ts:80

Save the buffer; an untitled buffer routes through saveAs. Resolves false on cancel/error.

Returns

Promise<boolean>


saveAs()

saveAs(): Promise<boolean>

Defined in: files/src/editor/file-editor.ts:86

Prompt for a path; a chosen path rebinds fileName (retitling the window) and writes.

Returns

Promise<boolean>


saveFile()

saveFile(): boolean

Defined in: files/src/editor/file-editor.ts:94

Back up the previous content (if enabled) then write the buffer. Reports an error and returns false.

Returns

boolean


scrollTo()

scrollTo(x, y): void

Defined in: ui/dist/editor/editor.d.ts:194

Parameters

x

number

y

number

Returns

void

Inherited from

Editor.scrollTo


searchAgain()

searchAgain(): Promise<number>

Defined in: ui/dist/editor/editor.d.ts:155

Repeat the last search/replace with the stored parameters; resolves with the replacement count.

Returns

Promise<number>

Inherited from

Editor.searchAgain


searchOnce()

searchOnce(): boolean

Defined in: ui/dist/editor/editor.d.ts:156

Returns

boolean

Inherited from

Editor.searchOnce


selectByClick()?

optional selectByClick(): void

Defined in: ui/dist/view/view.d.ts:156

Optional "select + raise on click" hook. Left undefined on the base, so a plain view is not a select/raise target. A container that owns z-order (a Window) overrides it to select and raise itself. The hit-test invokes the first ancestor that defines this — before delivering the mouse-down — so a click always raises the window even if the interior also consumes the click.

Returns

void

Inherited from

Editor.selectByClick


selectionText()

selectionText(): string

Defined in: ui/dist/editor/editor.d.ts:130

The currently selected text, or '' when there is no selection.

Returns

string

Inherited from

Editor.selectionText


setText()

setText(text): void

Defined in: ui/dist/editor/editor.d.ts:113

Replace the entire content (verbatim, mixed line endings preserved); the line-ending kind is re-detected and cursor/selection/scroll/undo history are reset.

Parameters

text

string

The new buffer content.

Returns

void

Inherited from

Editor.setText


toggleInsMode()

toggleInsMode(): void

Defined in: ui/dist/editor/editor.d.ts:193

Returns

void

Inherited from

Editor.toggleInsMode


undo()

undo(): void

Defined in: ui/dist/editor/editor.d.ts:165

Undo the most recent edit.

Returns

void

Inherited from

Editor.undo


valid()

valid(_command): Promise<boolean>

Defined in: files/src/editor/file-editor.ts:125

The prompt shown when closing a modified buffer: Yes saves (returning its result), No discards and closes, Cancel keeps the buffer open. An unmodified buffer closes immediately.

Parameters

_command

"close" | "quit"

Returns

Promise<boolean>


viewH()

viewH(): number

Defined in: ui/dist/editor/editor.d.ts:170

Returns

number

Inherited from

Editor.viewH