@@ -53,22 +53,32 @@ local visual_commands = {
53
53
54
54
M .command_complete = function (_ , line )
55
55
local commands = normal_commands
56
+ -- line is whatever the user has typed on the cmdline. Like :Magenta start-inl
57
+ -- start splitting by whitespace
56
58
local parts = vim .split (vim .trim (line ), " %s+" )
59
+ -- check if runnning command from visual mode
60
+ -- and remove command prefix from parts
57
61
if vim .startswith (" '<,'>Magenta" , parts [1 ]) then
58
62
commands = visual_commands
59
63
table.remove (parts , 1 )
60
64
elseif vim .startswith (" Magenta" , parts [1 ]) then
61
65
table.remove (parts , 1 )
62
66
end
67
+ -- this ensures #parts == 1 if the user has typed :Magenta<SPACE>
68
+ -- and #parts == 2 if the user has typed :Magenta command<SPACE>
63
69
if line :sub (- 1 ) == " " then
64
70
parts [# parts + 1 ] = " "
65
71
end
66
- local prefix , args = table.remove (parts , 1 ) or " " , parts
72
+ -- splits command and args
73
+ -- because of above, #parts >=1 as soon as user has entered<SPACE> after command
74
+ local command , args = table.remove (parts , 1 ) or " " , parts
75
+ -- disable autocompletion if tyiping beyond command
67
76
if # args > 0 then
68
77
return nil
69
78
end
79
+ -- filter commands by types prefix
70
80
return vim .tbl_filter (function (key )
71
- return key :find (prefix , 1 , true ) == 1
81
+ return key :find (command , 1 , true ) == 1
72
82
end , commands )
73
83
end
74
84
0 commit comments