aboutsummaryrefslogtreecommitdiff
path: root/view.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-07-23 14:38:45 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-07-26 12:13:44 +0200
commitd7a7a3efde175e944cc6943170c9f60467850060 (patch)
tree3d415c3b8892af2e453414fdcf73aace3285c2c9 /view.h
parent5e016233a9fe77258edd85a2dc746d20e6db46a0 (diff)
downloadvis-d7a7a3efde175e944cc6943170c9f60467850060.tar.gz
vis-d7a7a3efde175e944cc6943170c9f60467850060.tar.xz
vis: add infrastructure to support multiple cursors/selections
This cleans up the existing selection handling code and adds the necessary bits to eventually support multiple cursors/selections. The cursor position is kept track of using marks, which means retrieving the cursor position is no longer a constant time operation. Furthermore the terminal cursor is no longer used, instead the whole window is redrawn after every cursor movement.
Diffstat (limited to 'view.h')
-rw-r--r--view.h104
1 files changed, 69 insertions, 35 deletions
diff --git a/view.h b/view.h
index 0adec05..d993fbd 100644
--- a/view.h
+++ b/view.h
@@ -8,6 +8,8 @@
#include "syntax.h"
typedef struct View View;
+typedef struct Cursor Cursor;
+typedef struct Selection Selection;
typedef struct {
void *data;
@@ -24,7 +26,8 @@ typedef struct {
the same as in the underlying text, for example tabs get expanded */
unsigned int attr;
bool istab;
- bool selected;
+ bool selected; /* whether this cell is part of a selected region */
+ bool cursor; /* whether a cursor is currently locaated on the cell */
} Cell;
typedef struct Line Line;
@@ -55,13 +58,13 @@ void view_tabwidth_set(View*, int tabwidth);
/* cursor movements which also update selection if one is active.
* they return new cursor postion */
-size_t view_line_down(View*);
-size_t view_line_up(View*);
-size_t view_screenline_down(View*);
-size_t view_screenline_up(View*);
-size_t view_screenline_begin(View*);
-size_t view_screenline_middle(View*);
-size_t view_screenline_end(View*);
+size_t view_line_down(Cursor*);
+size_t view_line_up(Cursor*);
+size_t view_screenline_down(Cursor*);
+size_t view_screenline_up(Cursor*);
+size_t view_screenline_begin(Cursor*);
+size_t view_screenline_middle(Cursor*);
+size_t view_screenline_end(Cursor*);
/* move window content up/down, but keep cursor position unchanged unless it is
* on a now invisible line in which case we try to preserve the column position */
size_t view_slide_up(View*, int lines);
@@ -73,38 +76,11 @@ size_t view_scroll_down(View*, int lines);
/* place the cursor at the start ot the n-th window line, counting from 1 */
size_t view_screenline_goto(View*, int n);
-/* get cursor position in bytes from start of the file */
-size_t view_cursor_get(View*);
-
-typedef struct {
- int x, y;
-} ViewPos;
-
-ViewPos view_cursor_viewpos(View*);
-
const Line *view_lines_get(View*);
-/* get cursor position in terms of screen coordinates */
-CursorPos view_cursor_getpos(View*);
-/* moves window viewport in direction until pos is visible. should only be
- * used for short distances between current cursor position and destination */
-void view_scroll_to(View*, size_t pos);
-/* move cursor to a given position. changes the viewport to make sure that
- * position is visible. if the position is in the middle of a line, try to
- * adjust the viewport in such a way that the whole line is displayed */
-void view_cursor_to(View*, size_t pos);
/* redraw current cursor line at top/center/bottom of window */
void view_redraw_top(View*);
void view_redraw_center(View*);
void view_redraw_bottom(View*);
-/* start selected area at current cursor position. further cursor movements will
- * affect the selected region. */
-void view_selection_start(View*);
-/* returns the currently selected text region, is either empty or well defined,
- * i.e. sel.start <= sel.end */
-Filerange view_selection_get(View*);
-void view_selection_set(View*, Filerange *sel);
-/* clear selection and redraw window */
-void view_selection_clear(View*);
/* get the currently displayed area in bytes from the start of the file */
Filerange view_viewport_get(View*);
/* move visible viewport n-lines up/down, redraws the view but does not change
@@ -119,4 +95,62 @@ Syntax *view_syntax_get(View*);
void view_symbols_set(View*, int flags);
int view_symbols_get(View*);
+/* A view can manage multiple cursors, one of which (the main cursor) is always
+ * placed within the visible viewport. All functions named view_cursor_* operate
+ * on this cursor. Additional cursor can be created and manipulated using the
+ * functions named view_cursors_* */
+
+/* get main cursor position in terms of screen coordinates */
+CursorPos view_cursor_getpos(View*);
+/* get main cursor position in bytes from start of the file */
+size_t view_cursor_get(View*);
+/* moves window viewport in direction until pos is visible. should only be
+ * used for short distances between current cursor position and destination */
+void view_scroll_to(View*, size_t pos);
+/* move cursor to a given position. changes the viewport to make sure that
+ * position is visible. if the position is in the middle of a line, try to
+ * adjust the viewport in such a way that the whole line is displayed */
+void view_cursor_to(View*, size_t pos);
+/* create a new cursor */
+Cursor *view_cursors_new(View*);
+/* dispose an existing cursor */
+void view_cursors_free(Cursor*);
+/* only keep the main cursor, release all others together with their
+ * selections (if any) */
+void view_cursors_clear(View*);
+/* get the main cursor which is always in the visible viewport */
+Cursor *view_cursor(View*);
+/* get the first cursor */
+Cursor *view_cursors(View*);
+Cursor *view_cursors_prev(Cursor*);
+Cursor *view_cursors_next(Cursor*);
+/* get current position of cursor in bytes from the start of the file */
+size_t view_cursors_pos(Cursor*);
+/* place cursor at `pos' which should be in the interval [0, text-size] */
+void view_cursors_to(Cursor*, size_t pos);
+void view_cursors_scroll_to(Cursor*, size_t pos);
+/* start selected area at current cursor position. further cursor movements
+ * will affect the selected region. */
+void view_cursors_selection_start(Cursor*);
+/* detach cursor from selection, further cursor movements will not affect
+ * the selected region. */
+void view_cursors_selection_stop(Cursor*);
+/* clear selection associated with this cursor (if any) */
+void view_cursors_selection_clear(Cursor*);
+/* move cursor position from one end of the selection to the other */
+void view_cursors_selection_swap(Cursor*);
+/* get/set the selected region associated with this cursor */
+Filerange view_cursors_selection_get(Cursor*);
+void view_cursors_selection_set(Cursor*, Filerange*);
+
+Selection *view_selections_new(View*);
+void view_selections_free(Selection*);
+void view_selections_clear(View*);
+void view_selections_swap(Selection*);
+Selection *view_selections(View*);
+Selection *view_selections_prev(Selection*);
+Selection *view_selections_next(Selection*);
+Filerange view_selections_get(Selection*);
+void view_selections_set(Selection*, Filerange*);
+
#endif