@@ -65,8 +65,8 @@ function M.handle_enter()
6565
6666 if not list_info then
6767 -- Not in a list at all, simulate default Enter behavior
68- local line_before = current_line : sub ( 1 , col )
69- local line_after = current_line : sub ( col + 1 )
68+ -- Use UTF-8 safe split to handle multibyte characters correctly
69+ local line_before , line_after = utils . split_at_cursor ( current_line , col )
7070
7171 utils .set_line (row , line_before )
7272 utils .insert_line (row + 1 , line_after )
@@ -102,8 +102,8 @@ function M.handle_enter()
102102
103103 if should_split then
104104 -- Split content at cursor position
105- local content_before = current_line : sub ( 1 , col )
106- local content_after = current_line : sub ( col + 1 )
105+ -- Use UTF-8 safe split to handle multibyte characters correctly
106+ local content_before , content_after = utils . split_at_cursor ( current_line , col )
107107
108108 -- Update current line with content before cursor
109109 utils .set_line (row , content_before )
@@ -142,8 +142,8 @@ function M.continue_list_content()
142142
143143 if not list_info then
144144 -- Not in a list, simulate default Enter behavior
145- local line_before = current_line : sub ( 1 , col )
146- local line_after = current_line : sub ( col + 1 )
145+ -- Use UTF-8 safe split to handle multibyte characters correctly
146+ local line_before , line_after = utils . split_at_cursor ( current_line , col )
147147
148148 utils .set_line (row , line_before )
149149 utils .insert_line (row + 1 , line_after )
@@ -155,8 +155,8 @@ function M.continue_list_content()
155155 local marker_end = shared .get_content_start_col (list_info )
156156
157157 -- Split line at cursor
158- local line_before = current_line : sub ( 1 , col )
159- local line_after = current_line : sub ( col + 1 )
158+ -- Use UTF-8 safe split to handle multibyte characters correctly
159+ local line_before , line_after = utils . split_at_cursor ( current_line , col )
160160
161161 -- Update current line
162162 utils .set_line (row , line_before )
@@ -179,9 +179,11 @@ function M.handle_tab()
179179 local cursor = utils .get_cursor ()
180180 local row , col = cursor [1 ], cursor [2 ]
181181 local indent = string.rep (" " , vim .bo .shiftwidth or 2 )
182- local new_line = current_line :sub (1 , col ) .. indent .. current_line :sub (col + 1 )
182+ -- Use UTF-8 safe split to handle multibyte characters correctly
183+ local before , after = utils .split_after_cursor (current_line , col )
184+ local new_line = before .. indent .. after
183185 utils .set_line (row , new_line )
184- utils .set_cursor (row , col + # indent )
186+ utils .set_cursor (row , # before + # indent )
185187 return
186188 end
187189
0 commit comments