bookmarks

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bookmarks is the persistent store behind an IDE's code bookmarks: (file, line) marks with a note, written to one JSON file and re-anchored to the text of their line so a mark survives edits made above it — including edits made while the IDE was closed.

It is UI-free. ged.BookmarksPanel renders whatever flat list the host pushes into it and gui.CodeEditor keeps per-buffer marks that die with the buffer; this package is the part that outlives both, and is the only one that has to be deterministic on disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bookmark

type Bookmark struct {
	Path    string `json:"path"`
	Line    int    `json:"line"`
	Context string `json:"context,omitempty"`
	Note    string `json:"note,omitempty"`
}

Bookmark is one mark.

Line is 1-based, matching what a gutter shows and how Reanchor indexes the file's lines (lines[Line-1]). Context is the text of that line when the mark was set — Reanchor's only way to find the line again after it moved — and Note is the user's label.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a set of bookmarks, unique by (Path, Line). It is not goroutine-safe: the IDE drives it from the UI thread.

func Load

func Load(path string) (*Store, error)

Load reads a bookmark file written by Save. Entries go through Add, so a hand-edited file with duplicate or unusable marks loads clean instead of poisoning the store. A missing file is returned as an error — check os.IsNotExist to tell "no bookmarks yet" from "unreadable file".

func NewStore

func NewStore() *Store

NewStore returns an empty store.

func (*Store) Add

func (s *Store) Add(b Bookmark) bool

Add inserts b, or refreshes the Context and Note of the mark already at (b.Path, b.Line). A mark with no Path or a Line below 1 is rejected: it can be neither jumped to nor re-anchored. Reports whether a new mark was inserted.

func (*Store) ByFile

func (s *Store) ByFile(path string) []Bookmark

ByFile returns path's marks, ordered by line.

func (*Store) List

func (s *Store) List() []Bookmark

List returns every mark ordered by path then line. The slice is a copy and the order does not depend on insertion order, so the result can be rendered, diffed or written to disk as-is.

func (*Store) Reanchor

func (s *Store) Reanchor(path string, lines []string) int

Reanchor re-points path's bookmarks at the file's current text, lines being the file split into lines (lines[0] is line 1). A mark whose Context still matches its line is left alone; one whose line no longer carries its Context is moved to the nearest line within maxDrift that does, closest first and the lower line number on a tie. A mark with no Context, or whose Context is gone from that window, keeps its line — a stale line number is more useful than a silently dropped bookmark.

Matching ignores leading and trailing whitespace, so a re-indented line still counts as the same line. When a move lands on a line that already has a mark the two are merged, keeping the older one. Returns the number of marks that moved.

func (*Store) Remove

func (s *Store) Remove(path string, line int) bool

Remove deletes the mark at (path, line) and reports whether one was there.

func (*Store) Save

func (s *Store) Save(path string) error

Save writes the store to path as a JSON array in List order, creating the parent directory when needed. The bytes go to a sibling temp file that is renamed into place, so a crash mid-write cannot truncate the bookmark file.

func (*Store) Toggle

func (s *Store) Toggle(b Bookmark) bool

Toggle drops the mark at (b.Path, b.Line) when one exists and adds b otherwise. It reports whether the mark is set afterwards, which is what a gutter click needs in order to redraw itself.

Jump to

Keyboard shortcuts

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