comparison src/sign.c @ 16978:15bc5a64bd50 v8.1.1489

patch 8.1.1489: sign order wrong when priority was changed commit https://github.com/vim/vim/commit/64416127fc184b5544530afe818722679158f059 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 7 21:37:13 2019 +0200 patch 8.1.1489: sign order wrong when priority was changed Problem: Sign order wrong when priority was changed. Solution: Reorder signs when priority is changed. (Yegappan Lakshmanan, closes #4502)
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Jun 2019 21:45:05 +0200
parents 1689b52cf297
children 811c5c2f5236
comparison
equal deleted inserted replaced
16977:9d3ff8fd2018 16978:15bc5a64bd50
306 306
307 return d; 307 return d;
308 } 308 }
309 309
310 /* 310 /*
311 * Sort the signs placed on the same line as "sign" by priority. Invoked after
312 * changing the priority of an already placed sign. Assumes the signs in the
313 * buffer are sorted by line number and priority.
314 */
315 static void
316 sign_sort_by_prio_on_line(buf_T *buf, signlist_T *sign)
317 {
318 signlist_T *p = NULL;
319
320 // If there is only one sign in the buffer or only one sign on the line or
321 // the sign is already sorted by priority, then return.
322 if ((sign->prev == NULL
323 || sign->prev->lnum != sign->lnum
324 || sign->prev->priority > sign->priority)
325 && (sign->next == NULL
326 || sign->next->lnum != sign->lnum
327 || sign->next->priority < sign->priority))
328 return;
329
330 // One or more signs on the same line as 'sign'
331 // Find a sign after which 'sign' should be inserted
332
333 // First search backward for a sign with higher priority on the same line
334 p = sign;
335 while (p->prev != NULL && p->prev->lnum == sign->lnum
336 && p->prev->priority <= sign->priority)
337 p = p->prev;
338
339 if (p == sign)
340 {
341 // Sign not found. Search forward for a sign with priority just before
342 // 'sign'.
343 p = sign->next;
344 while (p->next != NULL && p->next->lnum == sign->lnum
345 && p->next->priority > sign->priority)
346 p = p->next;
347 }
348
349 // Remove 'sign' from the list
350 if (buf->b_signlist == sign)
351 buf->b_signlist = sign->next;
352 if (sign->prev != NULL)
353 sign->prev->next = sign->next;
354 if (sign->next != NULL)
355 sign->next->prev = sign->prev;
356 sign->prev = NULL;
357 sign->next = NULL;
358
359 // Re-insert 'sign' at the right place
360 if (p->priority <= sign->priority)
361 {
362 // 'sign' has a higher priority and should be inserted before 'p'
363 sign->prev = p->prev;
364 sign->next = p;
365 p->prev = sign;
366 if (sign->prev != NULL)
367 sign->prev->next = sign;
368 if (buf->b_signlist == p)
369 buf->b_signlist = sign;
370 }
371 else
372 {
373 // 'sign' has a lower priority and should be inserted after 'p'
374 sign->prev = p;
375 sign->next = p->next;
376 p->next = sign;
377 if (sign->next != NULL)
378 sign->next->prev = sign;
379 }
380 }
381
382 /*
311 * Add the sign into the signlist. Find the right spot to do it though. 383 * Add the sign into the signlist. Find the right spot to do it though.
312 */ 384 */
313 static void 385 static void
314 buf_addsign( 386 buf_addsign(
315 buf_T *buf, // buffer to store sign in 387 buf_T *buf, // buffer to store sign in
329 && sign_in_group(sign, groupname)) 401 && sign_in_group(sign, groupname))
330 { 402 {
331 // Update an existing sign 403 // Update an existing sign
332 sign->typenr = typenr; 404 sign->typenr = typenr;
333 sign->priority = prio; 405 sign->priority = prio;
406 sign_sort_by_prio_on_line(buf, sign);
334 return; 407 return;
335 } 408 }
336 else if (lnum < sign->lnum) 409 else if (lnum < sign->lnum)
337 { 410 {
338 insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, 411 insert_sign_by_lnum_prio(buf, prev, id, groupname, prio,