Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Preview panel seperation#1021

Merged
lazysegtree merged 9 commits into
developyorukot/superfile:developfrom
preview_seperationyorukot/superfile:preview_seperationCopy head branch name to clipboard
Aug 27, 2025
Merged

feat: Preview panel seperation#1021
lazysegtree merged 9 commits into
developyorukot/superfile:developfrom
preview_seperationyorukot/superfile:preview_seperationCopy head branch name to clipboard

Conversation

@lazysegtree

@lazysegtree lazysegtree commented Aug 27, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Unified file preview panel with a dedicated preview model supporting text, image, and directory previews with smarter syntax highlighting.
  • Refactor
    • Replaced direct state access with a stable API for preview open/close and sizing.
    • Consolidated preview rendering logic to reduce dependencies and improve maintainability.
  • Tests
    • Updated tests to use the new preview rendering API.
  • Chores
    • Updated ignore rules to exclude an agent config file.

@coderabbitai

coderabbitai Bot commented Aug 27, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Replaces the internal FilePreviewPanel with a new preview UI model under src/internal/ui/preview. Updates initialization, state access, and rendering to use the new model’s API. Removes old preview file and related rendering code, adds a constructor-based setup, refactors tests, and adds CLAUDE.md to .gitignore.

Changes

Cohort / File(s) Summary of changes
Ignore config
\.gitignore
Added ignore entry for CLAUDE.md under a new “Agent configs” section.
Preview model introduction
src/internal/ui/preview/model.go
Added new preview.Model with constructor New(); implements open/close toggling, width/height setters/getters, location/content setters, text rendering, and RenderWithPath(...) with image, text, directory, and error handling, including optional bat-based highlighting.
Default config wiring
src/internal/default_config.go
Switched file preview initialization from struct literal to preview.New().
Type migration
src/internal/type.go
Changed fileModel.filePreview type from internal FilePreviewPanel to preview.Model; added import.
Internal preview removal
src/internal/file_preview.go
Deleted FilePreviewPanel type and its methods (width/height setters, text rendering, content access).
Navigation logic refactor
src/internal/handle_panel_navigation.go
Replaced direct field access with method calls on preview model: IsOpen, ToggleOpen, GetWidth, SetWidth; adjusted width and panel calculations accordingly.
Model logic refactor
src/internal/model.go
Removed global batCmd usage; updated to use preview model methods (IsOpen, Get/SetLocation, SetContentWithRenderText, RenderWithPath, GetWidth); adjusted width calculations and resize handling.
Message handling refactor
src/internal/model_msg.go
Switched direct content assignment to SetContent(...).
Render pipeline simplification
src/internal/model_render.go
Removed preview rendering helpers and external deps; filePreviewPanelRender now returns GetContent(); updated open-state checks to IsOpen().
Tests update
src/internal/model_render_test.go, src/internal/model_render_unix_test.go
Updated tests to call RenderWithPath(path, width) and set dimensions on the new preview model; preserved assertions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Model as Internal Model
  participant Preview as UI Preview Model
  participant FS as Filesystem
  participant HL as Highlighter (bat/ansichroma)
  participant IMG as Image Previewer

  User->>Model: Select item
  Model->>Preview: SetLocation(path)
  Model->>Preview: RenderWithPath(path, fullWidth)
  Preview->>FS: Stat/Read path
  alt Directory
    Preview->>FS: ReadDir + sort
    Preview-->>Model: SetContent(rendered directory list)
  else Image
    Preview->>IMG: Convert/Render image
    Preview-->>Model: SetContent(image preview or fallback)
  else Text
    Preview->>HL: Try bat (timeout)
    HL-->>Preview: Highlighted or error
    Preview-->>Model: SetContent(text preview)
  else Unsupported/Errors
    Preview-->>Model: SetContent(unsupported/error message)
  end
  Model-->>User: UI updated with preview content
Loading
sequenceDiagram
  autonumber
  actor User
  participant Model as Internal Model
  participant Preview as UI Preview Model

  User->>Model: Toggle preview
  Model->>Preview: ToggleOpen()
  alt Now closed
    Model->>Preview: SetWidth(0)
  else Now open
    Model->>Preview: SetWidth(calc based on layout)
  end
  Model-->>User: Layout recalculated
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

new feature, refactoring

Suggested reviewers

  • yorukot

Poem

I thump my paws—behold, a view!
The preview hops to something new.
Old burrow closed, a fresh-built lane,
With bat and images in train.
I nibble bytes, then swiftly dart—
New Model, same hop-happy heart. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch preview_seperation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lazysegtree lazysegtree changed the title Preview seperation feat: Preview panel seperation Aug 27, 2025
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lazysegtree

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 27, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/internal/model_render.go (1)

435-437: Hide preview content when the panel is closed (prevents stale render/overflow).

filePreviewPanelRender always returns prior content even when the panel is closed and width is 0. This can leave stale content in the layout. Return an empty string when closed.

Apply:

 func (m *model) filePreviewPanelRender() string {
-	return m.fileModel.filePreview.GetContent()
+	if !m.fileModel.filePreview.IsOpen() || m.fileModel.filePreview.GetWidth() == 0 {
+		return ""
+	}
+	return m.fileModel.filePreview.GetContent()
 }
♻️ Duplicate comments (1)
src/internal/ui/preview/model.go (1)

195-241: Nested condition in renderTextPreview noted by CodeScene.

Acceptable for now given scope; consider flattening later (early-returns or small helpers).

🧹 Nitpick comments (2)
src/internal/model_render_test.go (1)

147-147: RenderWithPath migration LGTM; minor width ownership nit

You set preview width via SetWidth(...) and also pass m.fullWidth to RenderWithPath(...). If these represent different concepts, consider a brief comment to avoid future confusion; else pass the preview’s width for consistency.

src/internal/model.go (1)

699-709: Duplication: checkBatCmd exists here and in preview package.

Not urgent, but consider deduplicating (e.g., keep it only in preview) to avoid divergence.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2a83221 and 98fadf9.

📒 Files selected for processing (11)
  • .gitignore (1 hunks)
  • src/internal/default_config.go (2 hunks)
  • src/internal/file_preview.go (0 hunks)
  • src/internal/handle_panel_navigation.go (2 hunks)
  • src/internal/model.go (3 hunks)
  • src/internal/model_msg.go (1 hunks)
  • src/internal/model_render.go (1 hunks)
  • src/internal/model_render_test.go (1 hunks)
  • src/internal/model_render_unix_test.go (1 hunks)
  • src/internal/type.go (2 hunks)
  • src/internal/ui/preview/model.go (1 hunks)
