@@ -1100,41 +1100,41 @@ function M.setup(config)
11001100 if M .chat then
11011101 M .chat :close (state .source .bufnr )
11021102 M .chat :delete ()
1103- end
1104-
1105- M .chat = require (' CopilotChat.ui.chat' )(M .config , function (bufnr )
1106- for name , _ in pairs (M .config .mappings ) do
1107- map_key (name , bufnr )
1108- end
1109-
1110- require (' CopilotChat.completion' ).enable (bufnr , M .config .chat_autocomplete )
1103+ else
1104+ M .chat = require (' CopilotChat.ui.chat' )(M .config , function (bufnr )
1105+ for name , _ in pairs (M .config .mappings ) do
1106+ map_key (name , bufnr )
1107+ end
11111108
1112- vim .api .nvim_create_autocmd ({ ' BufEnter' , ' BufLeave' }, {
1113- buffer = bufnr ,
1114- callback = function (ev )
1115- if ev .event == ' BufEnter' then
1116- update_source ()
1117- end
1109+ require (' CopilotChat.completion' ).enable (bufnr , M .config .chat_autocomplete )
11181110
1119- vim .schedule (function ()
1120- select .highlight (state .source .bufnr , not (M .config .highlight_selection and M .chat :focused ()))
1121- end )
1122- end ,
1123- })
1124-
1125- if M .config .insert_at_end then
1126- vim .api .nvim_create_autocmd ({ ' InsertEnter' }, {
1111+ vim .api .nvim_create_autocmd ({ ' BufEnter' , ' BufLeave' }, {
11271112 buffer = bufnr ,
1128- callback = function ()
1129- vim .cmd (' normal! 0' )
1130- vim .cmd (' normal! G$' )
1131- vim .v .char = ' x'
1113+ callback = function (ev )
1114+ if ev .event == ' BufEnter' then
1115+ update_source ()
1116+ end
1117+
1118+ vim .schedule (function ()
1119+ select .highlight (state .source .bufnr , not (M .config .highlight_selection and M .chat :focused ()))
1120+ end )
11321121 end ,
11331122 })
1134- end
11351123
1136- finish (true )
1137- end )
1124+ if M .config .insert_at_end then
1125+ vim .api .nvim_create_autocmd ({ ' InsertEnter' }, {
1126+ buffer = bufnr ,
1127+ callback = function ()
1128+ vim .cmd (' normal! 0' )
1129+ vim .cmd (' normal! G$' )
1130+ vim .v .char = ' x'
1131+ end ,
1132+ })
1133+ end
1134+
1135+ finish (true )
1136+ end )
1137+ end
11381138
11391139 for name , prompt in pairs (list_prompts ()) do
11401140 if prompt .prompt then
0 commit comments