Skip to content

fix(list): continue lists when enter is pressed on indented continuation lines#103

Merged
YousefHadder merged 1 commit intomainfrom
fix/list-auto-continue
Nov 4, 2025
Merged

fix(list): continue lists when enter is pressed on indented continuation lines#103
YousefHadder merged 1 commit intomainfrom
fix/list-auto-continue

Conversation

@YousefHadder
Copy link
Copy Markdown
Owner

Fix auto-continue on an indented list item.

Copilot AI review requested due to automatic review settings November 4, 2025 02:39
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 support for pressing Enter on list continuation lines to create a new list item, rather than treating them as regular text. Previously, only lines that started with a list marker could trigger list continuation behavior.

  • Added find_parent_list_item() function to search upward for the parent list item when on a continuation line
  • Modified handle_enter() to check for continuation lines when no direct list marker is found
  • Added comprehensive test coverage for Enter behavior on continuation lines across different list types

Reviewed Changes

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

File Description
lua/markdown-plus/list/handlers.lua Added helper function to find parent list items and modified Enter handler to support continuation lines
spec/markdown-plus/list_spec.lua Added test suite for Enter key behavior on continuation lines for unordered, ordered, and checkbox lists
Comments suppressed due to low confidence (2)

lua/markdown-plus/list/handlers.lua:121

  • When list_info is found via find_parent_list_item(), it represents the parent list item, not the current continuation line. Calling is_empty_list_item(current_line, list_info) with a continuation line and parent's list_info will produce incorrect results since current_line doesn't contain a list marker. This should be skipped when on a continuation line.
  if parser.is_empty_list_item(current_line, list_info) then

lua/markdown-plus/list/handlers.lua:131

  • When on a continuation line, marker_end is calculated from the parent's list_info, but col is the cursor position on the continuation line. The condition col > marker_end compares cursor position against the parent item's marker position, which doesn't make sense for a continuation line that has no marker. This logic should differentiate between being on the actual list item vs. a continuation line.
  local marker_end = get_content_start_col(list_info)

  -- Check if cursor is in the middle of content
  if col > marker_end and col < #current_line - 1 then

end

-- Look upward for a list item with matching or less indentation
for i = current_row - 1, math.max(1, current_row - 20), -1 do
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 magic number 20 for the upward search limit is unexplained. Consider extracting this to a named constant (e.g., MAX_PARENT_SEARCH_LINES) or documenting why this specific limit was chosen.

Copilot uses AI. Check for mistakes.

it("splits continuation line content when cursor in middle", function()
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { "- Item", " continuation here" })
vim.api.nvim_win_set_cursor(0, { 2, 14 }) -- After "continuation", before space
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 comment says 'before space' but the string ' continuation here' has 'continuation' ending at position 14, which is actually after 'continuation' and at the space character. The comment should be 'at the space before here' to be accurate.

Suggested change
vim.api.nvim_win_set_cursor(0, { 2, 14 }) -- After "continuation", before space
vim.api.nvim_win_set_cursor(0, { 2, 14 }) -- At the space before "here"

Copilot uses AI. Check for mistakes.
@YousefHadder YousefHadder disabled auto-merge November 4, 2025 02:48
@YousefHadder YousefHadder merged commit 7d0d052 into main Nov 4, 2025
20 checks passed
@YousefHadder YousefHadder deleted the fix/list-auto-continue branch November 4, 2025 02:48
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