Line |
Branch |
Exec |
Source |
1 |
|
|
#ifndef VIEW_H |
2 |
|
|
#define VIEW_H |
3 |
|
|
|
4 |
|
|
#include <limits.h> |
5 |
|
|
#include <stdbool.h> |
6 |
|
|
#include <sys/types.h> |
7 |
|
|
#include "block-iter.h" |
8 |
|
|
#include "util/macros.h" |
9 |
|
|
#include "util/string-view.h" |
10 |
|
|
#include "util/string.h" |
11 |
|
|
|
12 |
|
|
typedef enum { |
13 |
|
|
SELECT_NONE, |
14 |
|
|
SELECT_CHARS, |
15 |
|
|
SELECT_LINES, |
16 |
|
|
} SelectionType; |
17 |
|
|
|
18 |
|
|
/* |
19 |
|
|
* A view into a Buffer, with its own cursor position and selection. |
20 |
|
|
* Visually speaking, each tab in a Window corresponds to a View and |
21 |
|
|
* if there are multiple Windows there may be multiple Views of the |
22 |
|
|
* same Buffer (see Buffer::views). |
23 |
|
|
*/ |
24 |
|
|
typedef struct View { |
25 |
|
|
struct Buffer *buffer; |
26 |
|
|
struct Window *window; |
27 |
|
|
BlockIter cursor; |
28 |
|
|
long cx; // Cursor x, in bytes |
29 |
|
|
long cy; // Cursor y |
30 |
|
|
long cx_display; // Cursor x, in terminal columns (see u_char_width()) |
31 |
|
|
long cx_char; // Cursor x, in Unicode codepoints (invalid UTF-8 byte is counted as 1) |
32 |
|
|
long vx, vy; // Top left corner (what cx/cy would be, if cursor was at top left of screen) |
33 |
|
|
long preferred_x; // Preferred value for cx_display (after vertical cursor movement) |
34 |
|
|
int tt_width; // Tab title width |
35 |
|
|
int tt_truncated_width; |
36 |
|
|
bool center_on_scroll; // Center view to cursor if scrolled |
37 |
|
|
bool force_center; // Force centering view to cursor |
38 |
|
|
|
39 |
|
|
SelectionType selection; // Type of selection currently active in this View |
40 |
|
|
SelectionType select_mode; // State of "selection mode" in this View (see dterc(5)) |
41 |
|
|
ssize_t sel_so; // Cursor offset when selection was started |
42 |
|
|
ssize_t sel_eo; // See `SEL_EO_RECALC` below |
43 |
|
|
|
44 |
|
|
// Used to save cursor state when multiple views share same buffer |
45 |
|
|
bool restore_cursor; |
46 |
|
|
size_t saved_cursor_offset; |
47 |
|
|
} View; |
48 |
|
|
|
49 |
|
|
// If View::sel_eo is set to this value it means the offset must |
50 |
|
|
// be calculated from the cursor iterator. Otherwise the offset |
51 |
|
|
// is precalculated and may not be the same as the cursor position |
52 |
|
|
// (see search/replace code). |
53 |
|
|
#define SEL_EO_RECALC SSIZE_MAX |
54 |
|
|
|
55 |
|
1483 |
static inline void view_reset_preferred_x(View *view) |
56 |
|
|
{ |
57 |
|
1483 |
view->preferred_x = -1; |
58 |
|
1483 |
} |
59 |
|
|
|
60 |
|
|
void view_update_cursor_y(View *view) NONNULL_ARGS; |
61 |
|
|
void view_update_cursor_x(View *view) NONNULL_ARGS; |
62 |
|
|
void view_update(View *view) NONNULL_ARGS; |
63 |
|
|
long view_get_preferred_x(View *view) NONNULL_ARGS; |
64 |
|
|
bool view_can_close(const View *view) NONNULL_ARGS; |
65 |
|
|
StringView view_get_word_under_cursor(const View *view) NONNULL_ARGS; |
66 |
|
|
size_t get_bounds_for_word_under_cursor(StringView line, size_t *cursor_offset); |
67 |
|
|
String dump_buffer(const View *view) NONNULL_ARGS; |
68 |
|
|
|
69 |
|
|
#endif |
70 |
|
|
|