fix(ui): rendering issues when opening files with -t flag#887
Open
dhanush0x96c wants to merge 1 commit intocharmbracelet:masterfrom
Open
fix(ui): rendering issues when opening files with -t flag#887dhanush0x96c wants to merge 1 commit intocharmbracelet:masterfrom
dhanush0x96c wants to merge 1 commit intocharmbracelet:masterfrom
Conversation
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 charmbracelet#878
Author
|
Hey @aymanbagabas and @raphamorim! Just a gentle ping on this PR when you get a chance. Would really appreciate your feedback 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #878
Problem
When opening a file directly in TUI mode (
glow -t README.mdorglow -w 60 -t README.md), the-w(word wrap width) flag was ignored. The word wrap only took effect after escaping from edit mode.Root Cause
In
ui/ui.go, theInit()function read the file content and passed it torenderWithGlamour()but never stored the body incurrentDocument.Body. When the firstWindowSizeMsgarrived (which sets the correct viewport dimensions), the pager attempted to re-render usingcurrentDocument.Body— which was an empty string. This caused the initial render (done before viewport dimensions were known) to be discarded and replaced with a blank re-render, effectively ignoring the configured word wrap width.Fix
Replaced the manual file read in
Init()withloadLocalMarkdown(), which:currentDocument.BodyfetchedMarkdownMsgthat triggers rendering with the correct bodyThis ensures that when
WindowSizeMsgtriggers a re-render,currentDocument.Bodycontains the actual file content, and the word wrap width is applied correctly.Changed File
ui/ui.go— Replaced inline file reading inInit()with a call toloadLocalMarkdown(&m.pager.currentDocument).I have read
CONTRIBUTING.md.I have created a discussion that was approved by a maintainer (for new features).