Mercurial > vim
comparison src/popupwin.c @ 17107:0001d10a7661 v8.1.1553
patch 8.1.1553: not easy to change the text in a popup window
commit https://github.com/vim/vim/commit/dc2ce58b5ac72e2af765385eb426660104816344
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 16 15:32:14 2019 +0200
patch 8.1.1553: not easy to change the text in a popup window
Problem: Not easy to change the text in a popup window.
Solution: Add popup_settext(). (Ben Jackson, closes https://github.com/vim/vim/issues/4549)
Also display a space for an empty popup.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 16 Jun 2019 15:45:05 +0200 |
parents | 1a23650f8da5 |
children | af861fccc309 |
comparison
equal
deleted
inserted
replaced
17106:32af152d94b1 | 17107:0001d10a7661 |
---|---|
599 wp->w_topline = wp->w_firstline; | 599 wp->w_topline = wp->w_firstline; |
600 if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) | 600 if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) |
601 wp->w_topline = wp->w_buffer->b_ml.ml_line_count; | 601 wp->w_topline = wp->w_buffer->b_ml.ml_line_count; |
602 | 602 |
603 // Compute width based on longest text line and the 'wrap' option. | 603 // Compute width based on longest text line and the 'wrap' option. |
604 // Use a minimum width of one, so that something shows when there is no | |
605 // text. | |
604 // TODO: more accurate wrapping | 606 // TODO: more accurate wrapping |
605 wp->w_width = 0; | 607 wp->w_width = 1; |
606 for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) | 608 for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) |
607 { | 609 { |
608 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); | 610 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); |
609 | 611 |
610 if (wp->w_p_wrap) | 612 if (wp->w_p_wrap) |
700 TYPE_NORMAL, | 702 TYPE_NORMAL, |
701 TYPE_ATCURSOR, | 703 TYPE_ATCURSOR, |
702 TYPE_NOTIFICATION, | 704 TYPE_NOTIFICATION, |
703 TYPE_DIALOG | 705 TYPE_DIALOG |
704 } create_type_T; | 706 } create_type_T; |
707 | |
708 /* | |
709 * Make "buf" empty and set the contents to "text". | |
710 * Used by popup_create() and popup_settext(). | |
711 */ | |
712 static void | |
713 popup_set_buffer_text(buf_T *buf, typval_T text) | |
714 { | |
715 int lnum; | |
716 | |
717 // Clear the buffer, then replace the lines. | |
718 curbuf = buf; | |
719 for (lnum = buf->b_ml.ml_line_count; lnum > 0; --lnum) | |
720 ml_delete(lnum, FALSE); | |
721 curbuf = curwin->w_buffer; | |
722 | |
723 // Add text to the buffer. | |
724 if (text.v_type == VAR_STRING) | |
725 { | |
726 // just a string | |
727 ml_append_buf(buf, 0, text.vval.v_string, (colnr_T)0, TRUE); | |
728 } | |
729 else | |
730 { | |
731 list_T *l = text.vval.v_list; | |
732 | |
733 if (l->lv_len > 0) | |
734 { | |
735 if (l->lv_first->li_tv.v_type == VAR_STRING) | |
736 // list of strings | |
737 add_popup_strings(buf, l); | |
738 else | |
739 // list of dictionaries | |
740 add_popup_dicts(buf, l); | |
741 } | |
742 } | |
743 | |
744 // delete the line that was in the empty buffer | |
745 curbuf = buf; | |
746 ml_delete(buf->b_ml.ml_line_count, FALSE); | |
747 curbuf = curwin->w_buffer; | |
748 } | |
705 | 749 |
706 /* | 750 /* |
707 * popup_create({text}, {options}) | 751 * popup_create({text}, {options}) |
708 * popup_atcursor({text}, {options}) | 752 * popup_atcursor({text}, {options}) |
709 */ | 753 */ |
787 } | 831 } |
788 else | 832 else |
789 // TODO: find tab page "nr" | 833 // TODO: find tab page "nr" |
790 emsg("Not implemented yet"); | 834 emsg("Not implemented yet"); |
791 | 835 |
792 // Add text to the buffer. | 836 popup_set_buffer_text(buf, argvars[0]); |
793 if (argvars[0].v_type == VAR_STRING) | |
794 { | |
795 // just a string | |
796 ml_append_buf(buf, 0, argvars[0].vval.v_string, (colnr_T)0, TRUE); | |
797 } | |
798 else | |
799 { | |
800 list_T *l = argvars[0].vval.v_list; | |
801 | |
802 if (l->lv_len > 0) | |
803 { | |
804 if (l->lv_first->li_tv.v_type == VAR_STRING) | |
805 // list of strings | |
806 add_popup_strings(buf, l); | |
807 else | |
808 // list of dictionaries | |
809 add_popup_dicts(buf, l); | |
810 } | |
811 } | |
812 | |
813 // Delete the line of the empty buffer. | |
814 curbuf = buf; | |
815 ml_delete(buf->b_ml.ml_line_count, FALSE); | |
816 curbuf = curwin->w_buffer; | |
817 | 837 |
818 if (type == TYPE_ATCURSOR) | 838 if (type == TYPE_ATCURSOR) |
819 { | 839 { |
820 wp->w_popup_pos = POPPOS_BOTLEFT; | 840 wp->w_popup_pos = POPPOS_BOTLEFT; |
821 setcursor_mayforce(TRUE); | 841 setcursor_mayforce(TRUE); |
1107 { | 1127 { |
1108 wp->w_popup_flags &= ~POPF_HIDDEN; | 1128 wp->w_popup_flags &= ~POPF_HIDDEN; |
1109 ++wp->w_buffer->b_nwindows; | 1129 ++wp->w_buffer->b_nwindows; |
1110 redraw_all_later(NOT_VALID); | 1130 redraw_all_later(NOT_VALID); |
1111 popup_mask_refresh = TRUE; | 1131 popup_mask_refresh = TRUE; |
1132 } | |
1133 } | |
1134 | |
1135 /* | |
1136 * popup_settext({id}, {text}) | |
1137 */ | |
1138 void | |
1139 f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED) | |
1140 { | |
1141 int id = (int)tv_get_number(&argvars[0]); | |
1142 win_T *wp = find_popup_win(id); | |
1143 | |
1144 if (wp != NULL) | |
1145 { | |
1146 popup_set_buffer_text(wp->w_buffer, argvars[1]); | |
1147 popup_adjust_position(wp); | |
1112 } | 1148 } |
1113 } | 1149 } |
1114 | 1150 |
1115 static void | 1151 static void |
1116 popup_free(win_T *wp) | 1152 popup_free(win_T *wp) |