-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
drawscreen.c
3352 lines (3089 loc) · 89.1 KB
/
drawscreen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* drawscreen.c: Code for updating all the windows on the screen.
* This is the top level, drawline.c is the middle and screen.c the lower
* level.
*
* update_screen() is the function that updates all windows and status lines.
* It is called form the main loop when must_redraw is non-zero. It may be
* called from other places when an immediate screen update is needed.
*
* The part of the buffer that is displayed in a window is set with:
* - w_topline (first buffer line in window)
* - w_topfill (filler lines above the first line)
* - w_leftcol (leftmost window cell in window),
* - w_skipcol (skipped window cells of first line)
*
* Commands that only move the cursor around in a window, do not need to take
* action to update the display. The main loop will check if w_topline is
* valid and update it (scroll the window) when needed.
*
* Commands that scroll a window change w_topline and must call
* check_cursor() to move the cursor into the visible part of the window, and
* call redraw_later(UPD_VALID) to have the window displayed by update_screen()
* later.
*
* Commands that change text in the buffer must call changed_bytes() or
* changed_lines() to mark the area that changed and will require updating
* later. The main loop will call update_screen(), which will update each
* window that shows the changed buffer. This assumes text above the change
* can remain displayed as it is. Text after the change may need updating for
* scrolling, folding and syntax highlighting.
*
* Commands that change how a window is displayed (e.g., setting 'list') or
* invalidate the contents of a window in another way (e.g., change fold
* settings), must call redraw_later(UPD_NOT_VALID) to have the whole window
* redisplayed by update_screen() later.
*
* Commands that change how a buffer is displayed (e.g., setting 'tabstop')
* must call redraw_curbuf_later(UPD_NOT_VALID) to have all the windows for the
* buffer redisplayed by update_screen() later.
*
* Commands that change highlighting and possibly cause a scroll too must call
* redraw_later(UPD_SOME_VALID) to update the whole window but still use
* scrolling to avoid redrawing everything. But the length of displayed lines
* must not change, use UPD_NOT_VALID then.
*
* Commands that move the window position must call redraw_later(UPD_NOT_VALID).
* TODO: should minimize redrawing by scrolling when possible.
*
* Commands that change everything (e.g., resizing the screen) must call
* redraw_all_later(UPD_NOT_VALID) or redraw_all_later(UPD_CLEAR).
*
* Things that are handled indirectly:
* - When messages scroll the screen up, msg_scrolled will be set and
* update_screen() called to redraw.
*/
#include "vim.h"
static void win_update(win_T *wp);
#ifdef FEAT_STL_OPT
static void redraw_custom_statusline(win_T *wp);
#endif
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
static int did_update_one_window;
#endif
/*
* Based on the current value of curwin->w_topline, transfer a screenfull
* of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
* Return OK when the screen was updated, FAIL if it was not done.
*/
int
update_screen(int type_arg)
{
int type = type_arg;
win_T *wp;
static int did_intro = FALSE;
#ifdef FEAT_GUI
int did_one = FALSE;
int did_undraw = FALSE;
int gui_cursor_col = 0;
int gui_cursor_row = 0;
#endif
int no_update = FALSE;
int save_pum_will_redraw = pum_will_redraw;
// Don't do anything if the screen structures are (not yet) valid.
if (!screen_valid(TRUE))
return FAIL;
if (type == UPD_VALID_NO_UPDATE)
{
no_update = TRUE;
type = 0;
}
#ifdef FEAT_EVAL
{
buf_T *buf;
// Before updating the screen, notify any listeners of changed text.
FOR_ALL_BUFFERS(buf)
invoke_listeners(buf);
}
#endif
#ifdef FEAT_DIFF
// May have postponed updating diffs.
if (need_diff_redraw)
diff_redraw(TRUE);
#endif
if (must_redraw)
{
if (type < must_redraw) // use maximal type
type = must_redraw;
// must_redraw is reset here, so that when we run into some weird
// reason to redraw while busy redrawing (e.g., asynchronous
// scrolling), or update_topline() in win_update() will cause a
// scroll, the screen will be redrawn later or in win_update().
must_redraw = 0;
}
// May need to update w_lines[].
if (curwin->w_lines_valid == 0 && type < UPD_NOT_VALID
#ifdef FEAT_TERMINAL
&& !term_do_update_window(curwin)
#endif
)
type = UPD_NOT_VALID;
// Postpone the redrawing when it's not needed and when being called
// recursively.
if (!redrawing() || updating_screen)
{
redraw_later(type); // remember type for next time
must_redraw = type;
if (type > UPD_INVERTED_ALL)
curwin->w_lines_valid = 0; // don't use w_lines[].wl_size now
return FAIL;
}
updating_screen = TRUE;
#ifdef FEAT_PROP_POPUP
// Update popup_mask if needed. This may set w_redraw_top and w_redraw_bot
// in some windows.
may_update_popup_mask(type);
#endif
#ifdef FEAT_SYN_HL
++display_tick; // let syntax code know we're in a next round of
// display updating
#endif
if (no_update)
++no_win_do_lines_ins;
// if the screen was scrolled up when displaying a message, scroll it down
if (msg_scrolled)
{
clear_cmdline = TRUE;
if (type != UPD_CLEAR)
{
if (msg_scrolled > Rows - 5) // redrawing is faster
{
type = UPD_NOT_VALID;
redraw_as_cleared();
}
else
{
check_for_delay(FALSE);
if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, 0, NULL)
== FAIL)
{
type = UPD_NOT_VALID;
redraw_as_cleared();
}
FOR_ALL_WINDOWS(wp)
{
if (wp->w_winrow < msg_scrolled)
{
if (W_WINROW(wp) + wp->w_height > msg_scrolled
&& wp->w_redr_type < UPD_REDRAW_TOP
&& wp->w_lines_valid > 0
&& wp->w_topline == wp->w_lines[0].wl_lnum)
{
wp->w_upd_rows = msg_scrolled - W_WINROW(wp);
wp->w_redr_type = UPD_REDRAW_TOP;
}
else
{
wp->w_redr_type = UPD_NOT_VALID;
if (W_WINROW(wp) + wp->w_height
+ wp->w_status_height <= msg_scrolled)
wp->w_redr_status = TRUE;
}
}
}
if (!no_update)
redraw_cmdline = TRUE;
redraw_tabline = TRUE;
}
}
msg_scrolled = 0;
need_wait_return = FALSE;
}
// reset cmdline_row now (may have been changed temporarily)
compute_cmdrow();
// Check for changed highlighting
if (need_highlight_changed)
highlight_changed();
if (type == UPD_CLEAR) // first clear screen
{
screenclear(); // will reset clear_cmdline
type = UPD_NOT_VALID;
// must_redraw may be set indirectly, avoid another redraw later
must_redraw = 0;
}
if (clear_cmdline) // going to clear cmdline (done below)
check_for_delay(FALSE);
#ifdef FEAT_LINEBREAK
// Force redraw when width of 'number' or 'relativenumber' column
// changes.
if (curwin->w_redr_type < UPD_NOT_VALID
&& curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu)
? number_width(curwin) : 0))
curwin->w_redr_type = UPD_NOT_VALID;
#endif
// Only start redrawing if there is really something to do.
if (type == UPD_INVERTED)
update_curswant();
if (curwin->w_redr_type < type
&& !((type == UPD_VALID
&& curwin->w_lines[0].wl_valid
#ifdef FEAT_DIFF
&& curwin->w_topfill == curwin->w_old_topfill
&& curwin->w_botfill == curwin->w_old_botfill
#endif
&& curwin->w_topline == curwin->w_lines[0].wl_lnum)
|| (type == UPD_INVERTED
&& VIsual_active
&& curwin->w_old_cursor_lnum == curwin->w_cursor.lnum
&& curwin->w_old_visual_mode == VIsual_mode
&& (curwin->w_valid & VALID_VIRTCOL)
&& curwin->w_old_curswant == curwin->w_curswant)
))
curwin->w_redr_type = type;
// Redraw the tab pages line if needed.
if (redraw_tabline || type >= UPD_NOT_VALID)
draw_tabline();
#ifdef FEAT_SYN_HL
// Correct stored syntax highlighting info for changes in each displayed
// buffer. Each buffer must only be done once.
FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer->b_mod_set)
{
win_T *wwp;
// Check if we already did this buffer.
for (wwp = firstwin; wwp != wp; wwp = wwp->w_next)
if (wwp->w_buffer == wp->w_buffer)
break;
if (wwp == wp && syntax_present(wp))
syn_stack_apply_changes(wp->w_buffer);
}
}
#endif
if (pum_redraw_in_same_position())
// Avoid flicker if the popup menu is going to be redrawn in the same
// position.
pum_will_redraw = TRUE;
// Go from top to bottom through the windows, redrawing the ones that need
// it.
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
did_update_one_window = FALSE;
#endif
#ifdef FEAT_SEARCH_EXTRA
screen_search_hl.rm.regprog = NULL;
#endif
FOR_ALL_WINDOWS(wp)
{
if (wp->w_redr_type != 0)
{
cursor_off();
#ifdef FEAT_GUI
if (!did_one)
{
did_one = TRUE;
// Remove the cursor before starting to do anything, because
// scrolling may make it difficult to redraw the text under
// it.
// Also remove the cursor if it needs to be hidden due to an
// ongoing cursor-less sleep.
if (gui.in_use && (wp == curwin || cursor_is_sleeping()))
{
gui_cursor_col = gui.cursor_col;
gui_cursor_row = gui.cursor_row;
gui_undraw_cursor();
did_undraw = TRUE;
}
}
#endif
win_update(wp);
}
// redraw status line after the window to minimize cursor movement
if (wp->w_redr_status)
{
cursor_off();
win_redr_status(wp, TRUE); // any popup menu will be redrawn below
}
}
#if defined(FEAT_SEARCH_EXTRA)
end_search_hl();
#endif
// May need to redraw the popup menu.
pum_will_redraw = save_pum_will_redraw;
pum_may_redraw();
// Reset b_mod_set flags. Going through all windows is probably faster
// than going through all buffers (there could be many buffers).
FOR_ALL_WINDOWS(wp)
wp->w_buffer->b_mod_set = FALSE;
#ifdef FEAT_PROP_POPUP
// Display popup windows on top of the windows and command line.
update_popups(win_update);
#endif
#ifdef FEAT_TERMINAL
FOR_ALL_WINDOWS(wp)
// If this window contains a terminal, after redrawing all windows, the
// dirty row range can be reset.
term_did_update_window(wp);
#endif
after_updating_screen(TRUE);
// Clear or redraw the command line. Done last, because scrolling may
// mess up the command line.
if (clear_cmdline || redraw_cmdline || redraw_mode)
showmode();
if (no_update)
--no_win_do_lines_ins;
// May put up an introductory message when not editing a file
if (!did_intro)
maybe_intro_message();
did_intro = TRUE;
#ifdef FEAT_GUI
// Redraw the cursor and update the scrollbars when all screen updating is
// done.
if (gui.in_use)
{
if (did_undraw && !gui_mch_is_blink_off())
{
mch_disable_flush();
out_flush(); // required before updating the cursor
mch_enable_flush();
// Put the GUI position where the cursor was, gui_update_cursor()
// uses that.
gui.col = gui_cursor_col;
gui.row = gui_cursor_row;
gui.col = mb_fix_col(gui.col, gui.row);
gui_update_cursor(FALSE, FALSE);
gui_may_flush();
screen_cur_col = gui.col;
screen_cur_row = gui.row;
}
else
out_flush();
gui_update_scrollbars(FALSE);
}
#endif
return OK;
}
/*
* Return the row for drawing the statusline and the ruler of window "wp".
*/
int
statusline_row(win_T *wp)
{
#if defined(FEAT_PROP_POPUP)
// If the window is really zero height the winbar isn't displayed.
if (wp->w_frame->fr_height == wp->w_status_height && !popup_is_popup(wp))
return wp->w_winrow;
#endif
return W_WINROW(wp) + wp->w_height;
}
/*
* Redraw the status line of window wp.
*
* If inversion is possible we use it. Else '=' characters are used.
* If "ignore_pum" is TRUE, also redraw statusline when the popup menu is
* displayed.
*/
void
win_redr_status(win_T *wp, int ignore_pum UNUSED)
{
int row;
char_u *p;
int len;
int fillchar;
int attr;
int this_ru_col;
static int busy = FALSE;
// It's possible to get here recursively when 'statusline' (indirectly)
// invokes ":redrawstatus". Simply ignore the call then.
if (busy)
return;
busy = TRUE;
row = statusline_row(wp);
wp->w_redr_status = FALSE;
if (wp->w_status_height == 0)
{
// no status line, can only be last window
redraw_cmdline = TRUE;
}
else if (!redrawing()
// don't update status line when popup menu is visible and may be
// drawn over it, unless it will be redrawn later
|| (!ignore_pum && pum_visible()))
{
// Don't redraw right now, do it later.
wp->w_redr_status = TRUE;
}
#ifdef FEAT_STL_OPT
else if (*p_stl != NUL || *wp->w_p_stl != NUL)
{
// redraw custom status line
redraw_custom_statusline(wp);
}
#endif
else
{
fillchar = fillchar_status(&attr, wp);
get_trans_bufname(wp->w_buffer);
p = NameBuff;
len = (int)STRLEN(p);
if ((bt_help(wp->w_buffer)
#ifdef FEAT_QUICKFIX
|| wp->w_p_pvw
#endif
|| bufIsChanged(wp->w_buffer)
|| wp->w_buffer->b_p_ro)
&& len < MAXPATHL - 1)
*(p + len++) = ' ';
if (bt_help(wp->w_buffer))
{
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Help]"));
len += (int)STRLEN(p + len);
}
#ifdef FEAT_QUICKFIX
if (wp->w_p_pvw)
{
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Preview]"));
len += (int)STRLEN(p + len);
}
#endif
if (bufIsChanged(wp->w_buffer) && !bt_terminal(wp->w_buffer))
{
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", "[+]");
len += (int)STRLEN(p + len);
}
if (wp->w_buffer->b_p_ro)
{
vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[RO]"));
len += (int)STRLEN(p + len);
}
this_ru_col = ru_col - (Columns - wp->w_width);
if (this_ru_col < (wp->w_width + 1) / 2)
this_ru_col = (wp->w_width + 1) / 2;
if (this_ru_col <= 1)
{
p = (char_u *)"<"; // No room for file name!
len = 1;
}
else if (has_mbyte)
{
int clen = 0, i;
// Count total number of display cells.
clen = mb_string2cells(p, -1);
// Find first character that will fit.
// Going from start to end is much faster for DBCS.
for (i = 0; p[i] != NUL && clen >= this_ru_col - 1;
i += (*mb_ptr2len)(p + i))
clen -= (*mb_ptr2cells)(p + i);
len = clen;
if (i > 0)
{
p = p + i - 1;
*p = '<';
++len;
}
}
else if (len > this_ru_col - 1)
{
p += len - (this_ru_col - 1);
*p = '<';
len = this_ru_col - 1;
}
screen_puts(p, row, wp->w_wincol, attr);
screen_fill(row, row + 1, len + wp->w_wincol,
this_ru_col + wp->w_wincol, fillchar, fillchar, attr);
if (get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL)
&& (this_ru_col - len) > (int)(STRLEN(NameBuff) + 1))
screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff)
- 1 + wp->w_wincol), attr);
win_redr_ruler(wp, TRUE, ignore_pum);
// Draw the 'showcmd' information if 'showcmdloc' == "statusline".
if (p_sc && *p_sloc == 's')
{
int width = MIN(10, this_ru_col - len - 2);
if (width > 0)
screen_puts_len(showcmd_buf, width, row,
wp->w_wincol + this_ru_col - width - 1, attr);
}
}
/*
* May need to draw the character below the vertical separator.
*/
if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing())
{
if (stl_connected(wp))
fillchar = fillchar_status(&attr, wp);
else
fillchar = fillchar_vsep(&attr, wp);
screen_putchar(fillchar, row, W_ENDCOL(wp), attr);
}
busy = FALSE;
}
#ifdef FEAT_STL_OPT
/*
* Redraw the status line according to 'statusline' and take care of any
* errors encountered.
*/
static void
redraw_custom_statusline(win_T *wp)
{
static int entered = FALSE;
// When called recursively return. This can happen when the statusline
// contains an expression that triggers a redraw.
if (entered)
return;
entered = TRUE;
win_redr_custom(wp, FALSE);
entered = FALSE;
}
#endif
/*
* Show current status info in ruler and various other places
* If always is FALSE, only show ruler if position has changed.
*/
void
showruler(int always)
{
if (!always && !redrawing())
return;
if (pum_visible())
{
// Don't redraw right now, do it later.
curwin->w_redr_status = TRUE;
return;
}
#if defined(FEAT_STL_OPT)
if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height)
redraw_custom_statusline(curwin);
else
#endif
win_redr_ruler(curwin, always, FALSE);
if (need_maketitle
#ifdef FEAT_STL_OPT
|| (p_icon && (stl_syntax & STL_IN_ICON))
|| (p_title && (stl_syntax & STL_IN_TITLE))
#endif
)
maketitle();
// Redraw the tab pages line if needed.
if (redraw_tabline)
draw_tabline();
}
void
win_redr_ruler(win_T *wp, int always, int ignore_pum)
{
#define RULER_BUF_LEN 70
char_u buffer[RULER_BUF_LEN];
int row;
int fillchar;
int attr;
int empty_line = FALSE;
colnr_T virtcol;
int i;
size_t len;
int o;
int this_ru_col;
int off = 0;
int width;
// If 'ruler' off don't do anything
if (!p_ru)
return;
/*
* Check if cursor.lnum is valid, since win_redr_ruler() may be called
* after deleting lines, before cursor.lnum is corrected.
*/
if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
return;
// Don't draw the ruler while doing insert-completion, it might overwrite
// the (long) mode message.
if (wp == lastwin && lastwin->w_status_height == 0)
if (edit_submode != NULL)
return;
// Don't draw the ruler when the popup menu is visible, it may overlap.
// Except when the popup menu will be redrawn anyway.
if (!ignore_pum && pum_visible())
return;
#ifdef FEAT_STL_OPT
if (*p_ruf)
{
win_redr_custom(wp, TRUE);
return;
}
#endif
/*
* Check if not in Insert mode and the line is empty (will show "0-1").
*/
if ((State & MODE_INSERT) == 0
&& *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL)
empty_line = TRUE;
/*
* Only draw the ruler when something changed.
*/
validate_virtcol_win(wp);
if ( redraw_cmdline
|| always
|| wp->w_cursor.lnum != wp->w_ru_cursor.lnum
|| wp->w_cursor.col != wp->w_ru_cursor.col
|| wp->w_virtcol != wp->w_ru_virtcol
|| wp->w_cursor.coladd != wp->w_ru_cursor.coladd
|| wp->w_topline != wp->w_ru_topline
|| wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count
#ifdef FEAT_DIFF
|| wp->w_topfill != wp->w_ru_topfill
#endif
|| empty_line != wp->w_ru_empty)
{
cursor_off();
if (wp->w_status_height)
{
row = statusline_row(wp);
fillchar = fillchar_status(&attr, wp);
off = wp->w_wincol;
width = wp->w_width;
}
else
{
row = Rows - 1;
fillchar = ' ';
attr = 0;
width = Columns;
off = 0;
}
// In list mode virtcol needs to be recomputed
virtcol = wp->w_virtcol;
if (wp->w_p_list && wp->w_lcs_chars.tab1 == NUL)
{
wp->w_p_list = FALSE;
getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
wp->w_p_list = TRUE;
}
/*
* Some sprintfs return the length, some return a pointer.
* To avoid portability problems we use strlen() here.
*/
vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,",
(wp->w_buffer->b_ml.ml_flags & ML_EMPTY)
? 0L
: (long)(wp->w_cursor.lnum));
len = STRLEN(buffer);
col_print(buffer + len, RULER_BUF_LEN - len,
empty_line ? 0 : (int)wp->w_cursor.col + 1,
(int)virtcol + 1);
/*
* Add a "50%" if there is room for it.
* On the last line, don't print in the last column (scrolls the
* screen up on some terminals).
*/
i = (int)STRLEN(buffer);
get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1);
o = i + vim_strsize(buffer + i + 1);
if (wp->w_status_height == 0) // can't use last char of screen
++o;
this_ru_col = ru_col - (Columns - width);
if (this_ru_col < 0)
this_ru_col = 0;
// Never use more than half the window/screen width, leave the other
// half for the filename.
if (this_ru_col < (width + 1) / 2)
this_ru_col = (width + 1) / 2;
if (this_ru_col + o < width)
{
// need at least 3 chars left for get_rel_pos() + NUL
while (this_ru_col + o < width && RULER_BUF_LEN > i + 4)
{
if (has_mbyte)
i += (*mb_char2bytes)(fillchar, buffer + i);
else
buffer[i++] = fillchar;
++o;
}
get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i);
}
// Truncate at window boundary.
if (has_mbyte)
{
o = 0;
for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i))
{
o += (*mb_ptr2cells)(buffer + i);
if (this_ru_col + o > width)
{
buffer[i] = NUL;
break;
}
}
}
else if (this_ru_col + (int)STRLEN(buffer) > width)
buffer[width - this_ru_col] = NUL;
screen_puts(buffer, row, this_ru_col + off, attr);
i = redraw_cmdline;
screen_fill(row, row + 1,
this_ru_col + off + (int)STRLEN(buffer),
(off + width),
fillchar, fillchar, attr);
// don't redraw the cmdline because of showing the ruler
redraw_cmdline = i;
wp->w_ru_cursor = wp->w_cursor;
wp->w_ru_virtcol = wp->w_virtcol;
wp->w_ru_empty = empty_line;
wp->w_ru_topline = wp->w_topline;
wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count;
#ifdef FEAT_DIFF
wp->w_ru_topfill = wp->w_topfill;
#endif
}
}
/*
* To be called when "updating_screen" was set before and now the postponed
* side effects may take place.
*/
void
after_updating_screen(int may_resize_shell UNUSED)
{
updating_screen = FALSE;
#ifdef FEAT_GUI
if (may_resize_shell)
gui_may_resize_shell();
#endif
#ifdef FEAT_TERMINAL
term_check_channel_closed_recently();
#endif
#ifdef HAVE_DROP_FILE
// If handle_drop() was called while updating_screen was TRUE need to
// handle the drop now.
handle_any_postponed_drop();
#endif
}
/*
* Update all windows that are editing the current buffer.
*/
void
update_curbuf(int type)
{
redraw_curbuf_later(type);
update_screen(type);
}
#if defined(FEAT_MENU) || defined(FEAT_FOLDING)
/*
* Copy "text" to ScreenLines using "attr".
* Returns the next screen column.
*/
static int
text_to_screenline(win_T *wp, char_u *text, int col)
{
int off = (int)(current_ScreenLine - ScreenLines);
if (has_mbyte)
{
int cells;
int u8c, u8cc[MAX_MCO];
int i;
int idx;
int c_len;
char_u *p;
# ifdef FEAT_ARABIC
int prev_c = 0; // previous Arabic character
int prev_c1 = 0; // first composing char for prev_c
# endif
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
idx = off;
else
# endif
idx = off + col;
// Store multibyte characters in ScreenLines[] et al. correctly.
for (p = text; *p != NUL; )
{
cells = (*mb_ptr2cells)(p);
c_len = (*mb_ptr2len)(p);
if (col + cells > wp->w_width
# ifdef FEAT_RIGHTLEFT
- (wp->w_p_rl ? col : 0)
# endif
)
break;
ScreenLines[idx] = *p;
if (enc_utf8)
{
u8c = utfc_ptr2char(p, u8cc);
if (*p < 0x80 && u8cc[0] == 0)
{
ScreenLinesUC[idx] = 0;
#ifdef FEAT_ARABIC
prev_c = u8c;
#endif
}
else
{
#ifdef FEAT_ARABIC
if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
{
// Do Arabic shaping.
int pc, pc1, nc;
int pcc[MAX_MCO];
int firstbyte = *p;
// The idea of what is the previous and next
// character depends on 'rightleft'.
if (wp->w_p_rl)
{
pc = prev_c;
pc1 = prev_c1;
nc = utf_ptr2char(p + c_len);
prev_c1 = u8cc[0];
}
else
{
pc = utfc_ptr2char(p + c_len, pcc);
nc = prev_c;
pc1 = pcc[0];
}
prev_c = u8c;
u8c = arabic_shape(u8c, &firstbyte, &u8cc[0],
pc, pc1, nc);
ScreenLines[idx] = firstbyte;
}
else
prev_c = u8c;
#endif
// Non-BMP character: display as ? or fullwidth ?.
ScreenLinesUC[idx] = u8c;
for (i = 0; i < Screen_mco; ++i)
{
ScreenLinesC[i][idx] = u8cc[i];
if (u8cc[i] == 0)
break;
}
}
if (cells > 1)
ScreenLines[idx + 1] = 0;
}
else if (enc_dbcs == DBCS_JPNU && *p == 0x8e)
// double-byte single width character
ScreenLines2[idx] = p[1];
else if (cells > 1)
// double-width character
ScreenLines[idx + 1] = p[1];
col += cells;
idx += cells;
p += c_len;
}
}
else
{
int len = (int)STRLEN(text);
if (len > wp->w_width - col)
len = wp->w_width - col;
if (len > 0)
{
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
mch_memmove(current_ScreenLine, text, len);
else
#endif
mch_memmove(current_ScreenLine + col, text, len);
col += len;
}
}
return col;
}
#endif
#ifdef FEAT_MENU
/*
* Draw the window toolbar.
*/
static void
redraw_win_toolbar(win_T *wp)
{
vimmenu_T *menu;
int item_idx = 0;
int item_count = 0;
int col = 0;
int next_col;
int off = (int)(current_ScreenLine - ScreenLines);
int fill_attr = syn_name2attr((char_u *)"ToolbarLine");
int button_attr = syn_name2attr((char_u *)"ToolbarButton");
vim_free(wp->w_winbar_items);
FOR_ALL_CHILD_MENUS(wp->w_winbar, menu)
++item_count;
wp->w_winbar_items = ALLOC_CLEAR_MULT(winbar_item_T, item_count + 1);
// TODO: use fewer spaces if there is not enough room
for (menu = wp->w_winbar->children;
menu != NULL && col < wp->w_width; menu = menu->next)
{
space_to_screenline(off + col, fill_attr);
if (++col >= wp->w_width)
break;
if (col > 1)
{
space_to_screenline(off + col, fill_attr);
if (++col >= wp->w_width)