-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
screen.c
5050 lines (4666 loc) · 126 KB
/
screen.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.
*/
/*
* screen.c: Lower level code for displaying on the screen.
*
* Output to the screen (console, terminal emulator or GUI window) is minimized
* by remembering what is already on the screen, and only updating the parts
* that changed.
*
* ScreenLines[off] Contains a copy of the whole screen, as it is currently
* displayed (excluding text written by external commands).
* ScreenAttrs[off] Contains the associated attributes.
* ScreenCols[off] Contains the virtual columns in the line. -1 means not
* available or before buffer text.
*
* LineOffset[row] Contains the offset into ScreenLines*[], ScreenAttrs[]
* and ScreenCols[] for each line.
* LineWraps[row] Flag for each line whether it wraps to the next line.
*
* For double-byte characters, two consecutive bytes in ScreenLines[] can form
* one character which occupies two display cells.
* For UTF-8 a multi-byte character is converted to Unicode and stored in
* ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII
* character without composing chars ScreenLinesUC[] will be 0 and
* ScreenLinesC[][] is not used. When the character occupies two display
* cells the next byte in ScreenLines[] is 0.
* ScreenLinesC[][] contain up to 'maxcombine' composing characters
* (drawn on top of the first character). There is 0 after the last one used.
* ScreenLines2[] is only used for euc-jp to store the second byte if the
* first byte is 0x8e (single-width character).
*
* The screen_*() functions write to the screen and handle updating
* ScreenLines[].
*/
#include "vim.h"
/*
* The attributes that are actually active for writing to the screen.
*/
static int screen_attr = 0;
static void screen_char_2(unsigned off, int row, int col);
static int screenclear2(int doclear);
static void lineclear(unsigned off, int width, int attr);
static void lineinvalid(unsigned off, int width);
static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del, int clear_attr);
static void win_rest_invalid(win_T *wp);
static void msg_pos_mode(void);
static void recording_mode(int attr);
// Ugly global: overrule attribute used by screen_char()
static int screen_char_attr = 0;
#if defined(FEAT_CONCEAL) || defined(PROTO)
/*
* Return TRUE if the cursor line in window "wp" may be concealed, according
* to the 'concealcursor' option.
*/
int
conceal_cursor_line(win_T *wp)
{
int c;
if (*wp->w_p_cocu == NUL)
return FALSE;
if (get_real_state() & MODE_VISUAL)
c = 'v';
else if (State & MODE_INSERT)
c = 'i';
else if (State & MODE_NORMAL)
c = 'n';
else if (State & MODE_CMDLINE)
c = 'c';
else
return FALSE;
return vim_strchr(wp->w_p_cocu, c) != NULL;
}
/*
* Check if the cursor line needs to be redrawn because of 'concealcursor'.
* To be called after changing the state, "was_concealed" is the value of
* "conceal_cursor_line()" before the change.
* "
*/
void
conceal_check_cursor_line(int was_concealed)
{
if (curwin->w_p_cole <= 0 || conceal_cursor_line(curwin) == was_concealed)
return;
int wcol = curwin->w_wcol;
need_cursor_line_redraw = TRUE;
// Need to recompute cursor column, e.g., when starting Visual mode
// without concealing.
curs_columns(TRUE);
// When concealing now w_wcol will be computed wrong, keep the previous
// value, it will be updated in win_line().
if (!was_concealed)
curwin->w_wcol = wcol;
}
#endif
/*
* Get 'wincolor' attribute for window "wp". If not set and "wp" is a popup
* window then get the "Pmenu" highlight attribute.
*/
int
get_wcr_attr(win_T *wp)
{
int wcr_attr = 0;
if (*wp->w_p_wcr != NUL)
wcr_attr = syn_name2attr(wp->w_p_wcr);
#ifdef FEAT_PROP_POPUP
else if (WIN_IS_POPUP(wp))
{
if (wp->w_popup_flags & POPF_INFO)
wcr_attr = HL_ATTR(HLF_PSI); // PmenuSel
else
wcr_attr = HL_ATTR(HLF_PNI); // Pmenu
}
#endif
return wcr_attr;
}
/*
* Call screen_fill() with the columns adjusted for 'rightleft' if needed.
* Return the new offset.
*/
static int
screen_fill_end(
win_T *wp,
int c1,
int c2,
int off,
int width,
int row,
int endrow,
int attr)
{
int nn = off + width;
if (nn > wp->w_width)
nn = wp->w_width;
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - off,
c1, c2, attr);
}
else
#endif
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol + off, (int)wp->w_wincol + nn,
c1, c2, attr);
return nn;
}
/*
* Clear lines near the end the window and mark the unused lines with "c1".
* use "c2" as the filler character.
* When "draw_margin" is TRUE then draw the sign, fold and number columns.
*/
void
win_draw_end(
win_T *wp,
int c1,
int c2,
int draw_margin,
int row,
int endrow,
hlf_T hl)
{
int n = 0;
int attr = HL_ATTR(hl);
int wcr_attr = get_wcr_attr(wp);
attr = hl_combine_attr(wcr_attr, attr);
if (draw_margin)
{
#ifdef FEAT_FOLDING
int fdc = compute_foldcolumn(wp, 0);
if (fdc > 0)
// draw the fold column
n = screen_fill_end(wp, ' ', ' ', n, fdc,
row, endrow, hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC)));
#endif
#ifdef FEAT_SIGNS
if (signcolumn_on(wp))
// draw the sign column
n = screen_fill_end(wp, ' ', ' ', n, 2,
row, endrow, hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC)));
#endif
if ((wp->w_p_nu || wp->w_p_rnu)
&& vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
// draw the number column
n = screen_fill_end(wp, ' ', ' ', n, number_width(wp) + 1,
row, endrow, hl_combine_attr(wcr_attr, HL_ATTR(HLF_N)));
}
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol, W_ENDCOL(wp) - 1 - n,
c2, c2, attr);
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
W_ENDCOL(wp) - 1 - n, W_ENDCOL(wp) - n,
c1, c2, attr);
}
else
#endif
{
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol + n, (int)W_ENDCOL(wp),
c1, c2, attr);
}
set_empty_rows(wp, row);
}
#if defined(FEAT_FOLDING) || defined(PROTO)
/*
* Compute the width of the foldcolumn. Based on 'foldcolumn' and how much
* space is available for window "wp", minus "col".
*/
int
compute_foldcolumn(win_T *wp, int col)
{
int fdc = wp->w_p_fdc;
int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw;
int wwidth = wp->w_width;
if (fdc > wwidth - (col + wmw))
fdc = wwidth - (col + wmw);
return fdc;
}
/*
* Fill the foldcolumn at "p" for window "wp".
* Only to be called when 'foldcolumn' > 0.
* Returns the number of bytes stored in 'p'. When non-multibyte characters are
* used for the fold column markers, this is equal to 'fdc' setting. Otherwise,
* this will be greater than 'fdc'.
*/
size_t
fill_foldcolumn(
char_u *p,
win_T *wp,
int closed, // TRUE of FALSE
linenr_T lnum) // current line number
{
int i = 0;
int level;
int first_level;
int empty;
int fdc = compute_foldcolumn(wp, 0);
size_t byte_counter = 0;
int symbol = 0;
int len = 0;
// Init to all spaces.
vim_memset(p, ' ', MAX_MCO * fdc + 1);
level = win_foldinfo.fi_level;
empty = (fdc == 1) ? 0 : 1;
// If the column is too narrow, we start at the lowest level that
// fits and use numbers to indicate the depth.
first_level = level - fdc - closed + 1 + empty;
if (first_level < 1)
first_level = 1;
for (i = 0; i < MIN(fdc, level); i++)
{
if (win_foldinfo.fi_lnum == lnum
&& first_level + i >= win_foldinfo.fi_low_level)
symbol = wp->w_fill_chars.foldopen;
else if (first_level == 1)
symbol = wp->w_fill_chars.foldsep;
else if (first_level + i <= 9)
symbol = '0' + first_level + i;
else
symbol = '>';
len = utf_char2bytes(symbol, &p[byte_counter]);
byte_counter += len;
if (first_level + i >= level)
{
i++;
break;
}
}
if (closed)
{
if (symbol != 0)
{
// rollback length and the character
byte_counter -= len;
if (len > 1)
// for a multibyte character, erase all the bytes
vim_memset(p + byte_counter, ' ', len);
}
symbol = wp->w_fill_chars.foldclosed;
len = utf_char2bytes(symbol, &p[byte_counter]);
byte_counter += len;
}
return MAX(byte_counter + (fdc - i), (size_t)fdc);
}
#endif // FEAT_FOLDING
/*
* Return if the composing characters at "off_from" and "off_to" differ.
* Only to be used when ScreenLinesUC[off_from] != 0.
*/
static int
comp_char_differs(int off_from, int off_to)
{
int i;
for (i = 0; i < Screen_mco; ++i)
{
if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to])
return TRUE;
if (ScreenLinesC[i][off_from] == 0)
break;
}
return FALSE;
}
/*
* Check whether the given character needs redrawing:
* - the (first byte of the) character is different
* - the attributes are different
* - the character is multi-byte and the next byte is different
* - the character is two cells wide and the second cell differs.
*/
static int
char_needs_redraw(int off_from, int off_to, int cols)
{
if (cols > 0
&& ((ScreenLines[off_from] != ScreenLines[off_to]
|| ScreenAttrs[off_from] != ScreenAttrs[off_to])
|| (enc_dbcs != 0
&& MB_BYTE2LEN(ScreenLines[off_from]) > 1
&& (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e
? ScreenLines2[off_from] != ScreenLines2[off_to]
: (cols > 1 && ScreenLines[off_from + 1]
!= ScreenLines[off_to + 1])))
|| (enc_utf8
&& (ScreenLinesUC[off_from] != ScreenLinesUC[off_to]
|| (ScreenLinesUC[off_from] != 0
&& comp_char_differs(off_from, off_to))
|| ((*mb_off2cells)(off_from, off_from + cols) > 1
&& ScreenLines[off_from + 1]
!= ScreenLines[off_to + 1])))))
return TRUE;
return FALSE;
}
#if defined(FEAT_TERMINAL) || defined(PROTO)
/*
* Return the index in ScreenLines[] for the current screen line.
*/
int
screen_get_current_line_off(void)
{
return (int)(current_ScreenLine - ScreenLines);
}
#endif
#ifdef FEAT_PROP_POPUP
/*
* Return TRUE if this position has a higher level popup or this cell is
* transparent in the current popup.
*/
static int
blocked_by_popup(int row, int col)
{
int off;
if (!popup_visible)
return FALSE;
off = row * screen_Columns + col;
return popup_mask[off] > screen_zindex || popup_transparent[off];
}
#endif
/*
* Reset the highlighting. Used before clearing the screen.
*/
void
reset_screen_attr(void)
{
#ifdef FEAT_GUI
if (gui.in_use)
// Use a code that will reset gui.highlight_mask in
// gui_stop_highlight().
screen_attr = HL_ALL + 1;
else
#endif
// Use attributes that is very unlikely to appear in text.
screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE | HL_STRIKETHROUGH;
}
/*
* Return TRUE if the character at "row" / "col" is under the popup menu and it
* will be redrawn soon or it is under another popup.
*/
static int
skip_for_popup(int row, int col)
{
// Popup windows with zindex higher than POPUPMENU_ZINDEX go on top.
if (pum_under_menu(row, col, TRUE)
#ifdef FEAT_PROP_POPUP
&& screen_zindex <= POPUPMENU_ZINDEX
#endif
)
return TRUE;
#ifdef FEAT_PROP_POPUP
if (blocked_by_popup(row, col))
return TRUE;
#endif
return FALSE;
}
/*
* Move one "cooked" screen line to the screen, but only the characters that
* have actually changed. Handle insert/delete character.
* "coloff" gives the first column on the screen for this line.
* "endcol" gives the columns where valid characters are.
* "clear_width" is the width of the window. It's > 0 if the rest of the line
* needs to be cleared, negative otherwise.
* "flags" can have bits:
* SLF_POPUP popup window
* SLF_RIGHTLEFT rightleft window:
* When TRUE and "clear_width" > 0, clear columns 0 to "endcol"
* When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width"
* SLF_INC_VCOL:
* When FALSE, use "last_vcol" for ScreenCols[] of the columns to clear.
* When TRUE, use an increasing sequence starting from "last_vcol + 1" for
* ScreenCols[] of the columns to clear.
*/
void
screen_line(
win_T *wp,
int row,
int coloff,
int endcol,
int clear_width,
colnr_T last_vcol,
int flags UNUSED)
{
unsigned off_from;
unsigned off_to;
unsigned max_off_from;
unsigned max_off_to;
int col = 0;
int hl;
int force = FALSE; // force update rest of the line
int redraw_this // bool: does character need redraw?
#ifdef FEAT_GUI
= TRUE // For GUI when while-loop empty
#endif
;
int redraw_next; // redraw_this for next character
#ifdef FEAT_GUI_MSWIN
int changed_this; // TRUE if character changed
int changed_next; // TRUE if next character changed
#endif
int clear_next = FALSE;
int char_cells; // 1: normal char
// 2: occupies two display cells
// Check for illegal row and col, just in case.
if (row >= Rows)
row = Rows - 1;
if (endcol > Columns)
endcol = Columns;
# ifdef FEAT_CLIPBOARD
clip_may_clear_selection(row, row);
# endif
off_from = (unsigned)(current_ScreenLine - ScreenLines);
off_to = LineOffset[row] + coloff;
max_off_from = off_from + screen_Columns;
max_off_to = LineOffset[row] + screen_Columns;
#ifdef FEAT_RIGHTLEFT
if (flags & SLF_RIGHTLEFT)
{
// Clear rest first, because it's left of the text.
if (clear_width > 0)
{
int clear_start = col;
while (col <= endcol && ScreenLines[off_to] == ' '
&& ScreenAttrs[off_to] == 0
&& (!enc_utf8 || ScreenLinesUC[off_to] == 0))
{
++off_to;
++col;
}
if (col <= endcol)
screen_fill(row, row + 1, col + coloff,
endcol + coloff + 1, ' ', ' ', 0);
for (int i = endcol; i >= clear_start; i--)
ScreenCols[off_to + (i - col)] =
(flags & SLF_INC_VCOL) ? ++last_vcol : last_vcol;
}
col = endcol + 1;
off_to = LineOffset[row] + col + coloff;
off_from += col;
endcol = (clear_width > 0 ? clear_width : -clear_width);
}
#endif // FEAT_RIGHTLEFT
#ifdef FEAT_PROP_POPUP
// First char of a popup window may go on top of the right half of a
// double-wide character. Clear the left half to avoid it getting the popup
// window background color.
if (coloff > 0 && enc_utf8
&& ScreenLines[off_to] == 0
&& ScreenLinesUC[off_to - 1] != 0
&& (*mb_char2cells)(ScreenLinesUC[off_to - 1]) > 1)
{
ScreenLines[off_to - 1] = ' ';
ScreenLinesUC[off_to - 1] = 0;
screen_char(off_to - 1, row, col + coloff - 1);
}
#endif
redraw_next = char_needs_redraw(off_from, off_to, endcol - col);
#ifdef FEAT_GUI_MSWIN
changed_next = redraw_next;
#endif
while (col < endcol)
{
if (has_mbyte && (col + 1 < endcol))
char_cells = (*mb_off2cells)(off_from, max_off_from);
else
char_cells = 1;
redraw_this = redraw_next;
redraw_next = force || char_needs_redraw(off_from + char_cells,
off_to + char_cells, endcol - col - char_cells);
#ifdef FEAT_GUI
# ifdef FEAT_GUI_MSWIN
changed_this = changed_next;
changed_next = redraw_next;
# endif
// If the next character was bold, then redraw the current character to
// remove any pixels that might have spilt over into us. This only
// happens in the GUI.
// With MS-Windows antialiasing may also cause pixels to spill over
// from a previous character, no matter attributes, always redraw if a
// character changed.
if (redraw_next && gui.in_use)
{
# ifndef FEAT_GUI_MSWIN
hl = ScreenAttrs[off_to + char_cells];
if (hl > HL_ALL)
hl = syn_attr2attr(hl);
if (hl & HL_BOLD)
# endif
redraw_this = TRUE;
}
#endif
// Do not redraw if under the popup menu.
if (redraw_this && skip_for_popup(row, col + coloff))
redraw_this = FALSE;
if (redraw_this)
{
/*
* Special handling when 'xs' termcap flag set (hpterm):
* Attributes for characters are stored at the position where the
* cursor is when writing the highlighting code. The
* start-highlighting code must be written with the cursor on the
* first highlighted character. The stop-highlighting code must
* be written with the cursor just after the last highlighted
* character.
* Overwriting a character doesn't remove its highlighting. Need
* to clear the rest of the line, and force redrawing it
* completely.
*/
if ( p_wiv
&& !force
#ifdef FEAT_GUI
&& !gui.in_use
#endif
&& ScreenAttrs[off_to] != 0
&& ScreenAttrs[off_from] != ScreenAttrs[off_to])
{
/*
* Need to remove highlighting attributes here.
*/
windgoto(row, col + coloff);
out_str(T_CE); // clear rest of this screen line
screen_start(); // don't know where cursor is now
force = TRUE; // force redraw of rest of the line
redraw_next = TRUE; // or else next char would miss out
/*
* If the previous character was highlighted, need to stop
* highlighting at this character.
*/
if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0)
{
screen_attr = ScreenAttrs[off_to - 1];
term_windgoto(row, col + coloff);
screen_stop_highlight();
}
else
screen_attr = 0; // highlighting has stopped
}
if (enc_dbcs != 0)
{
// Check if overwriting a double-byte with a single-byte or
// the other way around requires another character to be
// redrawn. For UTF-8 this isn't needed, because comparing
// ScreenLinesUC[] is sufficient.
if (char_cells == 1
&& col + 1 < endcol
&& (*mb_off2cells)(off_to, max_off_to) > 1)
{
// Writing a single-cell character over a double-cell
// character: need to redraw the next cell.
ScreenLines[off_to + 1] = 0;
redraw_next = TRUE;
}
else if (char_cells == 2
&& col + 2 < endcol
&& (*mb_off2cells)(off_to, max_off_to) == 1
&& (*mb_off2cells)(off_to + 1, max_off_to) > 1)
{
// Writing the second half of a double-cell character over
// a double-cell character: need to redraw the second
// cell.
ScreenLines[off_to + 2] = 0;
redraw_next = TRUE;
}
if (enc_dbcs == DBCS_JPNU)
ScreenLines2[off_to] = ScreenLines2[off_from];
}
// When writing a single-width character over a double-width
// character and at the end of the redrawn text, need to clear out
// the right half of the old character.
// Also required when writing the right half of a double-width
// char over the left half of an existing one.
if (has_mbyte && col + char_cells == endcol
&& ((char_cells == 1
&& (*mb_off2cells)(off_to, max_off_to) > 1)
|| (char_cells == 2
&& (*mb_off2cells)(off_to, max_off_to) == 1
&& (*mb_off2cells)(off_to + 1, max_off_to) > 1)))
clear_next = TRUE;
ScreenLines[off_to] = ScreenLines[off_from];
if (enc_utf8)
{
ScreenLinesUC[off_to] = ScreenLinesUC[off_from];
if (ScreenLinesUC[off_from] != 0)
{
int i;
for (i = 0; i < Screen_mco; ++i)
ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from];
}
}
if (char_cells == 2)
ScreenLines[off_to + 1] = ScreenLines[off_from + 1];
#if defined(FEAT_GUI) || defined(UNIX)
// The bold trick makes a single column of pixels appear in the
// next character. When a bold character is removed, the next
// character should be redrawn too. This happens for our own GUI
// and for some xterms.
if (
# ifdef FEAT_GUI
gui.in_use
# endif
# if defined(FEAT_GUI) && defined(UNIX)
||
# endif
# ifdef UNIX
term_is_xterm
# endif
)
{
hl = ScreenAttrs[off_to];
if (hl > HL_ALL)
hl = syn_attr2attr(hl);
if (hl & HL_BOLD)
redraw_next = TRUE;
}
#endif
#ifdef FEAT_GUI_MSWIN
// MS-Windows antialiasing may spill over to the next character,
// redraw that one if this one changed, no matter attributes.
if (gui.in_use && changed_this)
redraw_next = TRUE;
#endif
ScreenAttrs[off_to] = ScreenAttrs[off_from];
// For simplicity set the attributes of second half of a
// double-wide character equal to the first half.
if (char_cells == 2)
ScreenAttrs[off_to + 1] = ScreenAttrs[off_from];
if (enc_dbcs != 0 && char_cells == 2)
screen_char_2(off_to, row, col + coloff);
else
screen_char(off_to, row, col + coloff);
}
else if ( p_wiv
#ifdef FEAT_GUI
&& !gui.in_use
#endif
&& col + coloff > 0)
{
if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1])
{
/*
* Don't output stop-highlight when moving the cursor, it will
* stop the highlighting when it should continue.
*/
screen_attr = 0;
}
else if (screen_attr != 0)
screen_stop_highlight();
}
ScreenCols[off_to] = ScreenCols[off_from];
if (char_cells == 2)
ScreenCols[off_to + 1] = ScreenCols[off_from + 1];
off_to += char_cells;
off_from += char_cells;
col += char_cells;
}
if (clear_next && !skip_for_popup(row, col + coloff))
{
// Clear the second half of a double-wide character of which the left
// half was overwritten with a single-wide character.
ScreenLines[off_to] = ' ';
if (enc_utf8)
ScreenLinesUC[off_to] = 0;
screen_char(off_to, row, col + coloff);
}
if (clear_width > 0
#ifdef FEAT_RIGHTLEFT
&& !(flags & SLF_RIGHTLEFT)
#endif
)
{
#ifdef FEAT_GUI
int startCol = col;
#endif
// blank out the rest of the line
while (col < clear_width && ScreenLines[off_to] == ' '
&& ScreenAttrs[off_to] == 0
&& (!enc_utf8 || ScreenLinesUC[off_to] == 0))
{
ScreenCols[off_to] =
(flags & SLF_INC_VCOL) ? ++last_vcol : last_vcol;
++off_to;
++col;
}
if (col < clear_width)
{
#ifdef FEAT_GUI
/*
* In the GUI, clearing the rest of the line may leave pixels
* behind if the first character cleared was bold. Some bold
* fonts spill over the left. In this case we redraw the previous
* character too. If we didn't skip any blanks above, then we
* only redraw if the character wasn't already redrawn anyway.
*/
if (gui.in_use && (col > startCol || !redraw_this))
{
hl = ScreenAttrs[off_to];
if (hl > HL_ALL || (hl & HL_BOLD))
{
int prev_cells = 1;
if (enc_utf8)
// for utf-8, ScreenLines[char_offset + 1] == 0 means
// that its width is 2.
prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1;
else if (enc_dbcs != 0)
{
// find previous character by counting from first
// column and get its width.
unsigned off = LineOffset[row];
unsigned max_off = LineOffset[row] + screen_Columns;
while (off < off_to)
{
prev_cells = (*mb_off2cells)(off, max_off);
off += prev_cells;
}
}
if (!skip_for_popup(row, col + coloff - prev_cells))
{
if (enc_dbcs != 0 && prev_cells > 1)
screen_char_2(off_to - prev_cells, row,
col + coloff - prev_cells);
else
screen_char(off_to - prev_cells, row,
col + coloff - prev_cells);
}
}
}
#endif
screen_fill(row, row + 1, col + coloff, clear_width + coloff,
' ', ' ', 0);
while (col < clear_width)
{
ScreenCols[off_to++]
= (flags & SLF_INC_VCOL) ? ++last_vcol : last_vcol;
++col;
}
}
}
if (clear_width > 0
#ifdef FEAT_PROP_POPUP
&& !(flags & SLF_POPUP) // no separator for popup window
#endif
)
{
// For a window that has a right neighbor, draw the separator char
// right of the window contents. But not on top of a popup window.
if (coloff + col < Columns)
{
if (!skip_for_popup(row, col + coloff))
{
int c;
c = fillchar_vsep(&hl, wp);
if (ScreenLines[off_to] != (schar_T)c
|| (enc_utf8 && (int)ScreenLinesUC[off_to]
!= (c >= 0x80 ? c : 0))
|| ScreenAttrs[off_to] != hl)
{
ScreenLines[off_to] = c;
ScreenAttrs[off_to] = hl;
if (enc_utf8)
{
if (c >= 0x80)
{
ScreenLinesUC[off_to] = c;
ScreenLinesC[0][off_to] = 0;
}
else
ScreenLinesUC[off_to] = 0;
}
screen_char(off_to, row, col + coloff);
}
}
}
else
LineWraps[row] = FALSE;
}
}
#if defined(FEAT_RIGHTLEFT) || defined(PROTO)
/*
* Mirror text "str" for right-left displaying.
* Only works for single-byte characters (e.g., numbers).
*/
void
rl_mirror(char_u *str)
{
char_u *p1, *p2;
int t;
for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2)
{
t = *p1;
*p1 = *p2;
*p2 = t;
}
}
#endif
/*
* Draw the verticap separator right of window "wp" starting with line "row".
*/
void
draw_vsep_win(win_T *wp, int row)
{
int hl;
int c;
if (!wp->w_vsep_width)
return;
// draw the vertical separator right of this window
c = fillchar_vsep(&hl, wp);
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height,
W_ENDCOL(wp), W_ENDCOL(wp) + 1,
c, ' ', hl);
}
/*
* Return TRUE if the status line of window "wp" is connected to the status
* line of the window right of it. If not, then it's a vertical separator.
* Only call if (wp->w_vsep_width != 0).
*/
int
stl_connected(win_T *wp)
{
frame_T *fr;
fr = wp->w_frame;
while (fr->fr_parent != NULL)
{
if (fr->fr_parent->fr_layout == FR_COL)
{
if (fr->fr_next != NULL)
break;
}
else
{
if (fr->fr_next != NULL)
return TRUE;
}
fr = fr->fr_parent;
}
return FALSE;
}
/*
* Get the value to show for the language mappings, active 'keymap'.
*/
int
get_keymap_str(
win_T *wp,
char_u *fmt, // format string containing one %s item
char_u *buf, // buffer for the result
int len) // length of buffer
{
char_u *p;
if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP)
return FALSE;
#ifdef FEAT_EVAL
buf_T *old_curbuf = curbuf;
win_T *old_curwin = curwin;
char_u *s;
curbuf = wp->w_buffer;
curwin = wp;
STRCPY(buf, "b:keymap_name"); // must be writable
++emsg_skip;
s = p = eval_to_string(buf, FALSE, FALSE);
--emsg_skip;
curbuf = old_curbuf;
curwin = old_curwin;
if (p == NULL || *p == NUL)
#endif
{
#ifdef FEAT_KEYMAP
if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED)
p = wp->w_buffer->b_p_keymap;
else
#endif
p = (char_u *)"lang";
}
if (vim_snprintf((char *)buf, len, (char *)fmt, p) > len - 1)
buf[0] = NUL;
#ifdef FEAT_EVAL