11local util = require " easycomplete.util"
2- local log = util .log
32local console = util .console
43local normal_chars = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST0123456789#$_"
54-- cmdline_start_cmdpos 是不带偏移量的,偏移量只给 pum 定位用
65local cmdline_start_cmdpos = 0
76local zizz_flag = 0
87local zizz_timer = vim .loop .new_timer ()
9- local this = {}
108local completeopt = vim .o .completeopt
9+ local this = {}
1110
1211function this .pum_complete (start_col , menu_items )
1312 vim .opt .completeopt :append (" noselect" )
@@ -164,13 +163,22 @@ function this.cmdline_handler(keys, key_str)
164163 this .pum_close ()
165164 elseif string.byte (key_str ) == 8 or string.byte (key_str ) == 128 then
166165 -- console("退格键被按下")
167- this .pum_close ()
166+ this .do_complete ()
168167 elseif string.byte (key_str ) == 13 then
169168 -- console("回车键被按下")
170169 this .pum_close ()
171170 else
172171 -- console("其他键被按下: " .. keys)
173- local word = this .get_typing_word ()
172+ this .do_complete ()
173+ end
174+ vim .cmd (" redraw" )
175+ end
176+
177+ function this .do_complete ()
178+ local word = this .get_typing_word ()
179+ if word == " " then
180+ this .pum_close ()
181+ else
174182 local start_col = vim .fn .getcmdpos () - this .calculate_sign_and_linenr_width () - # word
175183 cmdline_start_cmdpos = vim .fn .getcmdpos () - # word
176184 local menu_items = this .get_cmp_items ()
@@ -180,7 +188,6 @@ function this.cmdline_handler(keys, key_str)
180188 this .pum_complete (start_col , this .normalize_list (menu_items , word ))
181189 end
182190 end
183- vim .cmd (" redraw" )
184191end
185192
186193function this .get_all_commands ()
196203
197204-- 路由
198205function this .get_cmp_items ()
199- if this .typing_cmd () then
206+ if this .typing : cmd () then
200207 return this .get_all_commands ()
208+ elseif this .typing :path () then
209+ return {}
210+ elseif this .typing :buffer () then
211+ return {}
212+ elseif this .typing :fun () then
213+ return {}
214+ else
215+ return {}
201216 end
202217end
203218
@@ -206,16 +221,27 @@ function this.trim_before(str)
206221 return string.gsub (str , " ^%s*(.-)$" , " %1" )
207222end
208223
209- -- 正在输入命令
210- function this .typing_cmd ()
211- local cmdline_all = vim .fn .getcmdline ()
212- local cmdline_typed = this .trim_before (string.sub (cmdline_all , 1 , vim .fn .getcmdpos ()))
213- if string.find (cmdline_typed , " %s" ) then
214- return false
215- else
216- return true
224+ this .typing = {
225+ -- 正在输入命令
226+ cmd = function ()
227+ local cmdline_all = vim .fn .getcmdline ()
228+ local cmdline_typed = this .trim_before (string.sub (cmdline_all , 1 , vim .fn .getcmdpos ()))
229+ if string.find (cmdline_typed , " %s" ) then
230+ return false
231+ else
232+ return true
233+ end
234+ end ,
235+ -- 正在输入路径
236+ path = function ()
237+ end ,
238+ -- 正在输入buf
239+ buffer = function ()
240+ end ,
241+ -- 正在输入函数
242+ fun = function ()
217243 end
218- end
244+ }
219245
220246-- 正在输入buffer
221247-- 正在输入路径
@@ -365,16 +391,14 @@ this.commands_type = {
365391 user = ' user' ,
366392}
367393
368-
369394function this .init_once ()
370395 -- TODO here -----------------------------
371- if true then return end
396+ do return end
372397 console (1 )
373398 -- TODO here -----------------------------
374399 vim .g .easycomplete_cmdline_pattern = " "
375400 vim .g .easycomplete_cmdline_typing = 0
376401 this .bind_cmdline_event ()
377402end
378403
379-
380404return this
0 commit comments