|
104 | 104 | :forceBalance (true? (get-option :force_balance))} |
105 | 105 | response ((. modes (get-option :mode)) text request)] |
106 | 106 | (log "request" request) |
107 | | - (tset state bufnr :changes nil) |
| 107 | + (tset state bufnr :changes []) |
108 | 108 | response)) |
109 | 109 |
|
110 | 110 | (fn update-buffer [bufnr lines] |
|
163 | 163 | (fn slice [lines start-row start-col end-row end-col] |
164 | 164 | (let [start-row (+ start-row 1) |
165 | 165 | start-col (+ start-col 1) |
166 | | - end-row (+ end-row 1) |
167 | | - end-col (+ end-col 1) |
168 | | - first-line (string.sub (. lines start-row) start-col (if (= start-row end-row) (- end-col 1) -1)) |
| 166 | + first-line (string.sub (. lines start-row) start-col (if (= 0 end-row) (- (+ start-col end-col) 1) -1)) |
169 | 167 | out [first-line]] |
170 | | - (for [i (+ start-row 1) (- end-row 1)] |
| 168 | + (for [i (+ start-row 1) (- (+ start-row end-row) 1)] |
171 | 169 | (let [line (. lines i)] |
172 | 170 | (table.insert out line))) |
173 | | - (when (and (not= start-row end-row) (< 1 end-col) (. lines end-row)) |
174 | | - (table.insert out (string.sub (. lines end-row) 1 (- end-col 1)))) |
| 171 | + (when (not= 0 end-row) |
| 172 | + (table.insert out (if (and (< 0 end-col) (. lines (+ start-row end-row))) |
| 173 | + (string.sub (. lines (+ start-row end-row)) 1 end-col) |
| 174 | + ""))) |
175 | 175 | out)) |
176 | 176 |
|
177 | 177 | (fn on-bytes [_ bufnr _ start-row start-col _ old-end-row old-end-col _ new-end-row new-end-col] |
|
182 | 182 | ; "changes" |
183 | 183 | (when (< start-row (length prev-contents)) |
184 | 184 | (let [contents (vim.api.nvim_buf_get_lines bufnr 0 -1 true) |
185 | | - old-end-row (+ start-row old-end-row) |
186 | | - new-end-row (+ start-row new-end-row) |
187 | | - old-end-col (+ start-col old-end-col) |
188 | | - new-end-col (+ start-col new-end-col) |
189 | 185 | old-text (slice prev-contents start-row start-col old-end-row old-end-col) |
190 | 186 | new-text (if (< start-row (length contents)) |
191 | 187 | (slice contents start-row start-col new-end-row new-end-col) |
|
195 | 191 | ; empty string |
196 | 192 | [""])] |
197 | 193 | (tset state bufnr :prev-contents contents) |
198 | | - (tset state bufnr :changes [{:oldText (table.concat old-text "\n") |
199 | | - :newText (table.concat new-text "\n") |
200 | | - :lineNo (+ start-row 1) |
201 | | - :x (+ start-col 1)}])))))) |
| 194 | + (when (not (. state bufnr :changes)) |
| 195 | + (tset state bufnr :changes [])) |
| 196 | + (table.insert (. state bufnr :changes) {:oldText (table.concat old-text "\n") |
| 197 | + :newText (table.concat new-text "\n") |
| 198 | + :lineNo (+ start-row 1) |
| 199 | + :x (+ start-col 1)})))))) |
202 | 200 |
|
203 | 201 | (fn enter-buffer [] |
204 | 202 | (let [bufnr (vim.api.nvim_get_current_buf) |
|
0 commit comments