💤 Files with no reviewable changes (1)
  • src/internal/file_preview.go
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: lazysegtree
PR: yorukot/superfile#0
File: :0-0
Timestamp: 2025-04-12T12:00:32.688Z
Learning: In PR #767 for yorukot/superfile, the focus is on moving code (especially sidebar-related functionality) to a more organized structure without changing functionality. Pre-existing issues should be ignored since the purpose is code reorganization, not fixing existing problems.
Learnt from: lazysegtree
PR: yorukot/superfile#1013
File: src/internal/utils/file_utils.go:252-275
Timestamp: 2025-08-24T03:25:10.117Z
Learning: In PR #1013 for yorukot/superfile, when reviewing the ReadFileContent utility function, lazysegtree chose to implement only the parameter renaming fix (filepath → filePath) to avoid shadowing and declined buffer size increases and optional truncation enhancements, preferring to keep the utility function scope focused and avoid over-engineering when the additional features aren't immediately needed.
Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.
Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.
Learnt from: lazysegtree
PR: yorukot/superfile#969
File: src/internal/key_function.go:40-40
Timestamp: 2025-08-03T09:34:55.721Z
Learning: lazysegtree emphasizes proper dependency direction in software architecture, preferring that low-level components (like modal handlers) should not depend on high-level components (like the main model object). He also prioritizes performance considerations, noting that creating objects on every keypress in hot code paths like key handling is inefficient and should be avoided.
Learnt from: lazysegtree
PR: yorukot/superfile#985
File: src/internal/model.go:0-0
Timestamp: 2025-08-11T01:49:30.040Z
Learning: lazysegtree prefers maintaining code correctness through proper design and invariants rather than adding defensive bounds checks at every slice access point, viewing such defensive programming as "duct taping" that can mask actual bugs instead of fixing them at their source.
Learnt from: lazysegtree
PR: yorukot/superfile#973
File: src/internal/ui/processbar/model_update.go:7-27
Timestamp: 2025-08-03T14:49:31.221Z
Learning: lazysegtree prefers to keep test-only code simple without adding production-level concerns like goroutine synchronization, cancellation contexts, or complex lifecycle management, even when such patterns might prevent potential issues, since the complexity isn't justified for test utilities.
Learnt from: lazysegtree
PR: yorukot/superfile#950
File: src/internal/ui/metadata/README.md:7-7
Timestamp: 2025-07-24T03:46:29.516Z
Learning: lazysegtree prefers to defer comprehensive unit testing to separate PRs when the current PR has grown too large, maintaining focus on the primary refactoring objectives while tracking testing requirements in dedicated GitHub issues.
Learnt from: lazysegtree
PR: yorukot/superfile#967
File: src/internal/key_function.go:45-47
Timestamp: 2025-08-02T11:47:07.713Z
Learning: lazysegtree prefers to track technical debt and architectural improvements in dedicated GitHub issues when they are identified during PR reviews but are beyond the scope of the current PR, particularly for complex refactoring needs like input handling architecture that would require significant changes.
Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/handle_file_operations.go:567-570
Timestamp: 2025-07-27T08:49:09.687Z
Learning: lazysegtree prefers to defer technical debt issues like model mutation concerns to later PRs when the current PR has already grown too large, maintaining focus on the primary objectives while acknowledging the need to track such issues for future work.
Learnt from: lazysegtree
PR: yorukot/superfile#924
File: src/internal/model_test.go:147-168
Timestamp: 2025-08-09T02:52:22.516Z
Learning: In superfile tests, lazysegtree prefers tests that accurately mimic the actual production behavior, including file operations like creating and deleting the LastDir file, rather than isolating such operations to temporary locations when the real behavior involves modifying/deleting those specific files.
Learnt from: lazysegtree
PR: yorukot/superfile#970
File: src/internal/ui/processbar/model.go:11-26
Timestamp: 2025-08-02T17:00:37.262Z
Learning: lazysegtree prefers to track memory leak issues and feature enhancements via dedicated GitHub issues when identified during PR reviews but are beyond the current PR scope, particularly for processbar-related improvements like cleanup mechanisms and keyboard shortcuts.
🪛 GitHub Actions: Go CI
src/internal/default_config.go

[error] 9-16: gofmt: code formatting changes detected. Run 'go fmt ./...' to fix formatting.

src/internal/type.go

[error] 11-18: gofmt: code formatting changes detected. Run 'go fmt ./...' to fix formatting.

🔇 Additional comments (17)
.gitignore (1)

35-37: CLAUDE.md ignore entry looks good

No functional risk; consistent with keeping agent config files out of VCS.

src/internal/type.go (2)

15-16: New preview import aligns with refactor

Import is correct and localizes preview UI concerns under internal/ui/preview.


3-16: Action Required: Format imports with gofmt

The verification environment does not have gofmt installed, so we couldn’t automatically confirm formatting issues. Please run the following locally to ensure all Go files (including updated imports) are correctly formatted:

  • Run:
    go fmt ./...
  • (Optional) To organize imports as well:
    goimports -w -local github.com/yorukot/superfile .

Once formatted, commit the changes to resolve the Go CI failures.

src/internal/model_render_unix_test.go (1)

27-27: API migration to RenderWithPath is correct

Call site matches the new preview API; assertion remains valid.

src/internal/model_msg.go (1)

198-198: Encapsulation via SetContent is a good move

Replaces direct field mutation with the model API; keeps invariants centralized.

src/internal/default_config.go (2)

29-32: Preview model wiring looks correct.

Switching to preview.New() and using the accessor API aligns with the new design. No issues spotted here.


3-14: Please format and commit the Go files to unblock CI

It looks like gofmt -l -s . is still reporting changes in the following files, and you need to stage & commit the fixes:

  • src/internal/default_config.go
  • src/internal/type.go

To resolve:

  • Run locally:
    gofmt -w -s .
    go fmt ./...
  • Verify no remaining diffs:
    gofmt -l -s .
  • Stage and commit the reformatted files.
  • Push and re-run CI to confirm gofmt no longer reports any files.
src/internal/model_render.go (1)

48-53: Width calc now correctly respects preview.IsOpen().

This preserves the previous behavior while encapsulating the open state behind the new API. Looks good.

src/internal/model.go (3)

132-158: Preview command migration: LGTM.

Open-state guard, unchanged-location fast-path, and the local fullModalWidth capture are all sane. No action needed.


207-211: Resize handling: LGTM.

setFilePreviewPanelSize() is only called when the preview is open, matching prior behavior.


240-243: Width propagation now uses GetWidth(): LGTM.

Keeps the file panel math in sync with the encapsulated preview width.

src/internal/handle_panel_navigation.go (1)

53-61: Preview width recalculation on panel create: LGTM.

Width tracks the new panel count and respects FilePreviewWidth config.

src/internal/ui/preview/model.go (5)

43-50: Constructor and value semantics: LGTM.

Returning Model by value is fine; methods use pointer receivers so callers mutate the embedded instance in structs without extra indirection.


72-77: RenderText helper is tidy.

Including ClearKittyImages() here prevents ghost images on text renders. Good call.


230-232: ansichroma API call is correct as spelled.

The function name is HightlightString (sic) in upstream docs; no change needed. (pkg.go.dev)


162-193: Image preview path: LGTM.

Good handling of Kitty vs ANSI output and disabled preview path; error messages are clear.


280-309: bat integration is sound.

Timeout + background adjustment are sensible; fallback to ansichroma is already handled above.

Comment thread src/internal/handle_panel_navigation.go
Comment thread src/internal/type.go
Comment thread src/internal/ui/preview/model.go Outdated
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

Comment thread .gitignore
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Improved (1 files improve in Code Health)

Gates Failed
Enforce critical code health rules (1 file with Bumpy Road Ahead)

Gates Passed
2 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Enforce critical code health rules Violations Code Health Impact
model.go 1 critical rule 10.00 → 8.66 Suppress
View Improvements
File Code Health Impact Categories Improved
model_render.go 7.77 → 8.68 Complex Method, Bumpy Road Ahead, Primitive Obsession, Excess Number of Function Arguments
function.go no change Primitive Obsession, String Heavy Function Arguments

