Skip to content

Commit d7dd1c4

Browse files
committed
fix: normal mode transforms
1 parent 1606997 commit d7dd1c4

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

lua/text-transform/replacers.lua

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local D = require("text-transform.utils.debug")
2-
local state = require("text-transform.state")
2+
local S = require("text-transform.state")
33
local t = require("text-transform.transformers")
44

55
local TextTransform = {}
@@ -153,32 +153,32 @@ end
153153
--- This allows to treat all ranges equally and allows to work on each selection without knowing
154154
--- the full information around the selection logic.
155155
function TextTransform.get_visual_selection_details()
156-
if not state.state.positions then
156+
if not S.state.positions.pos then
157157
D.log("get_visual_selection_details", "No positions saved")
158158
return {}
159159
end
160160
D.log(
161161
"get_visual_selection_details",
162162
"Getting visual selection details - mode: %s, is_visual: %s, is_block: %s",
163-
state.state.positions.mode,
164-
state.is_visual_mode(),
165-
state.is_block_visual_mode()
163+
S.state.mode,
164+
S.is_visual_mode(),
165+
S.is_block_visual_mode()
166166
)
167167

168168
-- Get the start and end positions of the selection
169-
local start_pos = state.state.positions.visual_start
170-
local end_pos = state.state.positions.visual_end
169+
local start_pos = S.state.positions.visual_start
170+
local end_pos = S.state.positions.visual_end
171171
local start_line, start_col = start_pos[2], start_pos[3]
172172
local end_line, end_col = end_pos[2], end_pos[3]
173173

174174
-- Check if currently in visual mode; if not, return the cursor position
175175
if
176-
not state.is_visual_mode()
177-
and not state.is_block_visual_mode()
178-
and not state.has_range(start_pos, end_pos)
176+
not S.is_visual_mode()
177+
and not S.is_block_visual_mode()
178+
and not S.has_range(start_pos, end_pos)
179179
then
180-
local pos = state.positions.pos
181-
D.log("get_visual_selection_details", "Returning single cursor position")
180+
D.log("get_visual_selection_details", "Returning single cursor position: " .. vim.inspect(S))
181+
local pos = S.state.positions.pos
182182
return {
183183
{
184184
start_line = pos[2],
@@ -196,7 +196,7 @@ function TextTransform.get_visual_selection_details()
196196
end
197197

198198
-- If it's block visual mode, return table for each row
199-
if state.is_block_visual_mode() or state.has_range(start_pos, end_pos) then
199+
if S.is_block_visual_mode() or S.has_range(start_pos, end_pos) then
200200
local block_selection = {}
201201
for line = start_line, end_line do
202202
if start_col == end_col then

lua/text-transform/state.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ local TextTransform = {
66
state = {
77
-- A table containing cursor position and visual selection details,
88
-- saved using `save_position()` and can be restored using `restore_positions()`
9-
positions = nil,
9+
--@type {buf: number, mode: string, pos: table, visual_start: table, visual_end: table}
10+
positions = {},
1011
},
1112
}
1213

@@ -119,7 +120,7 @@ function TextTransform.restore_positions(positions)
119120
D.log("restore_positions", [[Restored visual mode %s using "%s"]], positions.mode, command)
120121
end
121122

122-
TextTransform.state.positions = nil
123+
TextTransform.state.positions = {}
123124
end
124125

125126
return TextTransform

0 commit comments

Comments
 (0)