Skip to content

Commit 062ace3

Browse files
Merge pull request #11 from joshuadanpeterson/dev
Fix for 'attempt to call global 'get_expand_root' (a nil value)' Error
2 parents 8556d63 + af06296 commit 062ace3

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Changelog
22

3+
## [v0.4.22](https://github.com/joshuadanpeterson/typewriter.nvim/tree/v0.4.22) (2024-07-19)
4+
- fix(commands): Move helper functions outside specific functions to avoid nil error
5+
- docs: update CHANGELOG.md for v0.4.21 and remove duplicate entries
6+
7+
[Full Changelog](https://github.com/joshuadanpeterson/typewriter.nvim/compare/v0.4.21...v0.4.22)
8+
39
## [v0.4.21](https://github.com/joshuadanpeterson/typewriter.nvim/tree/v0.4.21) (2024-07-18)
410
- Merge pull request #10 from joshuadanpeterson/dev
511
- docs: update CHANGELOG.md for v0.4.20 and remove duplicate entries
612

7-
[Full Changelog](https://github.com/joshuadanpeterson/typewriter.nvim/compare/v0.4.20...v0.4.21)
13+
[Full Changelog](https://github.com/joshuadanpeterson/typewriter.nvim/compare/v0.4.22...v0.4.21)
814

915
## [v0.4.20](https://github.com/joshuadanpeterson/typewriter.nvim/tree/v0.4.20) (2024-07-18)
1016
- Merge branch dev of https://github.com/joshuadanpeterson/typewriter.nvim into dev

lua/typewriter/commands.lua

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ local center_block_config = require("typewriter.utils.center_block_config")
1616
local M = {}
1717
local typewriter_active = false
1818

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+
1936
--- Center the cursor on the screen
2037
---
2138
--- This function moves the view so that the cursor is centered vertically
@@ -76,30 +93,14 @@ function M.toggle_typewriter_mode()
7693
M.enable_typewriter_mode()
7794
end
7895
end
96+
7997
--- Center the current code block and cursor
8098
---
8199
--- This function centers both the current code block and the cursor on the screen.
82100
--- It's useful for focusing on a specific block of code.
83101
---
84102
--- @usage require("typewriter.commands").center_block_and_cursor()
85103
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-
103104
local node = ts_utils.get_node_at_cursor()
104105
if not node then
105106
return
@@ -131,8 +132,6 @@ end
131132
---
132133
--- @usage require("typewriter.commands").move_to_top_of_block()
133134
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-
136135
local node = ts_utils.get_node_at_cursor()
137136
if not node then
138137
return
@@ -171,8 +170,6 @@ end
171170
---
172171
--- @usage require("typewriter.commands").move_to_bottom_of_block()
173172
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-
176173
local node = ts_utils.get_node_at_cursor()
177174
if not node then
178175
return

0 commit comments

Comments
 (0)