aboutsummaryrefslogtreecommitdiff
path: root/src/sc_editor.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-11-26 09:55:46 +0100
committerThomas White <taw@bitwiz.org.uk>2015-11-26 09:55:46 +0100
commit3cbb8d0124e839136795ae8dcf475a5fbe86c093 (patch)
treeb3ddeed8d286b0b986338e29850c040a23ca1216 /src/sc_editor.c
parent81100c4e659c6b11f2e36f48a171325ddff76676 (diff)
WIP
Diffstat (limited to 'src/sc_editor.c')
-rw-r--r--src/sc_editor.c60
1 files changed, 37 insertions, 23 deletions
diff --git a/src/sc_editor.c b/src/sc_editor.c
index bdfc842..ed554c4 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -779,29 +779,6 @@ void insert_scblock(SCBlock *scblock, SCEditor *e)
static void update_local(SCEditor *e, struct frame *fr, int line, int bn)
{
struct wrap_box *box = &fr->lines[line].boxes[bn];
- const char *text;
- size_t len_bytes;
- int len_chars;
- PangoLogAttr *log_attrs;
- int offs;
-
- text = sc_block_contents(box->scblock);
- len_bytes = strlen(text);
- len_chars = g_utf8_strlen(text, -1);
-
- log_attrs = malloc((len_chars+1)*sizeof(PangoLogAttr));
- if ( log_attrs == NULL ) return;
- pango_get_log_attrs(text, len_bytes, -1, e->lang,
- log_attrs, len_chars+1);
-
- offs = box->offs_char + e->cursor_pos;
-
- if ( log_attrs[offs].is_line_break ) {
- printf("Just typed a break!\n");
- }
-
- free(log_attrs);
-
/* Shape the box again */
shape_box(box->cf->cf);
box->glyphs = box->cf->cf->glyphs;
@@ -840,6 +817,11 @@ static void insert_text(char *t, SCEditor *e)
int sln, sbx, sps;
struct wrap_box *sbox;
struct frame *fr = e->cursor_frame;
+ const char *text;
+ size_t len_bytes;
+ int len_chars;
+ PangoLogAttr *log_attrs;
+ int offs;
if ( fr == NULL ) return;
@@ -855,6 +837,38 @@ static void insert_text(char *t, SCEditor *e)
printf("sps=%i, offs_char=%i\n", sps, sbox->offs_char);
sc_insert_text(sbox->scblock, sps+sbox->offs_char, t);
+ text = sc_block_contents(sbox->scblock);
+ len_bytes = strlen(text);
+ len_chars = g_utf8_strlen(text, -1);
+
+ log_attrs = malloc((len_chars+1)*sizeof(PangoLogAttr));
+ if ( log_attrs == NULL ) return;
+ pango_get_log_attrs(text, len_bytes, -1, e->lang,
+ log_attrs, len_chars+1);
+
+ offs = sbox->offs_char + e->cursor_pos;
+
+ if ( log_attrs[offs+1].is_line_break ) {
+
+ struct wrap_box *nbox;
+
+ /* Add a new box containing the text after the break */
+ insert_box(&e->cursor_frame->lines[sln], sbx);
+ nbox = &e->cursor_frame->lines[sln].boxes[sbx];
+ nbox->type = WRAP_BOX_PANGO;
+ nbox->space = WRAP_SPACE_INTERWORD;
+ nbox->len_chars = e->cursor_pos;
+
+ /* Shorten the text in the first box */
+ sbox->len_chars -= e->cursor_pos;
+
+ shape_box(sbox);
+ //shape_box(nbox);
+
+ }
+
+ free(log_attrs);
+
/* Update the length of the box in the unwrapped and un-paragraph-split
* string of wrap boxes */
sbox->cf->cf->len_chars += 1;