1
- local log = require (' magenta.log' )
1
+ local log = require (' magenta.log' ). log
2
2
3
3
local M = {}
4
4
@@ -92,17 +92,22 @@ function M.setup(opts)
92
92
-- end, {})
93
93
end
94
94
95
- -- Function to append text to the main area
96
- --- @param text string Text to append
97
- local function append_to_main (text )
95
+ --- @param opts { text : string , scrolltop : boolean ?} Options for appending text
96
+ local function append_to_main (opts )
98
97
if not main_area or not main_area .bufnr then
99
98
log .error (" Cannot append to main area - not initialized" )
100
99
return
101
100
end
102
101
103
- local lines = vim .split (text , ' \n ' , {})
102
+ local lines = vim .split (opts . text , ' \n ' , {})
104
103
if # lines == 0 then return end
105
104
105
+ local top_line = vim .api .nvim_buf_line_count (main_area .bufnr ) + 1 ;
106
+
107
+ if opts .scrolltop then
108
+ require (' magenta.util.scroll_buffer' ).scroll_buffer (main_area .bufnr , top_line )
109
+ end
110
+
106
111
local last_line = vim .api .nvim_buf_get_lines (main_area .bufnr , - 2 , - 1 , false )[1 ] or " "
107
112
108
113
vim .api .nvim_buf_set_option (main_area .bufnr , ' modifiable' , true )
@@ -137,7 +142,7 @@ function M.send_message()
137
142
vim .api .nvim_buf_set_lines (input_area .bufnr , 0 , - 1 , false , { " " })
138
143
139
144
-- Add user message to main area
140
- append_to_main ( " \n User: " .. message .. " \n\n Assistant: " )
145
+ append_to_main { text = " \n User: " .. message .. " \n\n Assistant: " , scrolltop = true }
141
146
142
147
-- Send to Anthropic with streaming
143
148
anthropic_client :request ({
@@ -147,12 +152,12 @@ function M.send_message()
147
152
callback = function (err , text )
148
153
if err then
149
154
log .error (" Anthropic API error:" , err )
150
- append_to_main ( " \n Error: " .. err .. " \n " )
155
+ append_to_main { text = " \n Error: " .. err .. " \n " }
151
156
return
152
157
end
153
158
154
159
log .debug (" Received stream text:" , text )
155
- append_to_main (text )
160
+ append_to_main ({ text = text } )
156
161
end ,
157
162
done = function ()
158
163
log .debug (" Request completed" )
@@ -181,8 +186,9 @@ function M.show_sidebar()
181
186
relative = " editor" ,
182
187
size = M .config .sidebar_width ,
183
188
win_options = {
184
- wrap = true , -- Changed to true for better text display
189
+ wrap = true ,
185
190
number = false ,
191
+ relativenumber = false ,
186
192
cursorline = true ,
187
193
},
188
194
})
@@ -193,6 +199,7 @@ function M.show_sidebar()
193
199
win_options = {
194
200
wrap = true ,
195
201
number = false ,
202
+ relativenumber = false ,
196
203
},
197
204
})
198
205
0 commit comments