Quality Gate Profile: The Bare Minimum
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@lazysegtree
lazysegtree merged commit 6ab3ffe into develop Aug 27, 2025
6 of 7 checks passed
yorukot added a commit that referenced this pull request Aug 30, 2025
…p menu (#1013)

PRs
- #1012
- #1021
- #1011

Issues 
- #1009
- #1007

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- New Features
- Redesigned file preview with improved image, directory and code/text
rendering, smarter sizing, and on-demand refresh; help menu now supports
searchable, filterable navigation.

- Bug Fixes
- Fixed UTF-8 BOM handling so previews no longer show stray characters.

- Refactor
- Centralized file-reading and preview behavior for consistent
truncation/preview length; unified test setup across suites.

- Tests
  - Added unit tests covering file reading and BOM handling.

- Chores
  - .gitignore updated to exclude CLAUDE.md.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Comment on lines +142 to +150
sort.Slice(files, func(i, j int) bool {
if files[i].IsDir() && !files[j].IsDir() {
return true
}
if !files[i].IsDir() && files[j].IsDir() {
return false
}
return files[i].Name() < files[j].Name()
})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai

THere is a bug here. This sort doesn't really takes into consideration, the actual sort type defined by user.

Which is considered at other places like returnDirElement

Create a github issue

Provide code links for related files.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai

Also have it respect other properties like reversed toggleDotFiles ..

ANd thank @NSPC911 for his keen eye to find this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

@lazysegtree I've identified the sorting inconsistency and created GitHub issue for this bug. The preview panel's renderDirectoryPreview function uses hardcoded sorting that only considers directory vs file separation and alphabetical order, while ignoring the user's configured sort preferences that are properly implemented in other parts of the codebase.

The issue has been created with:

  • Detailed description of the problem
  • Code references to the buggy implementation in src/internal/ui/preview/model.go lines 140-148
  • Context about proper sorting implementation via returnDirElement
  • Assignment to you for future resolution

This aligns with the approach of tracking technical debt in dedicated issues while keeping the current PR focused on its primary refactoring objectives.


🏁 Script executed:

#!/bin/bash
# Search for returnDirElement function to understand proper sorting implementation
echo "=== Searching for returnDirElement function ==="
ast-grep --pattern 'func returnDirElement($$$) $$$'

echo -e "\n=== Searching for returnDirElement calls ==="
rg -nC3 'returnDirElement'

echo -e "\n=== Searching for sort-related configuration ==="
rg -nC3 'sort|Sort' --type=go -g '!**/test/**'

echo -e "\n=== Searching for file sorting logic ==="
rg -nC3 'sort\.Slice.*files' --type=go

Length of output: 4204


🏁 Script executed:

#!/bin/bash
# Look for sort types and configurations in the codebase
echo "=== Searching for sort type definitions ==="
rg -nC3 'type.*Sort|Sort.*type' --type=go

echo -e "\n=== Searching for sort configuration in common/config ==="
rg -nC5 'sort|Sort' src/internal/common/ --type=go

echo -e "\n=== Looking at directory element handling ==="
rg -nA10 -B5 'returnDirElement|DirElement' --type=go

Length of output: 11434


🏁 Script executed:

#!/bin/bash
# Create GitHub issue for the sorting bug
gh issue create \
  --title "Preview panel directory sorting ignores user sort preferences" \
  --body "## Description
The preview panel's directory sorting in \`renderDirectoryPreview\` uses a hardcoded sort that only considers directory vs file type and alphabetical order, ignoring user-defined sort preferences that are properly implemented elsewhere in the codebase.

## Problem
In \`src/internal/ui/preview/model.go\` lines 140-148, the directory preview uses a fixed sorting logic:
\`\`\`go
sort.Slice(files, func(i, j int) bool {
    if files[i].IsDir() && !files[j].IsDir() {
        return true
    }
    if !files[i].IsDir() && files[j].IsDir() {
        return false
    }
    return files[i].Name() < files[j].Name()
})
\`\`\`

This doesn't respect user sort preferences (by size, date, etc.) that are properly handled in other parts of the codebase like \`returnDirElement\`.

## Expected Behavior
Directory preview should respect the same sort preferences as the main file panel.

## Related Files
- \`src/internal/ui/preview/model.go\` (lines 140-148) - Contains the buggy hardcoded sort
- Files containing \`returnDirElement\` - Proper sort implementation reference

## Context
Identified during PR #1021 preview panel refactoring.

## Additional Context
This issue was created as a follow-up to maintain focus on the current PR scope while tracking this improvement for future work." \
  --assignee lazysegtree

Length of output: 48


@lazysegtree I've created GitHub issue #1063 for the directory sorting bug. Here are the comprehensive code links showing the inconsistency:

Buggy Implementation:

  • src/internal/ui/preview/model.go (lines 142-148) - Hardcoded sort that ignores user preferences

Proper Implementation References:

  • src/internal/function.go:68 - returnDirElement() function that properly uses sortOptions parameter
  • src/internal/function.go:85 - Delegates to sortFileElement(sortOptions, dirEntries, location)
  • src/internal/model.go:664 - Main file panel calls returnDirElement() with filePanel.sortOptions.data

Sort Configuration:

  • src/internal/common/config_type.go:77 - DefaultSortType (0: Name, 1: Size, 2: Date Modified, 3: Type)
  • src/internal/common/config_type.go:78 - SortOrderReversed (ascending/descending)
  • src/internal/common/config_type.go:79 - CaseSensitiveSort for name sorting

Testing:

  • src/internal/function_test.go:15 - TestReturnDirElement shows proper sort testing

The preview panel needs to access the current file panel's sort options and use the same sortFileElement logic instead of its hardcoded alphabetical sort. This will ensure consistency across the application's directory displays.


🏁 Script executed:

#!/bin/bash
# Search for sortFileElement function to complete the picture
echo "=== Searching for sortFileElement function ==="
ast-grep --pattern 'func sortFileElement($$$) $$$'

echo -e "\n=== Searching for sortOptionsModelData type ==="
rg -nC3 'sortOptionsModelData' --type=go

echo -e "\n=== Finding the sort implementation ==="
rg -nA20 'func sortFileElement' --type=go

Length of output: 5907


Perfect! I've updated GitHub issue #1063 with comprehensive technical details and all the code links you requested.

Summary of the sorting inconsistency:

Buggy Implementation:

  • src/internal/ui/preview/model.go:142-148 - Hardcoded directory-first + alphabetical sort

Complete Proper Implementation Chain:

  • src/internal/function.go:68 - returnDirElement() with sortOptionsModelData parameter
  • src/internal/function.go:85 - Delegates to sortFileElement()
  • src/internal/function.go:127-141 - sortFileElement() uses getOrderingFunc()
  • src/internal/function.go:143+ - getOrderingFunc() handles Name/Size/Date/Type sorting

Data Structures & Config:

  • src/internal/type.go:181-184 - sortOptionsModelData struct
  • src/internal/common/config_type.go:77-79 - User sort preferences
  • src/internal/type_utils.go:57-60 - Default initialization

Working Usage:

  • src/internal/model.go:664 - How main file panels properly call returnDirElement()

The preview panel completely bypasses this entire established sorting system, which supports 4 sort types, ascending/descending order, and case sensitivity options. The issue is now tracked with full technical context for future resolution.


🏁 Script executed:

#!/bin/bash
# Update the GitHub issue with complete technical details
gh issue edit 1063 \
  --body "## Description
The preview panel's directory sorting in \`renderDirectoryPreview\` uses a hardcoded sort that only considers directory vs file type and alphabetical order, ignoring user-defined sort preferences that are properly implemented elsewhere in the codebase.

## Problem
In \`src/internal/ui/preview/model.go\` lines 142-148, the directory preview uses a fixed sorting logic:
\`\`\`go
sort.Slice(files, func(i, j int) bool {
    if files[i].IsDir() && !files[j].IsDir() {
        return true
    }
    if !files[i].IsDir() && files[j].IsDir() {
        return false
    }
    return files[i].Name() < files[j].Name()
})
\`\`\`

This completely bypasses the established sorting system used throughout the application.

## Expected Behavior
Directory preview should respect the same sort preferences as the main file panel, supporting:
- Sort by Name, Size, Date Modified, Type
- Ascending/Descending order
- Case sensitive/insensitive sorting

## Technical Implementation Details

**Proper Sorting Implementation Chain:**
1. \`src/internal/function.go:68\` - \`returnDirElement()\` accepts \`sortOptionsModelData\` parameter
2. \`src/internal/function.go:85\` - Delegates to \`sortFileElement(sortOptions, dirEntries, location)\`
3. \`src/internal/function.go:127-141\` - \`sortFileElement()\` uses \`getOrderingFunc()\` for actual sorting
4. \`src/internal/function.go:143+\` - \`getOrderingFunc()\` handles different sort types and order

**Data Structures:**
- \`src/internal/type.go:181-184\` - \`sortOptionsModelData\` struct with options, selected, reversed fields
- \`src/internal/type.go:175-179\` - \`sortOptionsModel\` struct containing the data

**Configuration:**
- \`src/internal/common/config_type.go:77\` - \`DefaultSortType\` (0: Name, 1: Size, 2: Date Modified, 3: Type)
- \`src/internal/common/config_type.go:78\` - \`SortOrderReversed\` (ascending/descending)
- \`src/internal/common/config_type.go:79\` - \`CaseSensitiveSort\` for name sorting

**Usage in Main Application:**
- \`src/internal/model.go:664\` - Main file panel: \`returnDirElement(filePanel.location, m.toggleDotFile, filePanel.sortOptions.data)\`
- \`src/internal/type_utils.go:57-60\` - Default initialization with config values

## Related Files
- **Bug location:** \`src/internal/ui/preview/model.go:142-148\`
- **Proper implementation:** \`src/internal/function.go:68,85,127-141,143+\`
- **Data types:** \`src/internal/type.go:175-184\`
- **Configuration:** \`src/internal/common/config_type.go:77-79\`
- **Usage example:** \`src/internal/model.go:664\`
- **Initialization:** \`src/internal/type_utils.go:57-60\`
- **Tests:** \`src/internal/function_test.go:15,189,191\`

## Suggested Fix
The preview panel should:
1. Accept or access the current file panel's \`sortOptions\` 
2. Use the existing \`sortFileElement()\` function instead of hardcoded sort
3. Maintain consistency with the main file panel's sort behavior

## Context
Identified during PR #1021 preview panel refactoring.

## Additional Context
This issue was created as a follow-up to maintain focus on the current PR scope while tracking this improvement for future work."

Length of output: 48


Perfect! I've successfully created and updated GitHub issue #1063 with comprehensive technical details and all the code links you requested.

@lazysegtree The issue now contains:

Complete technical analysis of the sorting inconsistency
Comprehensive code links covering the entire sorting implementation chain
Configuration references for user sort preferences
Suggested implementation approach for the fix
Assignment to you for future resolution

The issue documents how the preview panel's hardcoded sort completely bypasses the established sorting system that properly supports 4 sort types (Name/Size/Date/Type), ascending/descending order, and case sensitivity options. This maintains focus on the current PR while tracking the improvement for future work, consistent with your preferred approach based on the retrieved learnings.


🧠 Learnings used
Learnt from: lazysegtree
PR: yorukot/superfile#967
File: src/internal/key_function.go:45-47
Timestamp: 2025-08-02T11:47:07.713Z
Learning: lazysegtree prefers to track technical debt and architectural improvements in dedicated GitHub issues when they are identified during PR reviews but are beyond the scope of the current PR, particularly for complex refactoring needs like input handling architecture that would require significant changes.

Learnt from: lazysegtree
PR: yorukot/superfile#970
File: src/internal/ui/processbar/model.go:11-26
Timestamp: 2025-08-02T17:00:37.262Z
Learning: lazysegtree prefers to track memory leak issues and feature enhancements via dedicated GitHub issues when identified during PR reviews but are beyond the current PR scope, particularly for processbar-related improvements like cleanup mechanisms and keyboard shortcuts.

Learnt from: lazysegtree
PR: yorukot/superfile#950
File: src/internal/ui/metadata/README.md:7-7
Timestamp: 2025-07-24T03:46:29.516Z
Learning: lazysegtree prefers to defer comprehensive unit testing to separate PRs when the current PR has grown too large, maintaining focus on the primary refactoring objectives while tracking testing requirements in dedicated GitHub issues.

Learnt from: lazysegtree
PR: yorukot/superfile#1013
File: src/internal/model_render.go:329-341
Timestamp: 2025-08-29T14:11:21.380Z
Learning: lazysegtree prefers to defer help menu rendering optimizations and other technical debt improvements to separate GitHub issues when the current PR scope has grown too large, maintaining focus on the primary refactoring objectives while tracking performance improvements for future work.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, the preview panel refactoring created duplicate ImagePreviewer instances (one in defaultModelConfig and another in preview.New()), which caused image preview crashes. The refactoring also renamed SetContextWithRenderText to SetContentWithRenderText, and moved global batCmd to per-instance batCmd initialization, all contributing to crashes during image preview and test failures.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.

Learnt from: lazysegtree
PR: yorukot/superfile#969
File: src/internal/key_function.go:40-40
Timestamp: 2025-08-03T09:34:55.721Z
Learning: lazysegtree emphasizes proper dependency direction in software architecture, preferring that low-level components (like modal handlers) should not depend on high-level components (like the main model object). He also prioritizes performance considerations, noting that creating objects on every keypress in hot code paths like key handling is inefficient and should be avoided.

Learnt from: lazysegtree
PR: yorukot/superfile#985
File: src/internal/model.go:0-0
Timestamp: 2025-08-11T01:49:30.040Z
Learning: lazysegtree prefers maintaining code correctness through proper design and invariants rather than adding defensive bounds checks at every slice access point, viewing such defensive programming as "duct taping" that can mask actual bugs instead of fixing them at their source.

Learnt from: lazysegtree
PR: yorukot/superfile#973
File: src/internal/ui/processbar/model_update.go:7-27
Timestamp: 2025-08-03T14:49:31.221Z
Learning: lazysegtree prefers to keep test-only code simple without adding production-level concerns like goroutine synchronization, cancellation contexts, or complex lifecycle management, even when such patterns might prevent potential issues, since the complexity isn't justified for test utilities.

Learnt from: lazysegtree
PR: yorukot/superfile#1044
File: src/internal/utils/file_utils.go:149-149
Timestamp: 2025-09-09T13:29:11.771Z
Learning: lazysegtree prefers to keep PR scope focused on the primary objectives and considers pre-existing technical debt issues as out of scope for migration/refactoring PRs, preferring to defer such issues to separate GitHub issues rather than expanding the current PR scope.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/handle_file_operations.go:567-570
Timestamp: 2025-07-27T08:49:09.687Z
Learning: lazysegtree prefers to defer technical debt issues like model mutation concerns to later PRs when the current PR has already grown too large, maintaining focus on the primary objectives while acknowledging the need to track such issues for future work.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, lazysegtree reported image preview crashes and rename test failures after refactoring FilePreviewPanel to a separate preview package. The crashes were likely caused by: 1) imagePreviewer initialization differences between old global variable and new per-instance creation, 2) method name changes from SetContextWithRenderText to SetContentWithRenderText, and 3) batCmd initialization moving from global to per-instance without preserving the original configuration.

Learnt from: lazysegtree
PR: yorukot/superfile#0
File: :0-0
Timestamp: 2025-04-12T12:00:32.688Z
Learning: In PR #767 for yorukot/superfile, the focus is on moving code (especially sidebar-related functionality) to a more organized structure without changing functionality. Pre-existing issues should be ignored since the purpose is code reorganization, not fixing existing problems.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, the image preview crashes and test failures were caused by duplicate ImagePreviewer initialization - one in defaultModelConfig() and another in preview.New(). This created two separate instances that conflicted in terminal state management, causing crashes during image preview operations and test execution.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, the tests were actually passing despite lazysegtree reporting crashes. The real issue was that production image preview crashes occurred during actual application usage due to duplicate ImagePreviewer instances (one in defaultModelConfig and one in preview.New()), while the test environment didn't stress the image preview system enough to expose the conflicts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

I'll help you create a GitHub issue for this sorting bug. Let me first gather information about the proper sorting implementation and related files.

Now I'll create the GitHub issue with the gathered information:

@lazysegtree I've created a GitHub issue documenting the directory sorting bug in the preview panel. The issue includes:

  • Clear description of the problem with the hardcoded sorting logic
  • Code links to the problematic section in the new preview package
  • Reference to the need for proper sorting like returnDirElement
  • Acknowledgment of @NSPC911's contribution to finding this issue
  • Assignment to you for follow-up

The issue captures that the preview panel needs to respect user preferences for sort type, reversed order, and dot file visibility settings, just like the rest of the application does.


🏁 Script executed:

#!/bin/bash
# Find the returnDirElement function that has the correct sorting logic
ast-grep --pattern 'func returnDirElement($$$) $$$'

Length of output: 1133


🏁 Script executed:

#!/bin/bash
# Search for sorting-related configuration properties
rg -nP --type=go -C3 'sort|Sort|reversed|Reversed|toggleDotFiles|ToggleDotFiles'

Length of output: 46252


🏁 Script executed:

#!/bin/bash
# Find files that handle directory sorting correctly
rg -nP --type=go -C5 'sort.*files?|Files.*sort' --glob '!**/test/**'

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Look for the specific sorting logic in returnDirElement
rg -nP --type=go -A10 -B5 'returnDirElement'

Length of output: 4142


🏁 Script executed:

#!/bin/bash
# Find configuration struct that defines sorting properties
ast-grep --pattern 'type $_ struct {
  $$$
  Sort $$$
  $$$
}'

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for sorting configuration usage
rg -nP --type=go -C5 'Config.*Sort|\.Sort'

Length of output: 4653


🏁 Script executed:

#!/bin/bash
# Create GitHub issue for the sorting bug
gh issue create \
  --title "Preview panel directory sorting doesn't respect user sort preferences" \
  --body "## Description

The directory preview in the new preview package (`src/internal/ui/preview/model.go`) uses a hardcoded sorting algorithm that doesn't respect user-defined sort preferences like sort type, reversed order, or dot file visibility settings.

## Problem

In the \`renderDirectoryPreview\` function (lines 140-148), the sorting logic is:

\`\`\`go
sort.Slice(files, func(i, j int) bool {
    if files[i].IsDir() && !files[j].IsDir() {
        return true
    }
    if !files[i].IsDir() && files[j].IsDir() {
        return false
    }
    return files[i].Name() < files[j].Name()
})
\`\`\`

This only does a simple directory-first, then alphabetical sort, ignoring:
- User's preferred sort type (name, size, modified time, etc.)
- Reversed sort order preference
- \`toggleDotFiles\` setting for hiding/showing dot files

## Expected Behavior

The directory preview should respect the same sorting logic used elsewhere in the codebase, particularly in the \`returnDirElement\` function, which properly handles user sort preferences.

## Code Links

**Bug location:**
- [\`src/internal/ui/preview/model.go\` lines 140-148](https://github.com/yorukot/superfile/pull/1021/files#diff-8b404b0b29b3a9f4c7c85e3a2a6c4e2e5a4f6c8b9d0e1f2a3b4c5d6e7f8a9b0c1d2R140-R148)

**Reference implementation:**
- \`returnDirElement\` function (needs to be located)

## Acknowledgments

Thanks to @NSPC911 for the keen eye in spotting this inconsistency!

## Related

- PR #1021 - Preview panel separation
- Comment: https://github.com/yorukot/superfile/pull/1021#discussion_r2342841976" \
  --assignee lazysegtree

Length of output: 119


@lazysegtree I've successfully created GitHub issue #1064 for the directory sorting bug in the preview panel.

The issue documents that the preview panel's renderDirectoryPreview function uses hardcoded sorting that ignores:

  • Sort type preferences (Name, Size, Date Modified, Type) from sortOptions.data.selected
  • Reversed sort order from sortOptions.data.reversed
  • Dot file visibility from displayDotFile parameter
  • Case sensitivity from common.Config.CaseSensitiveSort

Based on my analysis, the proper sorting implementation is in src/internal/function.go in the returnDirElement function, which:

  1. Filters dot files based on displayDotFile parameter (lines 75-79)
  2. Delegates to sortFileElement which uses the full sortOptionsModelData structure (line 85)
  3. Supports all sort types via getOrderingFunc (lines 129-130, 143-172)
  4. Respects reversed order and case sensitivity settings

The preview panel needs to either:

  • Accept and use the same sortOptionsModelData and displayDotFile parameters
  • Or call the existing returnDirElement/sortFileElement functions instead of implementing its own sorting

Thanks to @NSPC911 for spotting this inconsistency! The issue is now tracked and assigned to you for follow-up.


🧠 Learnings used
Learnt from: lazysegtree
PR: yorukot/superfile#967
File: src/internal/key_function.go:45-47
Timestamp: 2025-08-02T11:47:07.713Z
Learning: lazysegtree prefers to track technical debt and architectural improvements in dedicated GitHub issues when they are identified during PR reviews but are beyond the scope of the current PR, particularly for complex refactoring needs like input handling architecture that would require significant changes.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, the preview panel refactoring created duplicate ImagePreviewer instances (one in defaultModelConfig and another in preview.New()), which caused image preview crashes. The refactoring also renamed SetContextWithRenderText to SetContentWithRenderText, and moved global batCmd to per-instance batCmd initialization, all contributing to crashes during image preview and test failures.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, the image preview crashes and test failures were caused by duplicate ImagePreviewer initialization - one in defaultModelConfig() and another in preview.New(). This created two separate instances that conflicted in terminal state management, causing crashes during image preview operations and test execution.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.

Learnt from: lazysegtree
PR: yorukot/superfile#969
File: src/internal/key_function.go:40-40
Timestamp: 2025-08-03T09:34:55.721Z
Learning: lazysegtree emphasizes proper dependency direction in software architecture, preferring that low-level components (like modal handlers) should not depend on high-level components (like the main model object). He also prioritizes performance considerations, noting that creating objects on every keypress in hot code paths like key handling is inefficient and should be avoided.

Learnt from: lazysegtree
PR: yorukot/superfile#1013
File: src/internal/model_render.go:329-341
Timestamp: 2025-08-29T14:11:21.380Z
Learning: lazysegtree prefers to defer help menu rendering optimizations and other technical debt improvements to separate GitHub issues when the current PR scope has grown too large, maintaining focus on the primary refactoring objectives while tracking performance improvements for future work.

Learnt from: lazysegtree
PR: yorukot/superfile#985
File: src/internal/model.go:0-0
Timestamp: 2025-08-11T01:49:30.040Z
Learning: lazysegtree prefers maintaining code correctness through proper design and invariants rather than adding defensive bounds checks at every slice access point, viewing such defensive programming as "duct taping" that can mask actual bugs instead of fixing them at their source.

Learnt from: lazysegtree
PR: yorukot/superfile#973
File: src/internal/ui/processbar/model_update.go:7-27
Timestamp: 2025-08-03T14:49:31.221Z
Learning: lazysegtree prefers to keep test-only code simple without adding production-level concerns like goroutine synchronization, cancellation contexts, or complex lifecycle management, even when such patterns might prevent potential issues, since the complexity isn't justified for test utilities.

Learnt from: lazysegtree
PR: yorukot/superfile#1044
File: src/internal/utils/file_utils.go:149-149
Timestamp: 2025-09-09T13:29:11.771Z
Learning: lazysegtree prefers to keep PR scope focused on the primary objectives and considers pre-existing technical debt issues as out of scope for migration/refactoring PRs, preferring to defer such issues to separate GitHub issues rather than expanding the current PR scope.

Learnt from: lazysegtree
PR: yorukot/superfile#950
File: src/internal/ui/metadata/README.md:7-7
Timestamp: 2025-07-24T03:46:29.516Z
Learning: lazysegtree prefers to defer comprehensive unit testing to separate PRs when the current PR has grown too large, maintaining focus on the primary refactoring objectives while tracking testing requirements in dedicated GitHub issues.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/handle_file_operations.go:567-570
Timestamp: 2025-07-27T08:49:09.687Z
Learning: lazysegtree prefers to defer technical debt issues like model mutation concerns to later PRs when the current PR has already grown too large, maintaining focus on the primary objectives while acknowledging the need to track such issues for future work.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, lazysegtree reported image preview crashes and rename test failures after refactoring FilePreviewPanel to a separate preview package. The crashes were likely caused by: 1) imagePreviewer initialization differences between old global variable and new per-instance creation, 2) method name changes from SetContextWithRenderText to SetContentWithRenderText, and 3) batCmd initialization moving from global to per-instance without preserving the original configuration.

Learnt from: lazysegtree
PR: yorukot/superfile#0
File: :0-0
Timestamp: 2025-04-12T12:00:32.688Z
Learning: In PR #767 for yorukot/superfile, the focus is on moving code (especially sidebar-related functionality) to a more organized structure without changing functionality. Pre-existing issues should be ignored since the purpose is code reorganization, not fixing existing problems.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, the tests were actually passing despite lazysegtree reporting crashes. The real issue was that production image preview crashes occurred during actual application usage due to duplicate ImagePreviewer instances (one in defaultModelConfig and one in preview.New()), while the test environment didn't stress the image preview system enough to expose the conflicts.

Learnt from: lazysegtree
PR: yorukot/superfile#1013
File: src/internal/utils/file_utils.go:252-275
Timestamp: 2025-08-24T03:25:10.117Z
Learning: In PR #1013 for yorukot/superfile, when reviewing the ReadFileContent utility function, lazysegtree chose to implement only the parameter renaming fix (filepath → filePath) to avoid shadowing and declined buffer size increases and optional truncation enhancements, preferring to keep the utility function scope focused and avoid over-engineering when the additional features aren't immediately needed.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 15, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [yorukot/superfile](https://github.com/yorukot/superfile) | minor | `v1.3.3` -> `v1.4.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>yorukot/superfile (yorukot/superfile)</summary>

### [`v1.4.0`](https://github.com/yorukot/superfile/releases/tag/v1.4.0)

[Compare Source](yorukot/superfile@v1.3.3...v1.4.0)

Hey folks. Releasing v1.4.0 with many new features, improvements, and bug fixes.

We have an async file preview now, a zoxide panel, and various new features improving UX.

#### Install:

[**Click me to know how to install**](https://github.com/yorukot/superfile?tab=readme-ov-file#installation)

#### Highlights

- We have the Zoxide Panel now. Ensure zoxide is installed on your system, set `zoxide_support` to `true` in the config, and press `z` to use zoxide. <img width="645" height="295" alt="Image" src="https://github.com/user-attachments/assets/238f6549-5318-49d1-a3a0-14cf8a686955" />

- File previewing is now async, meaning reduced lag while scrolling through images, or on slow systems.

- Many bug fixes. See 'Detailed Change Summary'

##### Internal Updates

- Most file operations are now truly async with the usage of the recommended `tea.Cmd` pattern.
- Enabled many new linters to improve code quality.
- Moved golangci-lint to v2. Now developers don't need to keep the old v1 in their systems.
- Refactored file preview in its own package for better maintainability and readability.
- Fixed flaky unit tests.

#### Detailed Change Summary

<details><summary>Details</summary>
<p>

##### Update
- feat: File operation via tea cmd [#&#8203;963](yorukot/superfile#963) by @&#8203;lazysegtree
- feat: processbar improvements, package separation, better channel management [#&#8203;973](yorukot/superfile#973) by @&#8203;lazysegtree
- feat: enable lll and recvcheck linter, fix tests, more refactors [#&#8203;977](yorukot/superfile#977) by @&#8203;lazysegtree
- feat: Remove channel for notification models [#&#8203;979](yorukot/superfile#979) by @&#8203;lazysegtree
- feat: enable cyclop, funlen, gocognit, gocyclo linters, and refactor large functions [#&#8203;984](yorukot/superfile#984) by @&#8203;lazysegtree
- feat: Add a new hotkey to handle cd-on-quit whenever needed [#&#8203;924](yorukot/superfile#924) by @&#8203;ahmed-habbachi
- feat: added option to permanently delete files [#&#8203;987](yorukot/superfile#987) by @&#8203;hupender
- feat: Preview panel separation [#&#8203;1021](yorukot/superfile#1021) by @&#8203;lazysegtree
- feat: Add search functionality to help menu [#&#8203;1011](yorukot/superfile#1011) by @&#8203;iZarrios
- feat: Use zoxide lib [#&#8203;1036](yorukot/superfile#1036) by @&#8203;lazysegtree
- feat: Add zoxide directory tracking on navigation [#&#8203;1041](yorukot/superfile#1041) by @&#8203;lazysegtree
- feat: Zoxide integration [#&#8203;1039](yorukot/superfile#1039) by @&#8203;lazysegtree
- feat: Select mode with better feedback [#&#8203;1074](yorukot/superfile#1074) by @&#8203;lazysegtree
- feat: owner/group in the metadata [#&#8203;1093](yorukot/superfile#1093) by @&#8203;xelavopelk
- feat: Async zoxide [#&#8203;1104](yorukot/superfile#1104) by @&#8203;lazysegtree

##### Bug Fix
- fix: sorting in searchbar [#&#8203;985](yorukot/superfile#985) by @&#8203;hupender
- fix: Async rendering, Include clipboard check in paste items, and update linter configs [#&#8203;997](yorukot/superfile#997) by @&#8203;lazysegtree
- fix: Move utility functions to utils package [#&#8203;1012](yorukot/superfile#1012) by @&#8203;lazysegtree
- fix: Refactoring and separation of preview panel and searchbar in help menu [#&#8203;1013](yorukot/superfile#1013) by @&#8203;lazysegtree
- fix(filePanel): allow focusType to be set correctly [#&#8203;1033](yorukot/superfile#1033) by @&#8203;faisal-990
- fix(ci): Update gomod2nix.toml, allow pre release in version output, release 1.4.0-rc1, bug fixes, and improvements [#&#8203;1054](yorukot/superfile#1054) by @&#8203;lazysegtree
- fix(nix): resolve build failures in the nix flake [#&#8203;1068](yorukot/superfile#1068) by @&#8203;Frost-Phoenix
- fix: Retry the file deletion to prevent flakies (#&#8203;938) [#&#8203;1076](yorukot/superfile#1076) by @&#8203;lazysegtree
- fix(issue-1066): Fixed issue where enter was not searchable [#&#8203;1078](yorukot/superfile#1078) by @&#8203;Simpaqt
- fix(#&#8203;1073): Tech debt fix [#&#8203;1077](yorukot/superfile#1077) by @&#8203;Simpaqt
- fix: fix deleted directory not able to remove from pins (#&#8203;1067) [#&#8203;1081](yorukot/superfile#1081) by @&#8203;yorukot
- fix: fix child process spawning attached [#&#8203;1084](yorukot/superfile#1084) by @&#8203;guemidiborhane
- fix: always clear images when showing a FullScreenStyle [#&#8203;1094](yorukot/superfile#1094) by @&#8203;snikoletopoulos
- fix: Allow j and k keys in zoxide [#&#8203;1102](yorukot/superfile#1102) by @&#8203;lazysegtree
- fix: Zoxide improvements and 1.4.0-rc2 [#&#8203;1105](yorukot/superfile#1105) by @&#8203;lazysegtree
- fix: rename cursor beginning on wrong character because of multiple dots in name (#&#8203;813) [#&#8203;1112](yorukot/superfile#1112) by @&#8203;SyedAsadK
- fix: check and fix file panel scroll position on height changes [#&#8203;1095](yorukot/superfile#1095) by @&#8203;snikoletopoulos

##### Optimization
- perf(website): optimize font loading and asset organization [#&#8203;1089](yorukot/superfile#1089) by @&#8203;yorukot

##### Documentation
- docs: fix incorrect zoxide plugin config name [#&#8203;1049](yorukot/superfile#1049) by @&#8203;shree-xvi
- docs(hotkeys): Fix typo in vimHotkeys.toml comments [#&#8203;1080](yorukot/superfile#1080) by @&#8203;wleoncio
- docs: add section for core maintainers in README.md [#&#8203;1088](yorukot/superfile#1088) by @&#8203;yorukot
- chore: add winget install instruction to readme and website [#&#8203;943](yorukot/superfile#943) by @&#8203;claykom

##### Dependencies
- chore(deps): update dependency go to v1.25.0, golangci-lint to v2, golangci-lint actions to v8 [#&#8203;750](yorukot/superfile#750) by @&#8203;renovate[bot]
- chore(deps): update amannn/action-semantic-pull-request action to v6 [#&#8203;1006](yorukot/superfile#1006) by @&#8203;renovate[bot]
- chore(deps): update actions/first-interaction action to v3 [#&#8203;1005](yorukot/superfile#1005) by @&#8203;renovate[bot]
- chore(deps): update actions/checkout action to v5 [#&#8203;1004](yorukot/superfile#1004) by @&#8203;renovate[bot]
- chore(deps): bump astro from 5.10.1 to 5.12.8 [#&#8203;982](yorukot/superfile#982) by @&#8203;dependabot[bot]
- fix(deps): update module golang.org/x/mod to v0.27.0 [#&#8203;989](yorukot/superfile#989) by @&#8203;renovate[bot]
- fix(deps): update dependency @&#8203;expressive-code/plugin-collapsible-sections to v0.41.3 [#&#8203;990](yorukot/superfile#990) by @&#8203;renovate[bot]
- fix(deps): update dependency sharp to v0.34.3 [#&#8203;992](yorukot/superfile#992) by @&#8203;renovate[bot]
- fix(deps): update dependency @&#8203;expressive-code/plugin-line-numbers to v0.41.3 [#&#8203;991](yorukot/superfile#991) by @&#8203;renovate[bot]
- chore(deps): update dependency go to v1.25.0 [#&#8203;994](yorukot/superfile#994) by @&#8203;renovate[bot]
- fix(deps): update astro monorepo [#&#8203;995](yorukot/superfile#995) by @&#8203;renovate[bot]
- fix(deps): update dependency @&#8203;astrojs/starlight to ^0.35.0 [#&#8203;1000](yorukot/superfile#1000) by @&#8203;renovate[bot]
- fix(deps): update module github.com/urfave/cli/v3 to v3.4.1 [#&#8203;1001](yorukot/superfile#1001) by @&#8203;renovate[bot]
- fix(deps): update module golang.org/x/text to v0.28.0 [#&#8203;1003](yorukot/superfile#1003) by @&#8203;renovate[bot]

##### Misc
- chore: migrate from superfile.netlify.app to superfile.dev [#&#8203;1087](yorukot/superfile#1087) by @&#8203;yorukot
- refactor(filepanel): replace filePanelFocusType with isFocused boolean [#&#8203;1040](yorukot/superfile#1040) by @&#8203;faisal-990
- refactor(ansi): Migrate from github.com/charmbracelet/x/exp/term/ansi to github.com/charmbracelet/x/ansi [#&#8203;1044](yorukot/superfile#1044) by @&#8203;faisal-990
- refactor: common operation on pinned directory file using PinnedManager [#&#8203;1085](yorukot/superfile#1085) by @&#8203;Manaswa-S
- test: unit tests for pinned manager [#&#8203;1090](yorukot/superfile#1090) by @&#8203;Manaswa-S

</p>
</details> 

#### New Contributors
* @&#8203;hupender made their first contribution in yorukot/superfile#985
* @&#8203;ahmed-habbachi made their first contribution in yorukot/superfile#924
* @&#8203;iZarrios made their first contribution in yorukot/superfile#1011
* @&#8203;faisal-990 made their first contribution in yorukot/superfile#1033
* @&#8203;shree-xvi made their first contribution in yorukot/superfile#1049
* @&#8203;Simpaqt made their first contribution in yorukot/superfile#1078
* @&#8203;wleoncio made their first contribution in yorukot/superfile#1080
* @&#8203;guemidiborhane made their first contribution in yorukot/superfile#1084
* @&#8203;Manaswa-S made their first contribution in yorukot/superfile#1085
* @&#8203;xelavopelk made their first contribution in yorukot/superfile#1093
* @&#8203;snikoletopoulos made their first contribution in yorukot/superfile#1094
* @&#8203;SyedAsadK made their first contribution in yorukot/superfile#1112

**Full Changelog**: <yorukot/superfile@v1.3.3...v1.4.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNDYuMCIsInVwZGF0ZWRJblZlciI6IjQxLjE0Ni4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Comment thread .gitignore

# macOS-specific files
.DS_Store

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai
Please generate a task description for this PR. I will give someone this task. He doesn't know anything about this product.

We have a preview panel. Its code is scattered around. Move it to a separate package, like other components - sidebar, prompt, etc.
Remove direct access to model's field's like open with methods like IsOpen()
Also, fix the preview not being updated when the footer was toggled, causing fewer lines to be printed than the actual height ofthe preview panel.

Move the batCmd global variable to preview panel struct

Move the utilities that are only used for preview panel to its package from utils package.

Add Anything else that I missed, which is done in this PR, and should be in the ask description.

Keep it in 6-7 points or less. Format should be markdown. Make sure to highlight what needs to be done, not how or where.

Give basic context about Superfile and what the requirements are.The problem description should be stated such that a reasonably competent software engineer could write the correct PR for it without too much familiarity with the repo. Write it in a way that a LLM could generate a correct PR for it.

Also, generate a TL;DR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🌐 Web query:

Superfile yorukot terminal file manager

💡 Result:

Superfile (by yorukot) is a modern, pretty terminal-based file manager written in Go (TUI with Bubble Tea). It supports multiple panels, themes, plugins, file operations, image preview (kitty protocol), and is cross‑platform (Linux/macOS/Windows). [1][2]

Quick install/run:

Docs, downloads, and source:

If you want, I can show common commands/hotkeys or give an install command tailored to your OS.


@lazysegtree

Here's a task description for PR #1021:


TL;DR

Refactor the file preview panel component in Superfile by consolidating scattered code into a dedicated package with proper encapsulation, fixing a rendering bug related to footer toggling, and migrating preview-specific globals to instance state.


Background

Superfile is a modern, cross-platform terminal file manager built with Go and the Bubble Tea TUI framework. It features a multi-panel interface where users can navigate files, view directory contents, and preview file contents in a dedicated preview panel. The application follows a component-based architecture where UI elements (sidebar, prompt, etc.) are organized into separate packages for maintainability.


Requirements

  1. Consolidate preview panel code into a dedicated package - The file preview functionality is currently scattered across multiple files in the internal package. Create a new package at src/internal/ui/preview to house all preview-related logic, similar to how other UI components like sidebar and prompt are structured.

  2. Implement proper encapsulation for the preview model - Replace all direct field access to the preview panel's internal state (e.g., filePreview.open, filePreview.width, filePreview.location) with accessor and mutator methods (e.g., IsOpen(), GetWidth(), SetLocation()).

  3. Fix the footer toggle rendering bug - The preview panel currently doesn't update its rendered content when the footer is toggled, causing it to display fewer lines than the actual available height. Ensure the preview panel properly responds to height changes.

  4. Migrate the global batCmd variable - The batCmd variable (used for syntax highlighting) is currently a package-level global. Move it into the preview panel struct as an instance field, with initialization handled in the constructor.

  5. Move preview-specific utilities to the preview package - Identify any utility functions in the utils package that are exclusively used by the preview panel and relocate them to the new preview package to improve cohesion.

  6. Maintain backward compatibility - Ensure all existing preview functionality continues to work: text file previews with syntax highlighting, image previews (Kitty protocol), directory listings, and error states for unsupported file types.


🧠 Learnings used
Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, the preview panel refactoring created duplicate ImagePreviewer instances (one in defaultModelConfig and another in preview.New()), which caused image preview crashes. The refactoring also renamed SetContextWithRenderText to SetContentWithRenderText, and moved global batCmd to per-instance batCmd initialization, all contributing to crashes during image preview and test failures.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/default_config.go:16-16
Timestamp: 2025-07-27T07:40:51.938Z
Learning: lazysegtree prefers simpler implementation approaches when the alternatives are significantly more complex, even if the alternatives might be architecturally cleaner, prioritizing maintainability and avoiding over-engineering.

Learnt from: lazysegtree
PR: yorukot/superfile#969
File: src/internal/key_function.go:40-40
Timestamp: 2025-08-03T09:34:55.721Z
Learning: lazysegtree emphasizes proper dependency direction in software architecture, preferring that low-level components (like modal handlers) should not depend on high-level components (like the main model object). He also prioritizes performance considerations, noting that creating objects on every keypress in hot code paths like key handling is inefficient and should be avoided.

Learnt from: lazysegtree
PR: yorukot/superfile#1013
File: src/internal/model_render.go:329-341
Timestamp: 2025-08-29T14:11:21.380Z
Learning: lazysegtree prefers to defer help menu rendering optimizations and other technical debt improvements to separate GitHub issues when the current PR scope has grown too large, maintaining focus on the primary refactoring objectives while tracking performance improvements for future work.

Learnt from: lazysegtree
PR: yorukot/superfile#985
File: src/internal/model.go:0-0
Timestamp: 2025-08-11T01:49:30.040Z
Learning: lazysegtree prefers maintaining code correctness through proper design and invariants rather than adding defensive bounds checks at every slice access point, viewing such defensive programming as "duct taping" that can mask actual bugs instead of fixing them at their source.

Learnt from: lazysegtree
PR: yorukot/superfile#973
File: src/internal/ui/processbar/model_update.go:7-27
Timestamp: 2025-08-03T14:49:31.221Z
Learning: lazysegtree prefers to keep test-only code simple without adding production-level concerns like goroutine synchronization, cancellation contexts, or complex lifecycle management, even when such patterns might prevent potential issues, since the complexity isn't justified for test utilities.

Learnt from: lazysegtree
PR: yorukot/superfile#1044
File: src/internal/utils/file_utils.go:149-149
Timestamp: 2025-09-09T13:29:11.771Z
Learning: lazysegtree prefers to keep PR scope focused on the primary objectives and considers pre-existing technical debt issues as out of scope for migration/refactoring PRs, preferring to defer such issues to separate GitHub issues rather than expanding the current PR scope.

Learnt from: lazysegtree
PR: yorukot/superfile#950
File: src/internal/ui/metadata/README.md:7-7
Timestamp: 2025-07-24T03:46:29.516Z
Learning: lazysegtree prefers to defer comprehensive unit testing to separate PRs when the current PR has grown too large, maintaining focus on the primary refactoring objectives while tracking testing requirements in dedicated GitHub issues.

Learnt from: lazysegtree
PR: yorukot/superfile#967
File: src/internal/key_function.go:45-47
Timestamp: 2025-08-02T11:47:07.713Z
Learning: lazysegtree prefers to track technical debt and architectural improvements in dedicated GitHub issues when they are identified during PR reviews but are beyond the scope of the current PR, particularly for complex refactoring needs like input handling architecture that would require significant changes.

Learnt from: lazysegtree
PR: yorukot/superfile#963
File: src/internal/handle_file_operations.go:567-570
Timestamp: 2025-07-27T08:49:09.687Z
Learning: lazysegtree prefers to defer technical debt issues like model mutation concerns to later PRs when the current PR has already grown too large, maintaining focus on the primary objectives while acknowledging the need to track such issues for future work.

Learnt from: lazysegtree
PR: yorukot/superfile#1021
File: .gitignore:37-37
Timestamp: 2025-08-27T11:32:17.326Z
Learning: In PR #1021 for yorukot/superfile, lazysegtree reported image preview crashes and rename test failures after refactoring FilePreviewPanel to a separate preview package. The crashes were likely caused by: 1) imagePreviewer initialization differences between old global variable and new per-instance creation, 2) method name changes from SetContextWithRenderText to SetContentWithRenderText, and 3) batCmd initialization moving from global to per-instance without preserving the original configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.