editor

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const MaxAttach = 10 << 20

MaxAttach is the most bytes notesd takes in one note.upload.

View Source
const ReadableWidth = 700

ReadableWidth is a note's width under Readable line length.

Variables

This section is empty.

Functions

func AttachmentFolder

func AttachmentFolder(setting, notePath string) string

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 Body

func Body(text string) string

Body is a note's text after its frontmatter.

func CleanName

func CleanName(name string) string

CleanName is the name a file is uploaded under.

func EmbedFor

func EmbedFor(p string, wikilinks, nameIsUnique bool) string

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

func FreePath(folder, name string, taken func(string) bool) string

FreePath is folder/name, or name with " 1", " 2"… before its extension, the first no file has.

func FrontmatterLastLine

func FrontmatterLastLine(text string) int

FrontmatterLastLine is the line of the frontmatter's closing "---", from 0; it is 0 without frontmatter.

func FrontmatterStart

func FrontmatterStart(text string) int

FrontmatterStart is where a note's frontmatter starts or would start: after a byte order mark.

func Language

func Language() *code.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

func PastedName(at time.Time, ext string) string

PastedName is Obsidian's name for a pasted image.

func PropertyType

func PropertyType(key string, value any, vaultType string) string

PropertyType is a property's type: the vault's type for its key, else what the key or value says.

func RenameProperty

func RenameProperty(text, from, to string) (string, error)

RenameProperty returns text with key from renamed to, its value kept, in its place.

func SetProperties

func SetProperties(text string, props map[string]any) (string, error)

SetProperties returns text with each key of props set to its value, a key whose value is nil removed.

func SubpathLine

func SubpathLine(text, subpath string) int

SubpathLine is the line, from 1, a link's "#Heading", "#A#B" or "#^block" leads to in text, 0 when the note has none.

func TagAt

func TagAt(text string, pos int) (string, bool)

TagAt finds the #tag at pos, without its '#'.

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 Bind

func Bind(doc *notes.Document) *Binding

Bind makes the buffer of doc and attaches it.

func (*Binding) Apply

func (b *Binding) Apply(cs notes.ChangeSet)

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) Buffer

func (b *Binding) Buffer() *code.Buffer

Buffer is the bound buffer, which every tab's editor of the note shows.

func (*Binding) Close

func (b *Binding) Close()

Close detaches the buffer from the document, which saves at once.

func (*Binding) Document

func (b *Binding) Document() *notes.Document

Document is the bound document.

func (*Binding) Edit

func (b *Binding) Edit(cs notes.ChangeSet)

Edit shows a user's change made outside the editor, as one step of undo.

func (*Binding) Redo

func (b *Binding) Redo() bool

Redo makes the newest undone step again.

func (*Binding) Sync

func (b *Binding) Sync()

Sync reports the user's edits since the last report to the document.

func (*Binding) Undo

func (b *Binding) Undo() bool

Undo takes back the user's newest step, never another writer's change, for a view without an editor of its own to run it.

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

type Edit struct {
	Changes notes.ChangeSet
	Sels    []Sel
}

Edit is what a formatting command does: the changes, and where the selections are after them.

func ContinueMarkup

func ContinueMarkup(text string, sels []Sel) (Edit, bool)

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

func DeleteMarkupBackward(text string, sels []Sel) (Edit, bool)

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

func DeleteParagraph(text string, sels []Sel) Edit

DeleteParagraph deletes each line the selections touch.

func InsertLink(text string, sels []Sel) Edit

InsertLink writes a Markdown link around each selection: its text, or its URL when it is one.

func InsertPair

func InsertPair(text string, sels []Sel, before, after string) Edit

InsertPair writes before and after around each selection, the caret after the selection: [[ ]], ![[ ]], #.

func SetHeading

func SetHeading(text string, sels []Sel, level int) Edit

SetHeading makes each touched line a heading of level 1 to 6, or plain text with 0.

func ToggleBlockquote

func ToggleBlockquote(text string, sels []Sel) Edit

ToggleBlockquote quotes each touched line with "> ", or unquotes them when all are quoted.

func ToggleBulletList

func ToggleBulletList(text string, sels []Sel) Edit

ToggleBulletList makes each touched line a "- " item, or plain when all are bullets.

func ToggleChecklist

func ToggleChecklist(text string, sels []Sel) Edit

ToggleChecklist checks or unchecks each touched line's task, makes a list item a task, and any other line a task item.

func ToggleComment

func ToggleComment(text string, sels []Sel) Edit

ToggleComment toggles %% around each selection, or around a caret's line.

func ToggleMark

func ToggleMark(text string, sels []Sel, mark string) Edit

ToggleMark toggles mark (**, *, ~~, ==, `) around each selection, or around the word at a caret.

func ToggleNumberedList

func ToggleNumberedList(text string, sels []Sel) Edit

ToggleNumberedList numbers the touched lines from 1, or makes them plain when all are numbered.

func WrapInMark

func WrapInMark(text string, sels []Sel, typed string) (Edit, bool)

WrapInMark wraps each selection in a Markdown mark typed over it (*, _, ~, =, `), as Auto-pair Markdown syntax does; ok is false for a caret or another character.

type File

type File struct {
	Name string
	Data []byte
	Path string
}

File is a file to attach: its name, and its bytes or the local path to read them from.

func (File) Read

func (f File) Read() ([]byte, error)

Read is the file's bytes, at most MaxAttach of them. It may read the disk, so an upload calls it off the UI thread.

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 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).

func LinkAt

func LinkAt(text string, pos int) (Link, bool)

LinkAt finds the link at pos in text, on pos's line.

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) Binding

func (e *NoteEditor) Binding() *Binding

Binding is the note's binding.

func (*NoteEditor) Redo

func (e *NoteEditor) Redo() bool

Redo makes the newest undone step again.

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.

func (*NoteEditor) View

func (e *NoteEditor) View(c *ui.Context) ui.Element

View draws the editor.

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.

func (*NoteView) View

func (v *NoteView) View(c *ui.Context) ui.Element

View draws the note.

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) Add

func (p *PropertiesPanel) Add()

Add opens a new row (Ctrl + ;).

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.

func (*PropertiesPanel) View

func (p *PropertiesPanel) View(c *ui.Context) ui.Element

View draws the panel; it draws nothing without properties.

type Property

type Property struct {
	Key   string
	Value any
}

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.

func (Sel) Empty

func (s Sel) Empty() bool

Empty reports whether the selection is a caret.

func (Sel) From

func (s Sel) From() int

From and To are the selection's start and end.

func (Sel) To

func (s Sel) To() int

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.

type Uploader

type Uploader interface {
	Upload(files []File, done func(embeds string, err error))
}

Uploader stores attachments beside a note (ADR-0023) and reports the embeds to insert, through done on the UI thread.

type Where

type Where int

Where a link opens.

const (
	WhereHere Where = iota
	WhereTab
	WhereRight
	WhereWindow
)

The places a link opens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL