robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
3.3 KiB99 linesraw
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5
6#include "nvim/marktree_defs.h"
7#include "nvim/pos_defs.h"
8#include "nvim/types_defs.h"
9
10typedef bool CSType;
11
12enum {
13  kCharsizeRegular,
14  kCharsizeFast,
15};
16
17/// Argument for char size functions.
18typedef struct {
19  win_T *win;
20  char *line;                ///< Start of the line.
21
22  bool use_tabstop;          ///< Use 'tabstop' instead of char2cells() for a TAB.
23  int indent_width;          ///< Width of 'showbreak' and 'breakindent' on wrapped
24                             ///< parts of lines, INT_MIN if not yet calculated.
25
26  int virt_row;              ///< Row for virtual text, -1 if no virtual text.
27  bool skip_cur_text;        ///< Don't count inline text at the measured character or advance iter.
28                             ///< A CharsizeArg with this set cannot be reused for a later character.
29  int cur_text_width_left;   ///< Width of virtual text left of cursor.
30  int cur_text_width_right;  ///< Width of virtual text right of cursor.
31
32  int max_head_vcol;         ///< See charsize_regular().
33  MarkTreeIter iter[1];
34} CharsizeArg;
35
36typedef struct {
37  int width;
38  int head;  ///< Size of 'breakindent' etc. before the character (included in width).
39  int tail;  ///< Size of 'linebreak' after the character (included in width).
40} CharSize;
41
42#include "plines.h.generated.h"
43#include "plines.h.inline.generated.h"
44
45/// Get the number of cells taken up on the screen by the given character at vcol.
46/// "csarg->cur_text_width_left" and "csarg->cur_text_width_right" are set
47/// to the extra size for inline virtual text.
48///
49/// When "csarg->max_head_vcol" is positive, only count in "head" the size
50/// of 'showbreak'/'breakindent' before "csarg->max_head_vcol".
51/// When "csarg->max_head_vcol" is negative, only count in "head" the size
52/// of 'showbreak'/'breakindent' before where cursor should be placed.
53static inline CharSize win_charsize(CSType cstype, int vcol, char *ptr, int32_t chr,
54                                    CharsizeArg *csarg, int mb_width)
55  FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
56{
57  if (cstype == kCharsizeFast) {
58    return charsize_fast(csarg, ptr, vcol, chr, mb_width);
59  } else {
60    return charsize_regular(csarg, ptr, vcol, chr, mb_width);
61  }
62}
63
64/// Return the number of cells the string "s" will take on the screen,
65/// taking into account the size of a tab.
66///
67/// @param s
68///
69/// @return Number of cells the string will take on the screen.
70static inline int linetabsize_str(char *s)
71  FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
72{
73  return linetabsize_col(0, s);
74}
75
76/// Like linetabsize_str(), but for a given window instead of the current one.
77/// Doesn't count the size of 'listchars' "eol".
78///
79/// @param wp
80/// @param line
81/// @param len
82///
83/// @return Number of cells the string will take on the screen.
84static inline int win_linetabsize(win_T *wp, linenr_T lnum, char *line, colnr_T len)
85  FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
86{
87  CharsizeArg csarg;
88  CSType const cstype = init_charsize_arg(&csarg, wp, lnum, line);
89  if (cstype == kCharsizeFast) {
90    return linesize_fast(&csarg, 0, len);
91  } else {
92    return linesize_regular(&csarg, 0, len);
93  }
94}
95
96/// Flags used by getvcol()
97enum {
98  GETVCOL_END_EXCL_LBR = 1,
99};