aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2014-09-24 21:52:00 +0200
committerThomas White <taw@bitwiz.org.uk>2014-09-24 21:52:00 +0200
commit76e314488bb87404c358e96ab48e6ae4602c05c1 (patch)
treea0661a443a9f6373b85dbaf5a1ea5e7bda753cb5 /src
parent2aac89de6e1864e5b92990baa6ea1d24458a3e11 (diff)
Fix cursor behaviour
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.c90
-rw-r--r--src/wrap.c91
-rw-r--r--src/wrap.h2
3 files changed, 103 insertions, 80 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 63b29c0..4c6809d 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -1033,93 +1033,25 @@ void update_titlebar(struct presentation *p)
}
-static void cur_box_diag(struct presentation *p)
+static void fixup_cursor(struct presentation *p)
{
- int sln, sbx, sps;
- struct frame *fr;
-
- fr = p->cursor_frame;
- sln = p->cursor_line;
- sbx = p->cursor_box;
- sps = p->cursor_pos;
+ struct wrap_box *sbox;
- struct wrap_box *sbox = &p->cursor_frame->lines[sln].boxes[sbx];
+ sbox = &p->cursor_frame->lines[p->cursor_line].boxes[p->cursor_box];
- printf("line/box/pos: [%i of %i]/[%i of %i]/%i\n", sln, fr->n_lines,
- sbx, p->cursor_frame->lines[sln].n_boxes, sps);
- printf("box type is %i, space type is %i\n", sbox->type, sbox->space);
- if ( sbox->type == WRAP_BOX_NOTHING ) {
- printf("Warning: in a nothing box!\n");
+ if ( p->cursor_pos > sbox->len_chars ) {
+ advance_cursor(p);
}
}
static void move_cursor(struct presentation *p, signed int x, signed int y)
{
- cur_box_diag(p);
if ( x > 0 ) {
-
- int advance = 0;
- signed int cp, cb, cl;
- struct wrap_line *line = &p->cursor_frame->lines[p->cursor_line];
- struct wrap_box *box = &line->boxes[p->cursor_box];
-
- cp = p->cursor_pos;
- cb = p->cursor_box;
- cl = p->cursor_line;
-
- switch ( box->type ) {
-
- case WRAP_BOX_PANGO:
- if ( cp+1 > box->len_chars ) {
- advance = 1;
- } else {
- cp++;
- }
- break;
-
- case WRAP_BOX_NOTHING:
- case WRAP_BOX_SENTINEL:
- advance = 1;
- break;
-
- case WRAP_BOX_IMAGE:
- cp++;
- if ( cp > 1 ) advance = 1;
- break;
-
- }
-
- if ( advance ) {
-
- do {
-
- cb++;
- cp = 0;
-
- if ( cb >= line->n_boxes ) {
- cl++;
- if ( cl >= p->cursor_frame->n_lines ) {
- /* Give up - could not move */
- return;
- }
- line = &p->cursor_frame->lines[cl];
- cb = 0;
- cp = 0;
- }
-
- } while ( !line->boxes[cb].editable );
-
- p->cursor_line = cl;
- p->cursor_box = cb;
-
- }
- p->cursor_pos = cp;
-
+ advance_cursor(p);
} else {
move_cursor_back(p);
}
- cur_box_diag(p);
}
@@ -1139,15 +1071,15 @@ static void insert_text(char *t, struct presentation *p)
sps = p->cursor_pos;
sbox = &p->cursor_frame->lines[sln].boxes[sbx];
- cur_box_diag(p);
- printf("inserting block=%p, offset %i+%i, '%s'\n",
- sbox->scblock, sps, sbox->offs_char, t);
sc_insert_text(sbox->scblock, sps+sbox->offs_char, t);
- move_cursor(p, +1, 0);
fr->empty = 0;
rerender_slide(p);
+
+ fixup_cursor(p);
+ advance_cursor(p);
+
redraw_editor(p);
}
@@ -1166,9 +1098,7 @@ static void do_backspace(struct frame *fr, struct presentation *p)
sps = p->cursor_pos;
struct wrap_box *sbox = &p->cursor_frame->lines[sln].boxes[sbx];
- cur_box_diag(p);
move_cursor_back(p);
- cur_box_diag(p);
/* Delete may cross wrap boxes and maybe SCBlock boundaries */
struct wrap_line *fline = &p->cursor_frame->lines[p->cursor_line];
diff --git a/src/wrap.c b/src/wrap.c
index 2013f31..6d43557 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -213,6 +213,9 @@ void move_cursor_back(struct presentation *p)
box = &line->boxes[cb];
if ( box->type == WRAP_BOX_PANGO ) {
cp = box->len_chars;
+ if ( box->space == WRAP_SPACE_NONE ) {
+ cp--;
+ }
} else {
cp = 1;
}
@@ -222,6 +225,94 @@ void move_cursor_back(struct presentation *p)
}
+void cur_box_diag(struct presentation *p)
+{
+ int sln, sbx, sps;
+ struct frame *fr;
+
+ fr = p->cursor_frame;
+ sln = p->cursor_line;
+ sbx = p->cursor_box;
+ sps = p->cursor_pos;
+
+ struct wrap_box *sbox = &p->cursor_frame->lines[sln].boxes[sbx];
+
+ printf("line/box/pos: [%i of %i]/[%i of %i]/[%i of %i]\n",
+ sln, fr->n_lines,
+ sbx, p->cursor_frame->lines[sln].n_boxes,
+ sps, sbox->len_chars);
+ printf("box type is %i, space type is %i\n", sbox->type, sbox->space);
+ if ( sbox->type == WRAP_BOX_NOTHING ) {
+ printf("Warning: in a nothing box!\n");
+ }
+}
+
+
+void advance_cursor(struct presentation *p)
+{
+ int advance = 0;
+ signed int cp, cb, cl;
+ struct wrap_line *line = &p->cursor_frame->lines[p->cursor_line];
+ struct wrap_box *box = &line->boxes[p->cursor_box];
+
+ cp = p->cursor_pos;
+ cb = p->cursor_box;
+ cl = p->cursor_line;
+
+ switch ( box->type ) {
+
+ case WRAP_BOX_PANGO:
+ if ( cp+1 > box->len_chars ) {
+ advance = 1;
+ } else {
+ cp++;
+ }
+ break;
+
+ case WRAP_BOX_NOTHING:
+ case WRAP_BOX_SENTINEL:
+ advance = 1;
+ break;
+
+ case WRAP_BOX_IMAGE:
+ cp++;
+ if ( cp > 1 ) advance = 1;
+ break;
+
+ }
+
+ if ( advance ) {
+
+ do {
+
+ cb++;
+ cp = 0;
+
+ if ( box->space == WRAP_SPACE_NONE ) {
+ cp = 1;
+ }
+
+ if ( cb >= line->n_boxes ) {
+ cl++;
+ if ( cl >= p->cursor_frame->n_lines ) {
+ /* Give up - could not move */
+ return;
+ }
+ line = &p->cursor_frame->lines[cl];
+ cb = 0;
+ cp = 0;
+ }
+
+ } while ( !line->boxes[cb].editable );
+
+ p->cursor_line = cl;
+ p->cursor_box = cb;
+
+ }
+ p->cursor_pos = cp;
+}
+
+
static int find_cursor_line(struct frame *fr, double yposd, int *end)
{
int i;
diff --git a/src/wrap.h b/src/wrap.h
index bd45aa8..441ec62 100644
--- a/src/wrap.h
+++ b/src/wrap.h
@@ -106,6 +106,8 @@ extern void get_cursor_pos(struct wrap_box *box, int pos,
double *xposd, double *yposd, double *line_height);
extern void move_cursor_back(struct presentation *p);
+extern void cur_box_diag(struct presentation *p);
+extern void advance_cursor(struct presentation *p);
extern void find_cursor(struct frame *fr, double xposd, double yposd,
int *line, int *box, int *pos);