workspace

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 15 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 workspace is the desktop app's workspace model (docs/design/app.md#workspace, plan 0009): a tree of splits and tab groups, two sidebars of panes, the tabs closed lately, the files opened lately and the Files pane's sort and open folders. It ports app/src/workspace's model and operations, which the web app keeps; here the operations change a workspace in place on the UI thread, and the store keeps one per vault in a versioned JSON file (ADR-0021).

Index

Constants

View Source
const (
	MaxHistory  = 50
	MaxClosed   = 20
	MaxRecent   = 50
	MaxExpanded = 1000

	// Sidebar widths (docs/specs/ui.md#layout).
	SidebarMin = 200
	SidebarMax = 600
	LeftWidth  = 260
	RightWidth = 300
)

The workspace's limits, as the web app's.

View Source
const (
	ViewEmpty   = "empty"
	ViewNote    = "note"
	ViewHistory = "history"
	ViewMerge   = "merge"
	ViewFile    = "file"
)

The kinds of view.

View Source
const (
	ModeEdit = "edit"
	ModeRead = "read"
)

The modes of a note view.

View Source
const (
	KindSplit = "split"
	KindTabs  = "tabs"
)

The kinds of node.

View Source
const (
	Row    = "row"
	Column = "column"
)

The directions of a split: side by side, or stacked.

View Source
const (
	SideLeft  = "left"
	SideRight = "right"
)

