| 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 | unsigned int tt_width; // Tab title width | ||
| 35 | unsigned 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 | typedef struct { | ||
| 50 | size_t start; | ||
| 51 | size_t end; | ||
| 52 | } WordBounds; | ||
| 53 | |||
| 54 | // If View::sel_eo is set to this value it means the offset must | ||
| 55 | // be calculated from the cursor iterator. Otherwise the offset | ||
| 56 | // is precalculated and may not be the same as the cursor position | ||
| 57 | // (see search/replace code). | ||
| 58 | #define SEL_EO_RECALC SSIZE_MAX | ||
| 59 | |||
| 60 | 1484 | static inline void view_reset_preferred_x(View *view) | |
| 61 | { | ||
| 62 | 1484 | view->preferred_x = -1; | |
| 63 | 1484 | } | |
| 64 | |||
| 65 | void view_update_cursor_y(View *view) NONNULL_ARGS; | ||
| 66 | void view_update_cursor_x(View *view) NONNULL_ARGS; | ||
| 67 | void view_update(View *view) NONNULL_ARGS; | ||
| 68 | long view_get_preferred_x(View *view) NONNULL_ARGS; | ||
| 69 | bool view_can_close(const View *view) NONNULL_ARGS; | ||
| 70 | size_t view_remove(View *view) NONNULL_ARGS; | ||
| 71 | StringView view_get_word_under_cursor(const View *view) NONNULL_ARGS; | ||
| 72 | WordBounds get_bounds_for_word_under_cursor(CurrentLineRef lr); | ||
| 73 | String dump_buffer(const View *view) NONNULL_ARGS; | ||
| 74 | |||
| 75 | #endif | ||
| 76 |