Skip to content

fix(return): improve return behavior when exiting .norg buffers#1765

Open
MarkoPLK wants to merge 1 commit into
nvim-neorg:mainfrom
MarkoPLK:fix/return-alternate-buffer
Open

fix(return): improve return behavior when exiting .norg buffers#1765
MarkoPLK wants to merge 1 commit into
nvim-neorg:mainfrom
MarkoPLK:fix/return-alternate-buffer

Conversation

@MarkoPLK

Copy link
Copy Markdown

This patch improves the behavior of the return command when exiting
.norg buffers.

When multiple .norg buffers are open, the previous implementation
simply returned to the last listed buffer by index.

This change closes all .norg buffers and preferably switches to the
alternate buffer (the last viewed buffer). If no valid alternate buffer
exists, it falls back to the most recent non-.norg buffer, or creates
a new buffer as a last resort.

Changes introduced:

  • Prefer switching to the alternate buffer (#) if it is valid,
    listed, and not a .norg buffer
  • Fallback to the most recent listed non-.norg buffer if alternate
    is unavailable
  • Create a new listed buffer if no suitable target exists
  • Validate all buffer handles before switching or deleting

This change is isolated to the return command logic and does not
modify Neorg core buffer handling mechanisms.

Improve the behavior of the `return` command when exiting `.norg`
buffers.

- Close all open .norg buffers when triggering the return command
- Switch to the alternate buffer if valid and not a .norg
- Fallback to the last open buffer if alternate is unavailable
- Fallback to :enew if no suitable buffer exists
- Ensure all buffer operations are safe by checking buffer validity
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