The sidebars and their panes (docs/specs/ui.md#sidebars-and-panes).

View Source
const (
	Here    = "here"
	NewTab  = "tab"
	ToRight = "right"
	Below   = "down"
)

Where a view opens: in the active tab, a new tab, or a new group to the right or below.

View Source
const (
	EdgeLeft   = "left"
	EdgeRight  = "right"
	EdgeTop    = "top"
	EdgeBottom = "bottom"
)

The edges of a tab group, where a dropped tab makes a new split.

View Source
const (
	// SaveDelay is how long after the last change the workspace is written.
	SaveDelay = 500 * time.Millisecond
	// SaveRetry is how long after a failed write it is tried again.
	SaveRetry = 5 * time.Second
)
View Source
const Version = 1

Version is the stored workspace's version.

Variables

View Source
var Panes = map[string][]string{
	SideLeft:  {"files", "search"},
	SideRight: {"backlinks", "outgoing", "tags", "properties", "outline", "tasks"},
}

Panes are each sidebar's panes, in order.

Functions

func WhereFor

func WhereFor(ctrl, alt bool, button int) string

WhereFor is where a click opens what it names, as Obsidian opens links: in the current tab, Ctrl in a new tab, Ctrl+Alt to the right, a middle click in a new tab.

Types

type ClosedTab

type ClosedTab struct {
	Tab   Tab    `json:"tab"`
	Group string `json:"group"`
	Index int    `json:"index"`
}

ClosedTab is a closed tab and where it was, to reopen it.

type FilesPane

type FilesPane struct {
	Sort     string   `json:"sort"`
	Expanded []string `json:"expanded"`
}

FilesPane is the Files pane's state: its sort order and its open folders.

type MergeSide

type MergeSide struct {
	Kind    string `json:"kind"` // version, revision or held
	Version int64  `json:"version,omitzero"`
	Seq     int64  `json:"seq,omitzero"`
}

MergeSide is the other side of a merge view: a version of the file, a hub revision, or the text the editor held when notesd refused its base (in memory only: a stored workspace drops it).

type Node

type Node struct {
	Kind      string    `json:"kind"`
	ID        string    `json:"id"`
	Direction string    `json:"direction,omitzero"`
	Children  []*Node   `json:"children,omitzero"`
	Sizes     []float64 `json:"sizes,omitzero"`
	Tabs      []Tab     `json:"tabs,omitzero"`
	Active    int       `json:"active"`
}

Node is a split or a tab group. A split lays out at least two children with sizes that sum to 1; a group holds at least one tab and its active one.

func Groups

func Groups(n *Node) []*Node

Groups lists the tab groups under n, left to right and top to bottom.

type Sidebar struct {
	Panes  []string `json:"panes"`
	Active int      `json:"active"`
	Width  float64  `json:"width"`
	Open   bool     `json:"open"`
}

Sidebar is a sidebar: its panes, the selected one, its width and whether it is open.

type Store

type Store struct {

	// Err is the last write's failure, nil when it worked.
	Err error
	// OnError is told of a new failure.
	OnError func(error)
	// contains filtered or unexported fields
}

Store is the window's vault's workspace, kept in a file per vault and written SaveDelay after the last change (ADR-0021). UI thread only.

func NewStore

func NewStore(env notes.Env, dir string) *Store

NewStore keeps workspaces in dir.

func (*Store) Flush

func (s *Store) Flush()

Flush writes a pending change now.

func (*Store) Follow

func (s *Store) Follow(vaultPath string, op func(*Workspace))

Follow applies a move or delete to the workspace of the vault it happened in: the window's when that vault is shown, else the stored one, so tabs follow what happened while another vault was shown.

func (*Store) Load

func (s *Store) Load(vaultPath string)

Load shows a vault's stored workspace, writing the one shown before.

func (*Store) Reset

func (s *Store) Reset()

Reset forgets the window's vault's layout (Reset workspace layout).

func (*Store) Update

func (s *Store) Update(op func(*Workspace))

Update applies an operation and writes the result soon.

func (*Store) Vault

func (s *Store) Vault() string

Vault is the path of the vault it belongs to, "" for none.

func (*Store) Workspace

func (s *Store) Workspace() *Workspace

Workspace is the window's workspace.

type Tab

type Tab struct {
	ID   string `json:"id"`
	View View   `json:"view"`
	// Back and Forward are the views to go back and forward to, the
	// nearest last; at most MaxHistory.
	Back    []View `json:"back"`
	Forward []View `json:"forward"`
	Pinned  bool   `json:"pinned"`
}

Tab is a tab: its view and the views before and after it.

type View

type View struct {
	Type   string     `json:"type"`
	Path   string     `json:"path,omitzero"`
	Mode   string     `json:"mode,omitzero"`
	Scroll float64    `json:"scroll,omitzero"`
	Cursor int        `json:"cursor,omitzero"`
	Other  *MergeSide `json:"other,omitzero"`
}

View is what a tab shows.

func Empty

func Empty() View

Empty is the view of an empty tab.

func Note

func Note(path, mode string) View

Note is a note's view in a mode.

func (View) Same

func (v View) Same(w View) bool

Same reports whether two views show the same thing, ignoring scroll and cursor.

func (View) Title

func (v View) Title() string

Title is a tab's title as its strip shows it.

type Workspace

type Workspace struct {
	Version  int         `json:"version"`
	Root     *Node       `json:"root"`
	ActiveID string      `json:"activeGroup"` // the group holding the active tab
	Left     Sidebar     `json:"left"`
	Right    Sidebar     `json:"right"`
	Closed   []ClosedTab `json:"closed"`
	Recent   []string    `json:"recent"`
	Files    FilesPane   `json:"files"`
	NextID   int         `json:"nextId"`
}

Workspace is one vault's layout.

func New

func New() *Workspace

New is a vault's first layout: one empty tab, both sidebars open on their first pane.

func Validate

func Validate(data []byte) *Workspace

Validate reads a stored workspace, keeping what it understands and dropping the rest, so a stored layout never wedges the window; it returns a new workspace when nothing is left.

func (*Workspace) Activate

func (w *Workspace) Activate(tabID string)

Activate makes a tab its group's active tab and its group the active group.

func (*Workspace) ActiveGroup

func (w *Workspace) ActiveGroup() *Node

ActiveGroup is the group holding the window's active tab.

func (*Workspace) ActiveTab

func (w *Workspace) ActiveTab() *Tab

ActiveTab is the window's active tab.

func (*Workspace) ApplyDelete

func (w *Workspace) ApplyDelete(p string)

ApplyDelete forgets a deleted file in history and the recent files; a tab showing it stays, saying so, until it is closed or the file comes back.

func (*Workspace) ApplyMove

func (w *Workspace) ApplyMove(from, to string)

ApplyMove follows a file or folder moved from one path to another, in every view, history and list.

func (*Workspace) Back

func (w *Workspace) Back()

Back shows the active tab's previous view.

func (*Workspace) Clone

func (w *Workspace) Clone() *Workspace

Clone is a deep copy of the workspace.

func (*Workspace) Close

func (w *Workspace) Close(tabID string)

Close closes a tab, keeping it to reopen.

func (*Workspace) CloseAll

func (w *Workspace) CloseAll(groupID string)

CloseAll closes a group's unpinned tabs.

func (*Workspace) CloseOthers

func (w *Workspace) CloseOthers(tabID string)

CloseOthers closes a group's unpinned tabs but one.

func (*Workspace) CloseToTheRight

func (w *Workspace) CloseToTheRight(tabID string)

CloseToTheRight closes a group's unpinned tabs after one.

func (*Workspace) Cycle

func (w *Workspace) Cycle(delta int)

Cycle activates the next (1) or previous (-1) tab of the active group, wrapping.

func (*Workspace) FindGroup

func (w *Workspace) FindGroup(id string) *Node

FindGroup returns the group with an ID, or nil.

func (*Workspace) FindTab

func (w *Workspace) FindTab(id string) (*Node, int)

FindTab returns a tab's group and index, or nil.

func (*Workspace) Forward

func (w *Workspace) Forward()

Forward shows the active tab's next view.

func (*Workspace) GotoLastTab

func (w *Workspace) GotoLastTab()

GotoLastTab activates the active group's last tab.

func (*Workspace) GotoTab

func (w *Workspace) GotoTab(n int)

GotoTab activates the active group's nth tab, counting from 1; past the end, nothing.

func (*Workspace) MoveTab

func (w *Workspace) MoveTab(tabID, groupID string, index int, edge string)

MoveTab moves a tab into a group at an index, or, with an edge, to that edge of the group as a new group.

func (*Workspace) Open

func (w *Workspace) Open(v View, where string)

Open shows v: in the active tab, which keeps its old view to go back to, unless it is pinned; in a new tab after the active one; or in a new group to the right of or below the active group.

func (*Workspace) Pin

func (w *Workspace) Pin(tabID string, pinned bool)

Pin pins or unpins a tab.

func (*Workspace) ReopenClosed

func (w *Workspace) ReopenClosed()

ReopenClosed reopens the tab closed last where it was, or after the active tab when its group is gone.

func (*Workspace) Resize

func (w *Workspace) Resize(splitID string, sizes []float64)

Resize sets a split's sizes, normalized to sum to 1, none under 5%.

func (*Workspace) RevealPath

func (w *Workspace) RevealPath(p string)

RevealPath opens every folder holding p, so its row shows.

func (*Workspace) SelectPane

func (w *Workspace) SelectPane(side, pane string)

SelectPane shows a pane in its sidebar, opening the sidebar.

func (*Workspace) SetFolderOpen

func (w *Workspace) SetFolderOpen(folder string, open bool)

SetFolderOpen opens or closes a folder in the Files pane.

func (*Workspace) SetSidebarWidth

func (w *Workspace) SetSidebarWidth(side string, width float64)

SetSidebarWidth sets a sidebar's width, between SidebarMin and SidebarMax.

func (*Workspace) SetView

func (w *Workspace) SetView(tabID string, v View)

SetView changes a tab's view without history: its scroll, cursor or mode.

func (*Workspace) Split

func (w *Workspace) Split(tabID, where string)

Split opens a copy of a tab's view in a new group to its right or below its group.

func (*Workspace) ToggleSidebar

func (w *Workspace) ToggleSidebar(side string)

ToggleSidebar opens or closes a sidebar.

Jump to

Keyboard shortcuts

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