Skip to content

Commit 2a16266

Browse files
committed
fix: address remaining PR review comments
Complete all remaining review feedback: 1. Restore handle_shift_tab() fallback behavior - Now handles non-list lines by removing indentation - Matches original implementation behavior - Provides consistent behavior for users 2. Fix handle_backspace() line deletion bug - Use atomic nvim_buf_set_lines() to avoid line number shifts - Prevents race condition when joining lines 3. Enhanced API documentation - Added detailed docstrings for get_next_marker() - Added detailed docstrings for get_previous_marker() - Clarified behavior for different list types - Improved parameter and return value descriptions 4. Clarified is_list_breaking_line() comment - Added comment explaining non-list content (headers, paragraphs) - Makes logic more explicit All 169 tests passing. No lint errors.
1 parent 9aa9c0c commit 2a16266

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

lua/markdown-plus/list/handlers.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ function M.handle_shift_tab()
112112
local list_info = parser.parse_list_line(current_line)
113113

114114
if not list_info then
115+
-- Not a list line: remove up to shiftwidth spaces from start
116+
local cursor = utils.get_cursor()
117+
local row, col = cursor[1], cursor[2]
118+
local indent_size = vim.bo.shiftwidth or 2
119+
local leading = current_line:match("^(%s*)")
120+
local to_remove = math.min(#leading, indent_size)
121+
if to_remove > 0 then
122+
local new_line = current_line:sub(to_remove + 1)
123+
utils.set_line(row, new_line)
124+
local new_col = math.max(0, col - to_remove)
125+
utils.set_cursor(row, new_col)
126+
end
115127
return
116128
end
117129

@@ -155,8 +167,7 @@ function M.handle_backspace()
155167
-- At start of line, join with previous line
156168
local prev_line = utils.get_line(row - 1)
157169
local joined_line = prev_line .. current_line
158-
utils.set_line(row - 1, joined_line)
159-
vim.api.nvim_buf_set_lines(0, row - 1, row, false, {})
170+
vim.api.nvim_buf_set_lines(0, row - 2, row, false, { joined_line })
160171
utils.set_cursor(row - 1, #prev_line)
161172
end
162173
return

lua/markdown-plus/list/parser.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ function M.next_letter(letter, is_upper)
158158
end
159159
end
160160

161-
---Get the next marker for a list item
162-
---@param list_info table List information
163-
---@return string Next marker
161+
---Get the next marker for a list item, incrementing numbers or letters as appropriate
162+
---For ordered lists: "1." -> "2.", for letters: "a." -> "b."
163+
---For unordered lists: returns same marker ("-", "+", "*")
164+
---@param list_info table Table containing list item information (type, marker, etc.)
165+
---@return string next_marker The next marker string for the list item (e.g., "2.", "b)", "-")
164166
function M.get_next_marker(list_info)
165167
if list_info.type == "ordered" then
166168
local current_num = tonumber(list_info.marker:match("(%d+)"))
@@ -187,9 +189,11 @@ function M.get_next_marker(list_info)
187189
end
188190

189191
---Get the previous/initial marker for inserting before current item
190-
---@param list_info table Current list information
191-
---@param row number Current row number
192-
---@return string Previous marker
192+
---Checks if there's a previous list item at same indent and returns incremented marker,
193+
---otherwise returns initial marker ("1.", "a.", etc.)
194+
---@param list_info table Current list information (type, marker, indent, etc.)
195+
---@param row number Current row number (1-indexed)
196+
---@return string previous_marker The marker to use for item inserted above (e.g., "1.", "a)", "-")
193197
function M.get_previous_marker(list_info, row)
194198
local is_ordered = list_info.type == "ordered" or list_info.type == "ordered_paren"
195199
local is_letter_lower = list_info.type == "letter_lower" or list_info.type == "letter_lower_paren"

lua/markdown-plus/list/renumber.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function M.is_list_breaking_line(line)
2929
if parser.parse_list_line(line) then
3030
return false
3131
end
32+
33+
-- Any non-list content (headers, paragraphs, etc.) breaks list continuity
3234
return true
3335
end
3436

0 commit comments

Comments
 (0)