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 ¶
- type Bookmark
- type Store
- func (s *Store) Add(b Bookmark) bool
- func (s *Store) ByFile(path string) []Bookmark
- func (s *Store) List() []Bookmark
- func (s *Store) Reanchor(path string, lines []string) int
- func (s *Store) Remove(path string, line int) bool
- func (s *Store) Save(path string) error
- func (s *Store) Toggle(b Bookmark) bool
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 ¶
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 (*Store) Add ¶
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) List ¶
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 ¶
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.