fix(list): continue lists when enter is pressed on indented continuation lines#103
fix(list): continue lists when enter is pressed on indented continuation lines#103YousefHadder merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
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_infois found viafind_parent_list_item(), it represents the parent list item, not the current continuation line. Callingis_empty_list_item(current_line, list_info)with a continuation line and parent's list_info will produce incorrect results sincecurrent_linedoesn'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_endis calculated from the parent'slist_info, butcolis the cursor position on the continuation line. The conditioncol > marker_endcompares 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 |
There was a problem hiding this comment.
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.
|
|
||
| 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 |
There was a problem hiding this comment.
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.
| 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" |
Fix auto-continue on an indented list item.