Skip to content

enhance(mapping): reposition cursor on fern-action-remove - #555

Merged
lambdalisue merged 1 commit into
lambdalisue:mainfrom
brandon1024:reposition-cursor-on-remove
Sep 5, 2026
Merged

lambdalisue merged 1 commit into
lambdalisue:mainfrom
brandon1024:reposition-cursor-on-remove

Conversation

@brandon1024

@brandon1024 brandon1024 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

When removing files or directories with the 'fern-action-remove' mapping, attempt to restore the cursor position.

When working in a large project with a lot of files and deeply nested directories, removing a file reloads and redraws the complete tree, which often positions the cursor on the parent node. This is a bit clunky--the user needs to keep jumping through the drawer to get back to where they were, or alternatively use marks to select+remove.

This revision attempts to reposition the cursor to where it was before the removal.

Summary by CodeRabbit

  • Bug Fixes
    • Preserved the cursor position after asynchronously deleting a file and refreshing the file tree.

When removing files or directories with the 'fern-action-remove'
mapping, attempt to restore the cursor position.

When working in a large project with a lot of files and deeply nested
directories, removing a file reloads and redraws the complete tree,
which often positions the cursor on the parent node. This is a bit
clunky--the user needs to keep jumping through the drawer to get back to
where they were, or alternatively use marks to select+remove.

This revision attempts to reposition the cursor to where it was before
the removal.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 1aa5aae8-b29e-4f79-b884-f109e7093e9a

📥 Commits

Reviewing files that changed from the base of the PR and between 3bbca3c and 5bd8b43.

📒 Files selected for processing (1)
  • autoload/fern/scheme/file/mapping.vim

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The file-removal mapping now saves the cursor before asynchronous cleanup and restores it after the tree reloads and redraws.

Changes

File Removal

Layer / File(s) Summary
Preserve cursor after removal
autoload/fern/scheme/file/mapping.vim
map_remove saves the cursor before removal and restores it after buffer deletion, node collapsing, reload, and redraw.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Merge Risk: ⚪ Minimal · up to 5bd8b

This localized change restores the cursor position after removing a file or directory. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: repositioning the cursor after fern-action-remove.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@brandon1024

Copy link
Copy Markdown
Contributor Author

A bit of an annoying side effect of this change is that the cursor briefly jumps to the parent node, then back to the original cursor position. This is hardly noticeable, but still there. This is because the mapping calls collapse_modified_nodes(nodes) and reload_node(root.__key), which both do a save_cursor() and restore_cursor() in update_nodes.

I'm not too sure how best to solve this. Open for suggestions 👍

@lambdalisue lambdalisue left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

lgtm

@lambdalisue
lambdalisue merged commit fd03997 into lambdalisue:main Sep 5, 2026
13 checks passed
@brandon1024
brandon1024 deleted the reposition-cursor-on-remove branch September 5, 2026 06:40
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.

2 participants