@@ -91,11 +91,7 @@ function M.setup(opts)
9191 end
9292 end
9393
94- vim .api .nvim_create_user_command (
95- ' Bool' ,
96- M .cursor_toggle_boolean ,
97- { desc = ' Invert Boolean Value on Cursor' }
98- )
94+ vim .api .nvim_create_user_command (' Bool' , M .cursor_toggle_boolean , { desc = ' Invert Boolean Value on Cursor' })
9995end
10096
10197--- @return boolean is_boolean
@@ -133,8 +129,20 @@ function M.boolean_under_cursor()
133129end
134130
135131function M .cursor_toggle_boolean ()
132+ local bufnr = vim .api .nvim_get_current_buf ()
136133 local ok , start_col , end_col = M .boolean_under_cursor ()
137- if not (ok and start_col and end_col ) then
134+ if
135+ not (
136+ ok
137+ and start_col
138+ and end_col
139+ and vim .list_contains ({ ' acwrite' , ' ' }, vim .api .nvim_get_option_value (' buftype' , { buf = bufnr }))
140+ )
141+ then
142+ return
143+ end
144+
145+ if vim .list_contains (Config .config .ignore_ft , vim .api .nvim_get_option_value (' filetype' , { buf = bufnr })) then
138146 return
139147 end
140148
@@ -161,8 +169,20 @@ function M.cursor_toggle_boolean()
161169end
162170
163171function M .cursor_set_to_false ()
172+ local bufnr = vim .api .nvim_get_current_buf ()
164173 local ok , start_col , end_col = M .boolean_under_cursor ()
165- if not (ok and start_col and end_col ) then
174+ if
175+ not (
176+ ok
177+ and start_col
178+ and end_col
179+ and vim .list_contains ({ ' acwrite' , ' ' }, vim .api .nvim_get_option_value (' buftype' , { buf = bufnr }))
180+ )
181+ then
182+ return
183+ end
184+
185+ if vim .list_contains (Config .config .ignore_ft , vim .api .nvim_get_option_value (' filetype' , { buf = bufnr })) then
166186 return
167187 end
168188
@@ -176,8 +196,7 @@ function M.cursor_set_to_false()
176196 local pos = vim .api .nvim_win_get_cursor (win )
177197 local before , after = get_boolean_surround (line , start_col , end_col )
178198 if not vim .list_contains ({ ' t' , ' T' }, line :sub (pos [2 ] + 1 , pos [2 ] + 1 )) then
179- pos [2 ] = pos [2 ]
180- + (line :len () > (before .. convert_to_false [current_bool ] .. after ):len () and - 1 or 1 )
199+ pos [2 ] = pos [2 ] + (line :len () > (before .. convert_to_false [current_bool ] .. after ):len () and - 1 or 1 )
181200 end
182201
183202 vim .api .nvim_set_current_line (before .. convert_to_false [line :sub (start_col , end_col )] .. after )
@@ -190,8 +209,20 @@ function M.cursor_set_to_false()
190209end
191210
192211function M .cursor_set_to_true ()
212+ local bufnr = vim .api .nvim_get_current_buf ()
193213 local ok , start_col , end_col = M .boolean_under_cursor ()
194- if not (ok and start_col and end_col ) then
214+ if
215+ not (
216+ ok
217+ and start_col
218+ and end_col
219+ and vim .list_contains ({ ' acwrite' , ' ' }, vim .api .nvim_get_option_value (' buftype' , { buf = bufnr }))
220+ )
221+ then
222+ return
223+ end
224+
225+ if vim .list_contains (Config .config .ignore_ft , vim .api .nvim_get_option_value (' filetype' , { buf = bufnr })) then
195226 return
196227 end
197228
@@ -205,8 +236,7 @@ function M.cursor_set_to_true()
205236 local pos = vim .api .nvim_win_get_cursor (win )
206237 local before , after = get_boolean_surround (line , start_col , end_col )
207238 if not vim .list_contains ({ ' t' , ' T' }, line :sub (pos [2 ] + 1 , pos [2 ] + 1 )) then
208- pos [2 ] = pos [2 ]
209- + (line :len () > (before .. convert_to_true [current_bool ] .. after ):len () and - 1 or 1 )
239+ pos [2 ] = pos [2 ] + (line :len () > (before .. convert_to_true [current_bool ] .. after ):len () and - 1 or 1 )
210240 end
211241
212242 vim .api .nvim_set_current_line (before .. convert_to_true [line :sub (start_col , end_col )] .. after )
@@ -218,7 +248,5 @@ function M.cursor_set_to_true()
218248 end
219249end
220250
221- function M .setup_keymaps () end
222-
223251return M
224252-- vim: set ts=2 sts=2 sw=2 et ai si sta:
0 commit comments