Skip to content

fix(bug): custom keymaps and list enter splitting bugs#108

Merged
YousefHadder merged 4 commits intomainfrom
fix-keymap-and-list-enter-bugs
Nov 4, 2025
Merged

fix(bug): custom keymaps and list enter splitting bugs#108
YousefHadder merged 4 commits intomainfrom
fix-keymap-and-list-enter-bugs

Conversation

@YousefHadder
Copy link
Copy Markdown
Owner

Fixes

  • Fixes [BUG] Custom keymaps not work #105 - Custom keymaps now work when keymaps.enabled = false
  • Fixes list enter bug where pressing <CR> before the last character wouldn't split content

Changes

Issue #105 - Custom Keymaps

  • <Plug> mappings are now always created regardless of keymaps.enabled setting
  • Default keymaps are only created when keymaps.enabled = true
  • Users can now disable defaults and create their own custom keymaps

List Enter Bug

  • Fixed condition to split content when cursor is before or at the last character
  • Added special handling for continuation lines to avoid incorrect splitting
  • Continuation lines now properly create new list items at end of line

Testing

  • ✅ All 217 tests pass
  • ✅ Linter passes (0 warnings, 0 errors)
  • ✅ No regressions introduced

Copilot AI review requested due to automatic review settings November 4, 2025 17:23
@YousefHadder YousefHadder changed the title Fix custom keymaps and list enter splitting bugs fix custom keymaps and list enter splitting bugs Nov 4, 2025
@YousefHadder YousefHadder changed the title fix custom keymaps and list enter splitting bugs fix: custom keymaps and list enter splitting bugs Nov 4, 2025
@YousefHadder YousefHadder changed the title fix: custom keymaps and list enter splitting bugs fix(bug): custom keymaps and list enter splitting bugs 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 fixes the keymap setup logic to always create <Plug> mappings regardless of keymaps.enabled configuration, and refines list handling behavior for cursor positioning and continuation lines. It also updates test expectations to reflect the actual Neovim API cursor clamping behavior.

  • Modified keymap helper to create <Plug> mappings unconditionally while only conditionally creating default keybindings
  • Refined list enter handler to differentiate between list item lines and continuation lines for split behavior
  • Updated tests to match actual API cursor clamping behavior

Reviewed Changes

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

File Description
lua/markdown-plus/keymap_helper.lua Removes early return that prevented <Plug> mapping creation; adds condition check for default keymaps
lua/markdown-plus/list/handlers.lua Adds continuation line tracking and distinct split logic for list items vs continuation lines
spec/markdown-plus/format_spec.lua Updates test to verify <Plug> mappings exist even when keymaps are disabled
spec/markdown-plus/list_spec.lua Updates test expectations to reflect API cursor clamping behavior and shorter test strings

Copilot AI review requested due to automatic review settings November 4, 2025 17:48
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 4 out of 4 changed files in this pull request and generated 3 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings November 4, 2025 17:52
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 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +140 to +141
-- Ensure both non-whitespace exists and trimmed content has multiple characters to avoid single-char list items
should_split = content_after:match("%S") ~= nil and #trimmed > 1
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The continuation line splitting logic has two separate pattern matches on content_after which could be combined for efficiency. Consider storing content_after:match('%S') in a variable or restructuring to check #trimmed > 1 only (since trimmed content with >1 char implies non-whitespace exists).

Suggested change
-- Ensure both non-whitespace exists and trimmed content has multiple characters to avoid single-char list items
should_split = content_after:match("%S") ~= nil and #trimmed > 1
-- Only split if trimmed content has multiple characters to avoid single-char list items
should_split = #trimmed > 1

Copilot uses AI. Check for mistakes.
-- Ensure both non-whitespace exists and trimmed content has multiple characters to avoid single-char list items
should_split = content_after:match("%S") ~= nil and #trimmed > 1
else
-- On list item line: split if cursor is after marker and before last char
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The condition col <= #current_line - 1 would benefit from a comment explaining that this prevents splitting at the last character position. The test comment mentions cursor clamping behavior, but this logic isn't documented in the implementation.

Suggested change
-- On list item line: split if cursor is after marker and before last char
-- On list item line: split if cursor is after marker and before last char
-- Prevent splitting at the last character position to avoid creating an empty list item.
-- This matches the cursor clamping behavior described in tests.

Copilot uses AI. Check for mistakes.
@YousefHadder YousefHadder merged commit f3ca2fd into main Nov 4, 2025
20 checks passed
@YousefHadder YousefHadder deleted the fix-keymap-and-list-enter-bugs branch November 4, 2025 17:55
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] Custom keymaps not work

2 participants