@@ -11,6 +11,7 @@ function TextInput:init(props, popup_options)
1111 autoresize = false ,
1212 max_lines = nil ,
1313 value = " " ,
14+ placeholder = " " ,
1415 on_change = fn .ignore ,
1516 border_style = " rounded" ,
1617 }, props )
@@ -52,9 +53,39 @@ function TextInput:prop_types()
5253 autoresize = { " boolean" , " nil" },
5354 wrap = { " boolean" , " nil" },
5455 filetype = { " string" , " nil" },
56+ placeholder = { " string" , " table" , " nil" },
5557 }
5658end
5759
60+ function TextInput :_update_placeholder ()
61+ local show = self :get_current_value () == " "
62+ local props = self :get_props ()
63+ local placeholder = props .placeholder
64+ if show and placeholder and placeholder ~= " " then
65+ local virt_text
66+ if type (placeholder ) == " table" then
67+ if type (placeholder [1 ]) == " table" then
68+ -- multiple virt-text chunks
69+ virt_text = placeholder
70+ else
71+ -- single virt-text chunk
72+ virt_text = { placeholder }
73+ end
74+ else
75+ -- string
76+ virt_text = { { placeholder , " Comment" } }
77+ end
78+ self ._private .placeholder_extmark = vim .api .nvim_buf_set_extmark (self .bufnr , self .ns_id , 0 , 0 , {
79+ virt_text = virt_text ,
80+ virt_text_pos = " inline" ,
81+ id = self ._private .placeholder_extmark ,
82+ })
83+ elseif self ._private .placeholder_extmark then
84+ vim .api .nvim_buf_del_extmark (self .bufnr , self .ns_id , self ._private .placeholder_extmark )
85+ self ._private .placeholder_extmark = nil
86+ end
87+ end
88+
5889function TextInput :_attach_change_listener ()
5990 local props = self :get_props ()
6091
@@ -66,6 +97,8 @@ function TextInput:_attach_change_listener()
6697 self :set_current_value (value )
6798 props .on_change (value , self )
6899
100+ self :_update_placeholder ()
101+
69102 if props .autoresize then
70103 self ._private .text_input_signal .size = math.max (# lines , self ._private .text_input_initial_size )
71104 end
184217
185218function TextInput :on_mount ()
186219 self :_attach_change_listener ()
220+ self :_update_placeholder ()
187221end
188222
189223return TextInput
0 commit comments