Skip to content

Commit 213f20d

Browse files
committed
refactor: simplify line motion detection logic in operator
1 parent 2d1a471 commit 213f20d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lua/sort/operator.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,14 @@ M.sort_operator = function(motion_type, from_visual)
286286
-- still represent a logical line selection.
287287
local spans_many_lines = (end_pos[1] - start_pos[1]) >= 2
288288

289-
if starts_at_line_beginning and ends_at_line_end then
290-
-- This is a "perfect lines" selection - convert to line motion.
291-
effective_motion_type = 'line'
292-
elseif spans_many_lines and (starts_at_line_beginning or ends_at_line_end) then
293-
-- For multi-line text objects that look like they cover mostly complete lines,
294-
-- treat as line motion to avoid corruption from partial line handling.
289+
-- Treat as line motion if:
290+
-- 1. "Perfect lines" selection (starts at beginning, ends at line end)
291+
-- 2. Multi-line text objects that cover mostly complete lines
292+
local is_perfect_lines = starts_at_line_beginning and ends_at_line_end
293+
local is_multiline_block = spans_many_lines
294+
and (starts_at_line_beginning or ends_at_line_end)
295+
296+
if is_perfect_lines or is_multiline_block then
295297
effective_motion_type = 'line'
296298
end
297299
end

0 commit comments

Comments
 (0)