aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2014-06-21 18:04:58 +0200
committerThomas White <taw@bitwiz.org.uk>2014-06-21 18:04:58 +0200
commit10d05eeeb2705c3918e27a98253e95a2d50fe189 (patch)
tree848ec0c2d7be583aff7b11815cb64dc079764a01
parentb36421467b4669dec503714bbf7be13fcfadc04e (diff)
Mostly working cursor logic
-rw-r--r--src/mainwindow.c14
-rw-r--r--src/sc_parse.c21
-rw-r--r--src/shape.c1
-rw-r--r--src/wrap.c4
-rw-r--r--src/wrap.h1
5 files changed, 24 insertions, 17 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 30f35e1..26c544f 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -1142,9 +1142,23 @@ static void do_backspace(struct frame *fr, struct presentation *p)
struct wrap_box *sbox = &p->cursor_frame->lines[sln].boxes[sbx];
struct wrap_line *fline = &p->cursor_frame->lines[p->cursor_line];
struct wrap_box *fbox = &fline->boxes[p->cursor_box];
+
+ SCBlock *scbl = sbox->scblock;
+ do {
+ show_sc_blocks(scbl);
+ scbl = sc_block_next(scbl);
+ } while ( (scbl != fbox->scblock) && (scbl != NULL) );
+
sc_delete_text(fbox->scblock, p->cursor_pos+fbox->offs_char,
sbox->scblock, sps+sbox->offs_char);
+ scbl = sbox->scblock;
+ do {
+ show_sc_blocks(scbl);
+ scbl = sc_block_next(scbl);
+ } while ( (scbl != fbox->scblock) && (scbl != NULL) );
+
+
rerender_slide(p);
redraw_editor(p);
}
diff --git a/src/sc_parse.c b/src/sc_parse.c
index fc6a40d..1d5c549 100644
--- a/src/sc_parse.c
+++ b/src/sc_parse.c
@@ -132,7 +132,7 @@ SCBlock *sc_block_append(SCBlock *bl, char *name, char *opt, char *contents,
}
-/* Frees "bl" and all its children, and links it out of its chain */
+/* Frees "bl" and all its children */
void sc_block_free(SCBlock *bl)
{
if ( bl->child != NULL ) {
@@ -381,13 +381,11 @@ SCBlock *sc_parse(const char *sc)
static void delete_from_block(SCBlock *b, int o1, int o2)
{
+ if ( o1 == o2 ) return; /* nothing to delete */
assert(o2 > o1);
char *p1 = g_utf8_offset_to_pointer(b->contents, o1);
char *p2 = g_utf8_offset_to_pointer(b->contents, o2);
- printf("'%s' (%p), chars %i to %i\n", b->contents, b->contents, o1, o2);
- printf("moving %i bytes from %p to %p\n", strlen(p2)+1, p2, p1);
memmove(p1, p2, strlen(p2)+1);
- printf("new: '%s'\n", b->contents);
}
@@ -408,23 +406,20 @@ static void delete_from_start(SCBlock *b, int offs)
/* Character offsets */
void sc_delete_text(SCBlock *b1, int o1, SCBlock *b2, int o2)
{
- printf("Before:\n");
- show_sc_blocks(b1);
if ( b1 == b2 ) {
- printf("--------> dfb\n");
delete_from_block(b1, o1, o2);
} else if ( b2 == b1->next ) {
- printf("--------> dte+dfs\n");
delete_to_end(b1, o1);
delete_from_start(b2, o2);
} else {
- printf("--------> dte+dfs+chain\n");
delete_to_end(b1, o1);
delete_from_start(b2, o2);
- while ( b1->next != b2 ) {
- sc_block_free(b1->next);
+ b1->next = b2;
+ SCBlock *de = b1->next;
+ while ( de != b2 ) {
+ SCBlock *denext = de->next;
+ sc_block_free(de);
+ de = denext;
}
}
- printf("After:\n");
- show_sc_blocks(b1);
}
diff --git a/src/shape.c b/src/shape.c
index e27db9a..8ae41ec 100644
--- a/src/shape.c
+++ b/src/shape.c
@@ -72,7 +72,6 @@ static void add_wrap_box(gpointer vi, gpointer vb)
box->scblock = bas->bl;
box->offs_char = g_utf8_pointer_to_offset(bas->text,
bas->text+item->offset+bas->offs);
- box->len_bytes = item->length;
box->len_chars = g_utf8_strlen(bas->text+item->offset+bas->offs,
item->length);
col = sc_interp_get_fgcol(bas->scin);
diff --git a/src/wrap.c b/src/wrap.c
index 084bf24..8c81295 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -146,7 +146,7 @@ void get_cursor_pos(struct wrap_box *box, size_t pos,
box_text = g_utf8_offset_to_pointer(block_text, box->offs_char);
/* cast because this function is not const-clean */
pango_glyph_string_index_to_x(box->glyphs, (char *)box_text,
- box->len_bytes,
+ strlen(box_text),
&box->item->analysis, pos,
FALSE, &p);
*xposd += pango_units_to_double(p);
@@ -311,7 +311,7 @@ void find_cursor(struct frame *fr, double xposd, double yposd,
box_text = g_utf8_offset_to_pointer(block_text, b->offs_char);
/* cast because this function is not const-clean */
pango_glyph_string_x_to_index(b->glyphs, (char *)box_text,
- b->len_bytes,
+ strlen(box_text),
&b->item->analysis,
x_pos_i, &idx, &trail);
offs = idx + trail;
diff --git a/src/wrap.h b/src/wrap.h
index 98ed632..cb3b610 100644
--- a/src/wrap.h
+++ b/src/wrap.h
@@ -77,7 +77,6 @@ struct wrap_box
PangoItem *item;
PangoFont *font;
double col[4]; /* rgba colour */
- size_t len_bytes; /* number of bytes (not characters) of text */
int len_chars;
/* For type == WRAP_BOX_IMAGE */