@@ -7,25 +7,27 @@ local M = {}
77function M .pop_modal (selected_text , filetype , callback )
88 if not selected_text or selected_text == " " then
99 vim .notify (" No text provided to modal" , vim .log .levels .ERROR )
10- if callback then callback (nil ) end
10+ if callback then
11+ callback (nil )
12+ end
1113 return
1214 end
1315
14- local selected_lines = vim .split (selected_text , ' \n ' , { plain = true })
16+ local selected_lines = vim .split (selected_text , " \n " , { plain = true })
1517
1618 -- Create a new buffer for the floating window
1719 local buf = vim .api .nvim_create_buf (false , true )
1820 vim .api .nvim_buf_set_lines (buf , 0 , - 1 , false , selected_lines )
1921
2022 -- Set filetype for syntax highlighting if provided
2123 if filetype and filetype ~= " " then
22- vim .api .nvim_buf_set_option (buf , ' filetype' , filetype )
24+ vim .api .nvim_buf_set_option (buf , " filetype" , filetype )
2325 end
2426
2527 -- Make the buffer read-only
26- vim .api .nvim_buf_set_option (buf , ' modifiable' , false )
27- vim .api .nvim_buf_set_option (buf , ' buftype' , ' nofile' )
28- vim .api .nvim_buf_set_option (buf , ' readonly' , true )
28+ vim .api .nvim_buf_set_option (buf , " modifiable" , false )
29+ vim .api .nvim_buf_set_option (buf , " buftype" , " nofile" )
30+ vim .api .nvim_buf_set_option (buf , " readonly" , true )
2931
3032 -- Calculate window size and position
3133 local width = 0
@@ -42,22 +44,22 @@ function M.pop_modal(selected_text, filetype, callback)
4244
4345 -- Create floating window
4446 local win = vim .api .nvim_open_win (buf , true , {
45- relative = ' editor' ,
47+ relative = " editor" ,
4648 row = row ,
4749 col = col ,
4850 width = width ,
4951 height = height ,
50- style = ' minimal' ,
51- border = ' rounded' ,
52- title = ' Select text to highlight (Press Enter to confirm, Esc to cancel) ' ,
53- title_pos = ' center' ,
52+ style = " minimal" ,
53+ border = " rounded" ,
54+ title = " Select text to highlight (Press Enter to confirm, Esc to cancel) " ,
55+ title_pos = " center" ,
5456 focusable = true ,
5557 })
5658
5759 -- Set window options
58- vim .api .nvim_win_set_option (win , ' cursorline' , true )
59- vim .api .nvim_win_set_option (win , ' number' , true )
60- vim .api .nvim_win_set_option (win , ' relativenumber' , false )
60+ vim .api .nvim_win_set_option (win , " cursorline" , true )
61+ vim .api .nvim_win_set_option (win , " number" , true )
62+ vim .api .nvim_win_set_option (win , " relativenumber" , false )
6163
6264 -- Ensure the window has focus
6365 vim .api .nvim_set_current_win (win )
@@ -75,40 +77,40 @@ function M.pop_modal(selected_text, filetype, callback)
7577 end
7678
7779 -- Set up keymaps for the floating window
78- vim .keymap .set ({' n ' , ' v ' }, ' <CR>' , function ()
80+ vim .keymap .set ({ " n " , " v " }, " <CR>" , function ()
7981 -- Get the current mode
8082 local mode = vim .api .nvim_get_mode ().mode
8183
82- if mode == ' v ' or mode == ' V ' or mode == ' \22 ' then -- \22 is Ctrl-V (visual block mode)
84+ if mode == " v " or mode == " V " or mode == " \22 " then -- \22 is Ctrl-V (visual block mode)
8385 -- Visual mode - get the selection range before exiting visual mode
84- local start_pos = vim .fn .getpos (' v ' )
85- local end_pos = vim .fn .getpos (' . ' )
86+ local start_pos = vim .fn .getpos (" v " )
87+ local end_pos = vim .fn .getpos (" . " )
8688
8789 -- Ensure start_pos is before end_pos
8890 if start_pos [2 ] > end_pos [2 ] then
8991 start_pos , end_pos = end_pos , start_pos
9092 end
9193
9294 -- Exit visual mode
93- vim .api .nvim_feedkeys (vim .api .nvim_replace_termcodes (' <Esc>' , true , false , true ), ' n ' , false )
95+ vim .api .nvim_feedkeys (vim .api .nvim_replace_termcodes (" <Esc>" , true , false , true ), " n " , false )
9496
95- close_and_callback ({start_pos [2 ], end_pos [2 ]}) -- Return line numbers
97+ close_and_callback ({ start_pos [2 ], end_pos [2 ] }) -- Return line numbers
9698 else
9799 -- No selection, return the entire buffer range
98100 local line_count = vim .api .nvim_buf_line_count (buf )
99- close_and_callback ({1 , line_count })
101+ close_and_callback ({ 1 , line_count })
100102 end
101103 end , { buffer = buf })
102104
103105 -- Set up keymap to close window with Esc
104- vim .keymap .set ({' n ' , ' v ' }, ' <Esc>' , function ()
105- close_and_callback (nil ) -- User cancelled
106+ vim .keymap .set ({ " n " , " v " }, " <Esc>" , function ()
107+ close_and_callback (nil ) -- User cancelled
106108 end , { buffer = buf })
107109
108110 -- Set up keymap to close window with q
109- vim .keymap .set (' n ' , ' q ' , function ()
110- close_and_callback (nil ) -- User cancelled
111+ vim .keymap .set (" n " , " q " , function ()
112+ close_and_callback (nil ) -- User cancelled
111113 end , { buffer = buf })
112114end
113115
114- return M
116+ return M
0 commit comments