aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frame.c21
-rw-r--r--src/frame.h2
-rw-r--r--src/sc_editor.c33
3 files changed, 55 insertions, 1 deletions
diff --git a/src/frame.c b/src/frame.c
index 6323872..fbfd1f2 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -959,3 +959,24 @@ SCBlock *block_at_cursor(struct frame *fr, int pn, size_t pos)
return para->macro_real_scblock;
}
+
+
+int get_sc_pos(struct frame *fr, int pn, size_t pos,
+ SCBlock **bl, size_t *ppos)
+{
+ Paragraph *para = fr->paras[pn];
+ int nrun;
+ struct text_run *run;
+
+ nrun = which_run(para, pos);
+ if ( nrun == para->n_runs ) {
+ fprintf(stderr, "Couldn't find run to insert into.\n");
+ return 1;
+ }
+ run = &para->runs[nrun];
+
+ *ppos = run->scblock_offs_bytes + pos - run->para_offs_bytes;
+ *bl = run->scblock;
+
+ return 0;
+}
diff --git a/src/frame.h b/src/frame.h
index 0ed7f88..907a910 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -156,4 +156,6 @@ extern SCBlock *split_paragraph(struct frame *fr, int pn, size_t pos,
PangoContext *pc);
extern SCBlock *block_at_cursor(struct frame *fr, int para, size_t pos);
+extern int get_sc_pos(struct frame *fr, int pn, size_t pos,
+ SCBlock **bl, size_t *ppos);
#endif /* FRAME_H */
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 4dfec35..941c822 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -1125,7 +1125,6 @@ static void copy_selection(SCEditor *e)
if ( bl == NULL ) return;
storycode = serialise_sc_block(bl);
- printf("Got '%s'\n", storycode);
cb = gtk_clipboard_get(GDK_NONE);
gtk_clipboard_set_text(cb, storycode, -1);
@@ -1133,6 +1132,30 @@ static void copy_selection(SCEditor *e)
}
+static void paste_callback(GtkClipboard *cb, const gchar *text, void *vp)
+{
+ SCEditor *e = vp;
+ SCBlock *bl = sc_parse(text);
+ SCBlock *cur_bl;
+ size_t cur_sc_pos;
+
+ get_sc_pos(e->cursor_frame, e->cursor_para,
+ e->cursor_pos+e->cursor_trail,
+ &cur_bl, &cur_sc_pos);
+ sc_insert_block(cur_bl, cur_sc_pos, bl);
+ full_rerender(e);
+}
+
+
+static void paste_selection(SCEditor *e)
+{
+ GtkClipboard *cb;
+
+ cb = gtk_clipboard_get(GDK_NONE);
+ gtk_clipboard_request_text(cb, paste_callback, e);
+}
+
+
static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
SCEditor *e)
{
@@ -1212,6 +1235,14 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
}
break;
+ case GDK_KEY_V :
+ case GDK_KEY_v :
+ if ( event->state == GDK_CONTROL_MASK ) {
+ paste_selection(e);
+ }
+ break;
+
+
}
if ( claim ) return TRUE;