diff options
| author | Albert Cervin <albert@acervin.com> | 2023-07-12 16:20:50 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-10-19 22:41:33 +0200 |
| commit | 54c9b4b533210b77be998f458ff96bdc54272f64 (patch) | |
| tree | eb434343bb1083172af50b7372d1e2745af00f8f /src/dged/buffer_view.h | |
| parent | 3a8ae83aa13636679c151027cace905fa87ebd8e (diff) | |
| download | dged-54c9b4b533210b77be998f458ff96bdc54272f64.tar.gz dged-54c9b4b533210b77be998f458ff96bdc54272f64.tar.xz dged-54c9b4b533210b77be998f458ff96bdc54272f64.zip | |
big buffer/buffer_view rework
A buffer is only the text and the corresponding operation. A buffer view
holds information about scroll, dot and mark positions. One way to think
about it is that a buffer is stateless whereas a buffer view is stateful.
Diffstat (limited to 'src/dged/buffer_view.h')
| -rw-r--r-- | src/dged/buffer_view.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/dged/buffer_view.h b/src/dged/buffer_view.h new file mode 100644 index 0000000..0002b95 --- /dev/null +++ b/src/dged/buffer_view.h @@ -0,0 +1,100 @@ +#ifndef _BUFFER_VIEW_H +#define _BUFFER_VIEW_H + +#include <stddef.h> + +#include "location.h" + +struct buffer; + +/** + * A view of a buffer. + * + * This contains the mark and dot as well as the scroll position for a buffer. + */ +struct buffer_view { + /** Location of dot (cursor) */ + struct location dot; + + /** Location of mark (where a selection starts) */ + struct location mark; + + /** Current buffer scroll position */ + struct location scroll; + + /** Pointer to the actual buffer */ + struct buffer *buffer; + + /** Modeline buffer (may be NULL) */ + struct modeline *modeline; + + /** Current left fringe size */ + uint32_t fringe_width; + + /** Does the buffer show line numbers */ + bool line_numbers; + + /** True if the start of a selection has been set */ + bool mark_set; +}; + +struct buffer_view buffer_view_create(struct buffer *buffer, bool modeline, + bool line_numbers); +struct buffer_view buffer_view_clone(const struct buffer_view *view); +void buffer_view_destroy(struct buffer_view *view); + +void buffer_view_add(struct buffer_view *view, uint8_t *txt, uint32_t nbytes); + +void buffer_view_goto_beginning(struct buffer_view *view); +void buffer_view_goto_end(struct buffer_view *view); +void buffer_view_goto(struct buffer_view *view, struct location to); +void buffer_view_goto_end_of_line(struct buffer_view *view); +void buffer_view_goto_beginning_of_line(struct buffer_view *view); + +void buffer_view_forward_char(struct buffer_view *view); +void buffer_view_backward_char(struct buffer_view *view); +void buffer_view_forward_word(struct buffer_view *view); +void buffer_view_backward_word(struct buffer_view *view); +void buffer_view_forward_line(struct buffer_view *view); +void buffer_view_backward_line(struct buffer_view *view); +void buffer_view_forward_nlines(struct buffer_view *view, uint32_t nlines); +void buffer_view_backward_nlines(struct buffer_view *view, uint32_t nlines); + +void buffer_view_forward_delete_char(struct buffer_view *view); +void buffer_view_backward_delete_char(struct buffer_view *view); +void buffer_view_forward_delete_word(struct buffer_view *view); +void buffer_view_backward_delete_word(struct buffer_view *view); + +void buffer_view_kill_line(struct buffer_view *view); + +void buffer_view_newline(struct buffer_view *view); +void buffer_view_indent(struct buffer_view *view); + +void buffer_view_copy(struct buffer_view *view); +void buffer_view_cut(struct buffer_view *view); +void buffer_view_paste(struct buffer_view *view); +void buffer_view_paste_older(struct buffer_view *view); + +void buffer_view_set_mark(struct buffer_view *view); +void buffer_view_clear_mark(struct buffer_view *view); +void buffer_view_set_mark_at(struct buffer_view *view, struct location mark); + +struct location buffer_view_dot_to_relative(struct buffer_view *view); + +void buffer_view_undo(struct buffer_view *view); + +struct buffer_view_update_params { + struct command_list *commands; + void *(*frame_alloc)(size_t); + uint32_t window_id; + int64_t frame_time; + uint32_t width; + uint32_t height; + uint32_t window_x; + uint32_t window_y; +}; + +void buffer_view_update(struct buffer_view *view, + struct buffer_view_update_params *params); + +#endif |
