@@ -16,6 +16,23 @@ local center_block_config = require("typewriter.utils.center_block_config")
16
16
local M = {}
17
17
local typewriter_active = false
18
18
19
+ --- Helper function to determine if a node is a significant block
20
+ local function is_significant_block (node )
21
+ local node_type = node :type ()
22
+ return center_block_config .expand [node_type ] == true
23
+ end
24
+
25
+ --- Helper function to get the root of the expandable block
26
+ local function get_expand_root (node )
27
+ while node do
28
+ if is_significant_block (node ) then
29
+ return node
30
+ end
31
+ node = node :parent ()
32
+ end
33
+ return nil
34
+ end
35
+
19
36
--- Center the cursor on the screen
20
37
---
21
38
--- This function moves the view so that the cursor is centered vertically
@@ -76,30 +93,14 @@ function M.toggle_typewriter_mode()
76
93
M .enable_typewriter_mode ()
77
94
end
78
95
end
96
+
79
97
--- Center the current code block and cursor
80
98
---
81
99
--- This function centers both the current code block and the cursor on the screen.
82
100
--- It's useful for focusing on a specific block of code.
83
101
---
84
102
--- @usage require("typewriter.commands").center_block_and_cursor()
85
103
function M .center_block_and_cursor ()
86
- -- Helper function to determine if a node is a significant block
87
- local function is_significant_block (node )
88
- local node_type = node :type ()
89
- return center_block_config .expand [node_type ] == true
90
- end
91
-
92
- -- Helper function to get the root of the expandable block
93
- local function get_expand_root (node )
94
- while node do
95
- if is_significant_block (node ) then
96
- return node
97
- end
98
- node = node :parent ()
99
- end
100
- return nil
101
- end
102
-
103
104
local node = ts_utils .get_node_at_cursor ()
104
105
if not node then
105
106
return
131
132
---
132
133
--- @usage require("typewriter.commands").move_to_top_of_block()
133
134
function M .move_to_top_of_block ()
134
- -- Helper functions (is_significant_block and get_expand_root) are the same as in center_block_and_cursor
135
-
136
135
local node = ts_utils .get_node_at_cursor ()
137
136
if not node then
138
137
return
171
170
---
172
171
--- @usage require("typewriter.commands").move_to_bottom_of_block()
173
172
function M .move_to_bottom_of_block ()
174
- -- Helper functions (is_significant_block and get_expand_root) are the same as in center_block_and_cursor
175
-
176
173
local node = ts_utils .get_node_at_cursor ()
177
174
if not node then
178
175
return
0 commit comments