notesy::editor

The note in front: what it says, where the caret is, and typing into it. Takes the editor permission. Everything here works on the note the user has in front, and nothing else; changes are steps the user can undo, like their own typing.

rustuse notesy::{commands, editor};

pub fn ready() {
    commands::add("stamp", "Stamp the note's path", |command| {
        editor::insert(`— ${editor::path().unwrap_or("?")}`);
    });
}
Function What it does
editor::note() The note in front, a Note (unsaved edits and all), Some(note), or None when there's none.
editor::path() The note in front's path, Some(path), or None when there's none.
editor::text() Its text, unsaved edits and all, or None.
editor::selection() Where the caret is: #{ start, end, text }, start and end in characters from the top (the same when nothing's selected), or None.
editor::insert(text) Types text at the caret, over what's selected.
editor::insert_snippet(text) The same, and the caret goes to its first $0: "**$0**" leaves it between the stars.
editor::replace(start, end, text) Puts text in place of the characters from start to end.
editor::set_selection(start, end) Puts the selection from start to end (the caret, when they're the same), brought into sight.

With no note in front, insert, replace and set_selection are errors. Positions count characters, not bytes: "é" is one.

#Taking the keys

With keys.take (and keys and keys.which, to hear which), a plugin can take what's typed in the editor before the note gets it: a vim mode's keys.

Function What it does
editor::take_keys(on) While on, a key struck or text typed in the editor goes to the plugin, as key.down (with which), and not into the note. false gives them back.

Shortcuts (with Ctrl, or Cmd on a Mac) still reach notesy, and so do pastes and what an input method writes, so the user can always reach the palette and settings. The keys are given back when the plugin stops. A key taken reaches the script a moment after it's struck; one typed while the plugin was giving them back (going into a vim's insert mode, say) arrives as a key.down too, for it to type itself. Each key.down says which it was: taken is true for a key that went to the plugin and not into the note, and false for one the note got (or a shortcut). A vim mode types the taken ones it hears after saying take_keys(false), and leaves the others, which are in the note already. examples/plugins/example.vim is a whole vim mode built on it.

Every page