Mercurial > vim
comparison src/textprop.c @ 30205:ed6f3d2593df v9.0.0438
patch 9.0.0438: cannot put virtual text above a line
Commit: https://github.com/vim/vim/commit/04e0ed1ddf399d609dbcb7dbf19e531da1fe6172
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 10 20:00:56 2022 +0100
patch 9.0.0438: cannot put virtual text above a line
Problem: Cannot put virtual text above a line.
Solution: Add the "above" value for "text_align".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Sep 2022 21:15:03 +0200 |
parents | adb0de8be4ce |
children | 0d084880276a |
comparison
equal
deleted
inserted
replaced
30204:b6c11bb32c89 | 30205:ed6f3d2593df |
---|---|
495 emsg(_(e_can_only_use_text_align_when_column_is_zero)); | 495 emsg(_(e_can_only_use_text_align_when_column_is_zero)); |
496 goto theend; | 496 goto theend; |
497 } | 497 } |
498 if (STRCMP(p, "right") == 0) | 498 if (STRCMP(p, "right") == 0) |
499 flags |= TP_FLAG_ALIGN_RIGHT; | 499 flags |= TP_FLAG_ALIGN_RIGHT; |
500 else if (STRCMP(p, "above") == 0) | |
501 flags |= TP_FLAG_ALIGN_ABOVE; | |
500 else if (STRCMP(p, "below") == 0) | 502 else if (STRCMP(p, "below") == 0) |
501 flags |= TP_FLAG_ALIGN_BELOW; | 503 flags |= TP_FLAG_ALIGN_BELOW; |
502 else if (STRCMP(p, "after") != 0) | 504 else if (STRCMP(p, "after") != 0) |
503 { | 505 { |
504 semsg(_(e_invalid_value_for_argument_str_str), "text_align", p); | 506 semsg(_(e_invalid_value_for_argument_str_str), "text_align", p); |
671 } | 673 } |
672 | 674 |
673 static textprop_T *text_prop_compare_props; | 675 static textprop_T *text_prop_compare_props; |
674 static buf_T *text_prop_compare_buf; | 676 static buf_T *text_prop_compare_buf; |
675 | 677 |
678 /* Score for sorting on position of the text property: 0: above, | |
679 * 1: after (default), 2: right, 3: below (comes last) | |
680 */ | |
681 static int | |
682 text_prop_order(int flags) | |
683 { | |
684 if (flags & TP_FLAG_ALIGN_ABOVE) | |
685 return 0; | |
686 if (flags & TP_FLAG_ALIGN_RIGHT) | |
687 return 2; | |
688 if (flags & TP_FLAG_ALIGN_BELOW) | |
689 return 3; | |
690 return 1; | |
691 } | |
692 | |
676 /* | 693 /* |
677 * Function passed to qsort() to sort text properties. | 694 * Function passed to qsort() to sort text properties. |
678 * Return 1 if "s1" has priority over "s2", -1 if the other way around, zero if | 695 * Return 1 if "s1" has priority over "s2", -1 if the other way around, zero if |
679 * both have the same priority. | 696 * both have the same priority. |
680 */ | 697 */ |
692 tp2 = &text_prop_compare_props[idx2]; | 709 tp2 = &text_prop_compare_props[idx2]; |
693 col1 = tp1->tp_col; | 710 col1 = tp1->tp_col; |
694 col2 = tp2->tp_col; | 711 col2 = tp2->tp_col; |
695 if (col1 == MAXCOL && col2 == MAXCOL) | 712 if (col1 == MAXCOL && col2 == MAXCOL) |
696 { | 713 { |
697 int flags1 = 0; | 714 int order1 = text_prop_order(tp1->tp_flags); |
698 int flags2 = 0; | 715 int order2 = text_prop_order(tp2->tp_flags); |
699 | 716 |
700 // both props add text are after the line, order on 0: after (default), | 717 // both props add text before or after the line, sort on order where it |
701 // 1: right, 2: below (comes last) | 718 // is added |
702 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT) | 719 if (order1 != order2) |
703 flags1 = 1; | 720 return order1 < order2 ? 1 : -1; |
704 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW) | |
705 flags1 = 2; | |
706 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT) | |
707 flags2 = 1; | |
708 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW) | |
709 flags2 = 2; | |
710 if (flags1 != flags2) | |
711 return flags1 < flags2 ? 1 : -1; | |
712 } | 721 } |
713 | 722 |
714 // property that inserts text has priority over one that doesn't | 723 // property that inserts text has priority over one that doesn't |
715 if ((tp1->tp_id < 0) != (tp2->tp_id < 0)) | 724 if ((tp1->tp_id < 0) != (tp2->tp_id < 0)) |
716 return tp1->tp_id < 0 ? 1 : -1; | 725 return tp1->tp_id < 0 ? 1 : -1; |