fix(ui): rendering issues when opening files with -t flag

When passing a file via the CLI with the TUI flag (-t), the -w flag was
ignored and window resizing would result in a blank screen. This was
caused by the file content not being stored in currentDocument.Body
during Init(). Consequently, the first WindowSizeMsg triggered a
re-render with an empty body, discarding the initial content.

Replaced manual file reading in Init() with loadLocalMarkdown() to
ensure the body is correctly stored and a fetchedMarkdownMsg is
emitted. This ensures content is preserved during re-renders and that
the word wrap width is correctly applied.

Fixes #878
This commit is contained in:
Dhanush Shetty 2026-02-20 00:38:39 +05:30
commit 820dbd1a2e

View file

@ -190,13 +190,7 @@ func (m model) Init() tea.Cmd {
case stateShowStash:
cmds = append(cmds, findLocalFiles(*m.common))
case stateShowDocument:
content, err := os.ReadFile(m.common.cfg.Path)
if err != nil {
log.Error("unable to read file", "file", m.common.cfg.Path, "error", err)
return func() tea.Msg { return errMsg{err} }
}
body := string(utils.RemoveFrontmatter(content))
cmds = append(cmds, renderWithGlamour(m.pager, body))
cmds = append(cmds, loadLocalMarkdown(&m.pager.currentDocument))
}
return tea.Batch(cmds...)