Documentation
¶
Overview ¶
Package editor is the desktop app's note editor on MyGo's code editor (plan 0009, Phase 2): source mode with Obsidian's syntax highlighted, folding by headings and lists, the app's own undo, Obsidian's keys, formatting commands, completions of links and tags, and links that follow. It joins a notes.Document to the MyGo buffer its tabs edit.
Index ¶
- Constants
- func AttachmentFolder(setting, notePath string) string
- func Body(text string) string
- func CleanName(name string) string
- func EmbedFor(p string, wikilinks, nameIsUnique bool) string
- func FreePath(folder, name string, taken func(string) bool) string
- func FrontmatterLastLine(text string) int
- func FrontmatterStart(text string) int
- func Language() *code.Language
- func Notice(c *ui.Context, d *notes.Document, a NoticeActions)
- func PastedName(at time.Time, ext string) string
- func PropertyType(key string, value any, vaultType string) string
- func RenameProperty(text, from, to string) (string, error)
- func SetProperties(text string, props map[string]any) (string, error)
- func SubpathLine(text, subpath string) int
- func TagAt(text string, pos int) (string, bool)
- type Binding
- type Clipboard
- type Edit
- func ContinueMarkup(text string, sels []Sel) (Edit, bool)
- func DeleteMarkupBackward(text string, sels []Sel) (Edit, bool)
- func DeleteParagraph(text string, sels []Sel) Edit
- func InsertLink(text string, sels []Sel) Edit
- func InsertPair(text string, sels []Sel, before, after string) Edit
- func SetHeading(text string, sels []Sel, level int) Edit
- func ToggleBlockquote(text string, sels []Sel) Edit
- func ToggleBulletList(text string, sels []Sel) Edit
- func ToggleChecklist(text string, sels []Sel) Edit
- func ToggleComment(text string, sels []Sel) Edit
- func ToggleMark(text string, sels []Sel, mark string) Edit
- func ToggleNumberedList(text string, sels []Sel) Edit
- func WrapInMark(text string, sels []Sel, typed string) (Edit, bool)
- type File
- type Frontmatter
- type Link
- type NoteEditor
- func (e *NoteEditor) Attach(files []File)
- func (e *NoteEditor) AttachPaths(paths []string)
- func (e *NoteEditor) Binding() *Binding
- func (e *NoteEditor) Redo() bool
- func (e *NoteEditor) RefreshLive()
- func (e *NoteEditor) Run(cmd func(text string, sels []Sel) Edit) bool
- func (e *NoteEditor) Undo() bool
- func (e *NoteEditor) View(c *ui.Context) ui.Element
- type NoteView
- type NoticeActions
- type Prefs
- type PropertiesPanel
- type Property
- type Sel
- type Sources
- type Target
- type Uploader
- type Where
Constants ¶
const ( TypeText = "text" TypeMultitext = "multitext" TypeNumber = "number" TypeCheckbox = "checkbox" TypeDate = "date" TypeDatetime = "datetime" TypeAliases = "aliases" TypeTags = "tags" )
The types of a property, as Obsidian names them.
const MaxAttach = 10 << 20
MaxAttach is the most bytes notesd takes in one note.upload.
const ReadableWidth = 700
ReadableWidth is a note's width under Readable line length.
Variables ¶
This section is empty.
Functions ¶
func AttachmentFolder ¶
AttachmentFolder is where a note's attachments go, by the setting as Obsidian writes it: "/" the vault root, "./" the note's folder, "./NAME" a folder NAME beside the note, else a folder's path. "" is the root.
func EmbedFor ¶
EmbedFor is the embed a note gets for an attachment: ![[name]] with wikilinks, the path when another file has its name; else a Markdown image with the path, encoded.
func FreePath ¶
FreePath is folder/name, or name with " 1", " 2"… before its extension, the first no file has.
func FrontmatterLastLine ¶
FrontmatterLastLine is the line of the frontmatter's closing "---", from 0; it is 0 without frontmatter.
func FrontmatterStart ¶
FrontmatterStart is where a note's frontmatter starts or would start: after a byte order mark.
func Language ¶
Language is Obsidian's Markdown for MyGo's editor: one value, as editors compare languages by pointer.
func Notice ¶
func Notice(c *ui.Context, d *notes.Document, a NoticeActions)
Notice draws what a note's tabs say about it (docs/specs/ui.md#notices-in-a-tab) as frostui's banner, and runs what the user chooses: a conflict (Compare, Dismiss), a refused base (Compare), a deleted note (Restore, and close for the tab), a failed save (Retry now), and a note that cannot be edited here. It draws nothing when the note has nothing to say.
func PastedName ¶
PastedName is Obsidian's name for a pasted image.
func PropertyType ¶
PropertyType is a property's type: the vault's type for its key, else what the key or value says.
func RenameProperty ¶
RenameProperty returns text with key from renamed to, its value kept, in its place.
func SetProperties ¶
SetProperties returns text with each key of props set to its value, a key whose value is nil removed.
func SubpathLine ¶
SubpathLine is the line, from 1, a link's "#Heading", "#A#B" or "#^block" leads to in text, 0 when the note has none.
Types ¶
type Binding ¶
type Binding struct {
// contains filtered or unexported fields
}
Binding joins a note's document to the MyGo buffer every tab of the note edits: MyGo's buffers are shared by editors, as the web app's documents are shared by views. It implements notes.Buffer. UI thread only.
func (*Binding) Apply ¶
Apply shows another writer's change or a merge, outside the buffer's undo history: undo moves its steps past it (ADR-0022).
func (*Binding) Close ¶
func (b *Binding) Close()
Close detaches the buffer from the document, which saves at once.
type Clipboard ¶
type Clipboard interface {
// Files are the local paths on the clipboard.
Files() []string
// PNG is an image on the clipboard, nil for none.
PNG() []byte
}
Clipboard is what the editor asks of the system's clipboard when text is pasted; the window gives it MyGo's.
type Edit ¶
Edit is what a formatting command does: the changes, and where the selections are after them.
func ContinueMarkup ¶
ContinueMarkup is Enter with smart lists: a list item, task or quote continues on the new line; an empty one ends its list. ok is false when a caret is not in one, and Enter does what it always does.
func DeleteMarkupBackward ¶
DeleteMarkupBackward is Backspace with smart lists: at the end of a list item's marker or a quote's '>', it removes the marker. ok is false otherwise.
func DeleteParagraph ¶
DeleteParagraph deletes each line the selections touch.
func InsertLink ¶
InsertLink writes a Markdown link around each selection: its text, or its URL when it is one.
func InsertPair ¶
InsertPair writes before and after around each selection, the caret after the selection: [[ ]], ![[ ]], #.
func SetHeading ¶
SetHeading makes each touched line a heading of level 1 to 6, or plain text with 0.
func ToggleBlockquote ¶
ToggleBlockquote quotes each touched line with "> ", or unquotes them when all are quoted.
func ToggleBulletList ¶
ToggleBulletList makes each touched line a "- " item, or plain when all are bullets.
func ToggleChecklist ¶
ToggleChecklist checks or unchecks each touched line's task, makes a list item a task, and any other line a task item.
func ToggleComment ¶
ToggleComment toggles %% around each selection, or around a caret's line.
func ToggleMark ¶
ToggleMark toggles mark (**, *, ~~, ==, `) around each selection, or around the word at a caret.
func ToggleNumberedList ¶
ToggleNumberedList numbers the touched lines from 1, or makes them plain when all are numbered.
type Frontmatter ¶
type Frontmatter struct {
Exists bool
Properties []Property
Error string // why it is not a mapping, "" when it is
}
Frontmatter is what a note's frontmatter holds.
func ReadFrontmatter ¶
func ReadFrontmatter(text string) Frontmatter
ReadFrontmatter reads a note's properties in order.
type Link ¶
type Link struct {
Target string // as written, without subpath or alias; "" for the note itself
Subpath string // with its leading '#'
URL string // a web link's address
Embed bool
From int // where the link is in the text
To int
}
Link is a link in a note: to a vault file (Target, and Subpath, a heading or block after '#'), or to the web (URL).
type NoteEditor ¶
type NoteEditor struct {
State *code.State
Prefs Prefs
Sources Sources
// Follow opens a link: Alt + Enter, Ctrl + click and their variants.
Follow func(l Link, where Where)
// FollowTag searches for a tag, the same way.
FollowTag func(tag string)
// Preview builds a link's page preview in a hover; nil for none.
Preview func(c *ui.Context, l Link)
// Uploads and Clipboard let files be pasted and dropped; nil for
// none. OnError shows what went wrong, Now is the clock.
Uploads Uploader
Clipboard Clipboard
OnError func(error)
Now func() time.Time
// HideFront hides the frontmatter in live preview, while the properties
// panel stands in for it.
HideFront bool
// Hold keeps the note open until the release it returns runs, for an
// upload that may outlast this editor; nil for none.
Hold func() (release func())
// Rendered draws live preview's callouts, tables, embeds and images;
// nil leaves them as source.
Rendered *reading.Blocks
// contains filtered or unexported fields
}
NoteEditor is one tab's editor of a note: MyGo's code editor on the note's shared buffer, with Obsidian's keys (docs/specs/ui.md#keyboard-map).
func NewNoteEditor ¶
func NewNoteEditor(b *Binding) *NoteEditor
NewNoteEditor makes a tab's editor of a bound note.
func (*NoteEditor) Attach ¶
func (e *NoteEditor) Attach(files []File)
Attach uploads files beside the note and inserts their embeds at the caret.
func (*NoteEditor) AttachPaths ¶
func (e *NoteEditor) AttachPaths(paths []string)
AttachPaths attaches local files, which the upload reads off the UI thread.
func (*NoteEditor) RefreshLive ¶
func (e *NoteEditor) RefreshLive()
RefreshLive works out what live preview shows again, as what an embed names may have come or gone.
func (*NoteEditor) Run ¶
func (e *NoteEditor) Run(cmd func(text string, sels []Sel) Edit) bool
Run applies a command's edit as the user's: one step of undo, saved as typing is.
func (*NoteEditor) Undo ¶
func (e *NoteEditor) Undo() bool
Undo takes back the user's newest step, never another writer's change, and puts the selections where they were.
type NoteView ¶
type NoteView struct {
Editor *NoteEditor
Properties *PropertiesPanel
// ShowTitle and ShowProperties are the Show inline title and
// Properties in document preferences.
ShowTitle, ShowProperties bool
// HideProperties hides the panel and frontmatter in live preview.
HideProperties bool
// Readable limits the note's width (Readable line length).
Readable bool
// Rename moves the note: its new name, without ".md".
Rename func(title string)
// contains filtered or unexported fields
}
NoteView is a tab's note in edit mode: its inline title, its properties and its editor (docs/specs/ui.md#editor-and-reading-view).
func NewNoteView ¶
func NewNoteView(e *NoteEditor) *NoteView
NewNoteView makes the view of an editor.
type NoticeActions ¶
type NoticeActions struct {
// CompareVersion opens the merge view of the note against one of its
// versions: the text a conflict kept.
CompareVersion func(version int64)
// CompareText opens the merge view of the note against text: what the
// editor held when notesd refused its base.
CompareText func(text string)
// Close closes the tab of a deleted note.
Close func()
}
NoticeActions are what a tab's notice leads to, which the window wires.
type Prefs ¶
type Prefs struct {
SmartLists bool
AutoPairMarkdown bool
AutoPairBrackets bool
LineNumbers bool
FoldHeadings bool
FoldIndent bool
IndentWithTabs bool
IndentGuides bool
TabSize int
FontSize int // 0 is the editor's own
Live bool // live preview, else source mode
}
Prefs are the editor's preferences (docs/specs/ui.md#settings-batch-2).
func DefaultPrefs ¶
func DefaultPrefs() Prefs
DefaultPrefs are the web app's defaults (app/src/data/prefs.ts).
type PropertiesPanel ¶
type PropertiesPanel struct {
// Types are the vault's property types (note.properties).
Types func() map[string]string
// Suggestions are what a tags field offers.
Suggestions func() []string
Folded bool
// contains filtered or unexported fields
}
PropertiesPanel draws and edits a note's frontmatter (docs/specs/ui.md#editor-and-reading-view): typed values, editable keys, remove and add, each edit rewriting only that key's lines.
func NewPropertiesPanel ¶
func NewPropertiesPanel(doc *notes.Document) *PropertiesPanel
NewPropertiesPanel makes the panel of doc.
func (*PropertiesPanel) Commit ¶
func (p *PropertiesPanel) Commit()
Commit writes what a field holds while it still has the focus, as the window closes: a text field otherwise commits on Enter or losing focus.
type Property ¶
Property is a key of the frontmatter and its value: a string, int64, float64, bool, nil, []any or map[string]any.
type Sel ¶
type Sel struct{ Anchor, Head int }
Sel is a selection: the anchor stays, the head is the caret. Offsets count bytes, as MyGo's editor does.
type Sources ¶
type Sources interface {
// LinkTargets lists the notes [[ completes to for query, best first.
LinkTargets(query string, limit int) []Target
// Tags lists the vault's tags, by how many notes have them.
Tags() []string
// Subpaths lists the headings, or the block IDs, of the note target
// leads to ("" is the note being edited), through done on the UI
// thread; done is not called when it leads to no note.
Subpaths(target string, blocks bool, done func([]Target))
// Resolve is the file a link names, "" for none.
Resolve(target string) string
}
Sources is what the editor completes from: the vault's notes and tags, which the session keeps.
type Target ¶
type Target struct {
Insert string // the link text, as the vault's link format writes it
Label string // what the list shows
Detail string // its folder, dimmed
}
Target is a note [[ completes to.