Skip to content

fix(bug): buffer-local keymap recreation and enhanced list content handling#102

Merged
YousefHadder merged 5 commits intomainfrom
fix/general-bug-fixes
Nov 4, 2025
Merged

fix(bug): buffer-local keymap recreation and enhanced list content handling#102
YousefHadder merged 5 commits intomainfrom
fix/general-bug-fixes

Conversation

@YousefHadder
Copy link
Copy Markdown
Owner

@YousefHadder YousefHadder commented Nov 4, 2025

Description

This PR fixes issue #101 where autocompletion breaks after running :MarkdownPreview, and adds enhanced list content handling features.

Changes

🐛 Bug Fix: Keymap Recreation After markdown-preview (#101)

Problem: When markdown-preview was invoked and the user returned to the markdown buffer, the FileType autocmd would fire again but buffer-local keymaps (like <CR>) would not be recreated, breaking autocompletion.

Root Cause: The keymap_helper.lua used vim.fn.hasmapto() which checks globally for mappings. Since the <Plug> mappings were created globally but default keymaps were buffer-local, the check would fail on subsequent FileType events.

Solution: Changed to use vim.fn.maparg() with buffer-local checking to properly detect if a buffer-local mapping exists before attempting to create one.

Files Changed:

  • lua/markdown-plus/keymap_helper.lua: Use maparg() instead of hasmapto() for buffer-local mapping detection

✨ Feature: Enhanced List Content Handling

Added two new behaviors for better list editing experience:

1. <CR> (Enter) - Split Content at Cursor

  • When cursor is in the middle of list content, pressing Enter now splits the content at cursor position
  • Creates a new list item with the remaining content after the cursor
  • Example:
    - This is some| content
    Pressing <CR> becomes:
    - This is some
    - content

2. <A-CR> (Alt+Enter) - Continue Content Without New Bullet

  • Press Alt+Enter to continue list content on the next line without creating a new bullet
  • Content is properly indented to align with the list item content
  • Matches behavior from popular markdown editors (Obsidian, Typora, Notion)
  • Example:
    - This is a longer list item that|
    Pressing <A-CR> becomes:
    - This is a longer list item that
      continues here

Files Changed:

  • lua/markdown-plus/list/handlers.lua: Enhanced handle_enter(), added handle_shift_enter()
  • lua/markdown-plus/list/init.lua: Added new <A-CR> keymap and exported new function
  • README.md: Added examples and updated keymap reference table
  • doc/markdown-plus.txt: Updated documentation and keymap descriptions

Testing

✅ All 168 tests pass
✅ Linting passes with 0 warnings
✅ Formatting compliant with stylua
✅ No breaking changes to existing functionality

Compatibility

The new list behaviors work with:

  • Regular list items (-, *, +)
  • Ordered lists (1., 2., etc.)
  • Letter lists (a., b., etc.)
  • Checkbox lists (- [ ], - [x])
  • Nested/indented lists
  • Parenthesized lists (1), a), etc.)

Fixes

Closes #101
Closes #100

- Fixed keymap_helper.lua to properly check for buffer-local mappings using maparg()
  instead of hasmapto() which was checking globally
- This resolves autocomplete breaking after running :MarkdownPreview
- Enhanced list item <CR> behavior to split content at cursor position
- Added <S-CR> mapping to continue list content on next line without new bullet
- All tests pass (168 successful), linting and formatting compliant
- Document <CR> split content at cursor feature
- Document <A-CR> continue content without new bullet feature
- Update keymap reference table with new <A-CR> binding
- Add examples showing both new behaviors in action
Copilot AI review requested due to automatic review settings November 4, 2025 00:19
@YousefHadder YousefHadder changed the title Fix issue #101: Buffer-local keymap recreation + Enhanced list content handling fix: Buffer-local keymap recreation + Enhanced list content handling Nov 4, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new "Shift+Enter" functionality for continuing list content on the next line without creating a new list item, while also improving the existing Enter key behavior to intelligently split list content at the cursor position.

  • Introduces handle_shift_enter() function that continues list content on a new line without adding a new bullet point
  • Enhances handle_enter() to split list content when cursor is in the middle of a line, creating a new list item with the remaining text
  • Updates keymap registration logic to properly check for existing buffer-local mappings

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
lua/markdown-plus/list/init.lua Adds new keymap for Shift+Enter (<A-CR>) and exports the new handle_shift_enter function
lua/markdown-plus/list/handlers.lua Implements handle_shift_enter() and modifies handle_enter() to support content splitting
lua/markdown-plus/keymap_helper.lua Changes keymap registration to use maparg() instead of hasmapto() for buffer-local mapping detection
doc/markdown-plus.txt Documents the new Shift+Enter functionality and updates Enter key description
README.md Adds usage examples for content splitting and continuation features

@YousefHadder YousefHadder changed the title fix: Buffer-local keymap recreation + Enhanced list content handling fix(bug): Buffer-local keymap recreation + Enhanced list content handling Nov 4, 2025
Copilot AI review requested due to automatic review settings November 4, 2025 00:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

@YousefHadder YousefHadder changed the title fix(bug): Buffer-local keymap recreation + Enhanced list content handling fix(bug): Buffer-local keymap recreation and Enhanced list content handling Nov 4, 2025
@YousefHadder YousefHadder changed the title fix(bug): Buffer-local keymap recreation and Enhanced list content handling fix(bug): buffer-local keymap recreation and enhanced list content handling Nov 4, 2025
- Fix off-by-one error in content split condition (col < #line - 1)
- Simplify buffer-local mapping check (remove unnecessary table comparison)
- Update comment to show variable checkbox states in examples
- All tests pass, no regressions
@YousefHadder YousefHadder merged commit 9799f35 into main Nov 4, 2025
14 checks passed
@YousefHadder YousefHadder deleted the fix/general-bug-fixes branch November 4, 2025 02:20
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.

[BUG] Markdown-plus breaks Autocompletion after running markdown-preview Can <cr> in insert mode be smarter?

2 participants