Single-file mode for direct file invocations#38
Merged
Conversation
When invoked as 'spiceedit somefile.md' the user is asking to look at one file, not to open a project. Skip the file-tree walk, the project-wide finder index, and the 10s background tree-refresh goroutine — none of them are visible to the user in that mode and on a large directory they're real CPU. main.go routes to a new app.NewSingleFile(path) constructor when an OpenFile is resolved; otherwise it stays on app.New(rootDir). The constructor leaves tree and finder nil, hides the sidebar, and opens the file as the first tab. The action menu's 'Show / Hide file explorer' row is filtered out via a new visibility predicate (hasTree) so the user can't try to show a sidebar that doesn't exist. The same machinery (visible func on menuItemDef) is general-purpose so future tree-dependent rows can opt in the same way. Tree-Refresh sites in fileops are routed through a small refreshTree() helper that no-ops when tree is nil.
# Conflicts: # internal/app/app.go
Fresh-eyes review of the merged single-file-mode feature surfaced three issues where post-merge code assumes a file tree that single-file mode deliberately omits: - Esc-t (menuToggleSidebar) bypassed the menu's hasTree gate and flipped sidebarShown true, sending draw() into a.tree.Render on a nil tree and panicking. Now a no-op with a flash. - Esc-p (openFinder) similarly bypassed the gate and popped an always-empty finder modal. Now a no-op with a flash. - Saving in single-file mode routes through refreshGitStatus, which bailed on nil tree and left the git gutter markers stale. It now refreshes the per-line markers (a file-scoped git diff) even without a tree. Adds regression tests for all three.
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.
Summary
spiceedit somefile.mdno longer walks the surrounding directory just to render a sidebar the user didn't ask for. Newapp.NewSingleFileconstructor skips the file tree, the project-wide finder index, and the 10s background tree-refresh goroutine.visiblepredicate tomenuItemDefso future tree-dependent rows can opt in the same way.Behavior matrix
spiceeditspiceedit .spiceedit somedir/spiceedit somefile.mdTest plan
make test— all green locally with the race detectorspiceedit README.mdopens the file with no sidebar visibletime spiceedit README.mdstartup is noticeably faster thantime spiceedit .spiceedit nonexistent.mdstill works (vim-style "create on first save")spiceedit somedir/still shows the sidebar and full treehasFinder/hasActiveSubfolderand continue to behave correctly withfinder == nil/ no subfolder)