Documentation
¶
Overview ¶
editor.go provides inline edit-mode logic for the preview panel. It manages cursor movement, text input, undo/redo dispatch, and the atomic save flow. Functions here are called from Preview.Update when editMode is true.
Package preview implements the file preview panel for the grut TUI. It provides syntax-highlighted code display, markdown rendering, binary file detection, and a scrollable viewport.
Index ¶
- type Preview
- func (p *Preview) Blur()
- func (p *Preview) CopySelection() (panels.Panel, tea.Cmd)
- func (p *Preview) FilePath() string
- func (p *Preview) Focus()
- func (p *Preview) HasSelection() bool
- func (p *Preview) Init(_ context.Context) tea.Cmd
- func (p *Preview) KeyBindings() []panels.KeyBinding
- func (p *Preview) SetGitClient(gc git.StatusReader)
- func (p *Preview) SetSize(width, height int)
- func (p *Preview) Title() string
- func (p *Preview) Update(msg tea.Msg) (panels.Panel, tea.Cmd)
- func (p *Preview) View(width, height int) string
- type TextBuffer
- func (b *TextBuffer) Dedent(line int, tabSize int)
- func (b *TextBuffer) DeleteForward(line, col int)
- func (b *TextBuffer) DeleteRune(line, col int) (newLine, newCol int)
- func (b *TextBuffer) Dirty() bool
- func (b *TextBuffer) DuplicateLine(line int)
- func (b *TextBuffer) InsertRune(line, col int, r rune)
- func (b *TextBuffer) InsertTab(line, col int, tabSize int) int
- func (b *TextBuffer) Line(n int) string
- func (b *TextBuffer) LineCount() int
- func (b *TextBuffer) Lines() []string
- func (b *TextBuffer) MarkClean()
- func (b *TextBuffer) Redo(cursorLine, cursorCol int) (newLine, newCol int, ok bool)
- func (b *TextBuffer) SetLines(lines []string)
- func (b *TextBuffer) SplitLine(line, col int, autoIndent bool)
- func (b *TextBuffer) Undo(cursorLine, cursorCol int) (newLine, newCol int, ok bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Preview ¶
type Preview struct {
// contains filtered or unexported fields
}
Preview is the file preview panel. It displays syntax-highlighted source code, rendered markdown, or file metadata for binary/oversized files.
func New ¶
func New(cfg config.PreviewConfig, editorCfg config.EditorConfig, th *theme.Theme) *Preview
New creates a new Preview panel with the given configuration.
func (*Preview) CopySelection ¶ added in v0.1.0
CopySelection implements panels.SelectionCopier.
func (*Preview) FilePath ¶
FilePath returns the path of the currently displayed file (empty if none).
func (*Preview) HasSelection ¶ added in v0.1.0
HasSelection implements panels.SelectionCopier.
func (*Preview) KeyBindings ¶
func (p *Preview) KeyBindings() []panels.KeyBinding
KeyBindings implements panels.Panel.
func (*Preview) SetGitClient ¶
func (p *Preview) SetGitClient(gc git.StatusReader)
SetGitClient configures the git client for diff-aware preview.
func (*Preview) Title ¶
Title implements panels.Panel. Returns the filename when a file is loaded, the GitHub item title when in ghMode, or "preview" when nothing is selected.
type TextBuffer ¶ added in v0.1.0
type TextBuffer struct {
// contains filtered or unexported fields
}
TextBuffer is a line-oriented editable text buffer with undo/redo support. It stores raw text lines (no ANSI) for in-place editing within the preview panel.
func NewTextBuffer ¶ added in v0.1.0
func NewTextBuffer(lines []string) *TextBuffer
NewTextBuffer creates a buffer from the given lines, deep-copying the input. An empty or nil input produces a single empty line.
func (*TextBuffer) Dedent ¶ added in v0.1.0
func (b *TextBuffer) Dedent(line int, tabSize int)
Dedent removes up to tabSize leading spaces from the line.
func (*TextBuffer) DeleteForward ¶ added in v0.1.0
func (b *TextBuffer) DeleteForward(line, col int)
DeleteForward performs the delete-key at (line, col): removes the character at the cursor position. If the cursor is at end-of-line, the next line is joined onto the current one.
func (*TextBuffer) DeleteRune ¶ added in v0.1.0
func (b *TextBuffer) DeleteRune(line, col int) (newLine, newCol int)
DeleteRune performs backspace at (line, col): deletes the character before the cursor. If col==0 and line>0, the current line joins with the previous one. Returns the new cursor position.
func (*TextBuffer) Dirty ¶ added in v0.1.0
func (b *TextBuffer) Dirty() bool
Dirty reports whether the buffer has unsaved changes.
func (*TextBuffer) DuplicateLine ¶ added in v0.1.0
func (b *TextBuffer) DuplicateLine(line int)
DuplicateLine duplicates the line at the given index, inserting the copy below it. Always forces an undo break.
func (*TextBuffer) InsertRune ¶ added in v0.1.0
func (b *TextBuffer) InsertRune(line, col int, r rune)
InsertRune inserts a rune at (line, col). Out-of-bounds values are clamped. Undo snapshots are coalesced for rapid consecutive inserts.
func (*TextBuffer) InsertTab ¶ added in v0.1.0
func (b *TextBuffer) InsertTab(line, col int, tabSize int) int
InsertTab inserts spaces to the next tab stop at (line, col) and returns the new column. tabSize is clamped to >= 1.
func (*TextBuffer) Line ¶ added in v0.1.0
func (b *TextBuffer) Line(n int) string
Line returns line n. Returns "" if n is out of range.
func (*TextBuffer) LineCount ¶ added in v0.1.0
func (b *TextBuffer) LineCount() int
LineCount returns the number of lines in the buffer.
func (*TextBuffer) Lines ¶ added in v0.1.0
func (b *TextBuffer) Lines() []string
Lines returns the current lines (read-only view).
func (*TextBuffer) MarkClean ¶ added in v0.1.0
func (b *TextBuffer) MarkClean()
MarkClean clears the dirty flag, typically called after a successful save.
func (*TextBuffer) Redo ¶ added in v0.1.0
func (b *TextBuffer) Redo(cursorLine, cursorCol int) (newLine, newCol int, ok bool)
Redo restores the next buffer snapshot. Returns the restored cursor position and true, or the original position and false if nothing to redo.
func (*TextBuffer) SetLines ¶ added in v0.1.0
func (b *TextBuffer) SetLines(lines []string)
SetLines replaces all content, marks the buffer dirty, and clears undo/redo.
func (*TextBuffer) SplitLine ¶ added in v0.1.0
func (b *TextBuffer) SplitLine(line, col int, autoIndent bool)
SplitLine splits the line at col (Enter key). If autoIndent is true the new line inherits the leading whitespace of the current line.