Index: release/scripts/startup/bl_ui/space_text.py =================================================================== --- release/scripts/startup/bl_ui/space_text.py (revision 45403) +++ release/scripts/startup/bl_ui/space_text.py (working copy) @@ -273,6 +273,7 @@ layout.operator("text.cut") layout.operator("text.copy") layout.operator("text.paste") + layout.operator("text.duplicate_line") layout.separator() Index: source/blender/blenkernel/BKE_text.h =================================================================== --- source/blender/blenkernel/BKE_text.h (revision 45403) +++ source/blender/blenkernel/BKE_text.h (working copy) @@ -96,6 +96,7 @@ void txt_comment (struct Text *text); void txt_indent (struct Text *text); void txt_uncomment (struct Text *text); +void txt_duplicate_line (struct Text *text); int setcurr_tab_spaces (struct Text *text, int space); void txt_add_marker (struct Text *text, struct TextLine *line, int start, int end, const unsigned char color[4], int group, int flags); @@ -169,6 +170,8 @@ #define UNDO_COMMENT 034 #define UNDO_UNCOMMENT 035 +#define UNDO_DUPLICATE 040 + /* Marker flags */ #define TMARK_TEMP 0x01 /* Remove on non-editing events, don't save */ #define TMARK_EDITALL 0x02 /* Edit all markers of the same group as one */ Index: source/blender/blenkernel/intern/text.c =================================================================== --- source/blender/blenkernel/intern/text.c (revision 45403) +++ source/blender/blenkernel/intern/text.c (working copy) @@ -2205,6 +2205,9 @@ text->undo_pos--; break; + case UNDO_DUPLICATE: + txt_delete_line(text, text->curl->next); + break; default: //XXX error("Undo buffer error - resetting"); text->undo_pos= -1; @@ -2402,6 +2405,9 @@ txt_uncomment(text); } break; + case UNDO_DUPLICATE: + txt_duplicate_line(text); + break; default: //XXX error("Undo buffer error - resetting"); text->undo_pos= -1; @@ -2543,6 +2549,23 @@ txt_clean_text(text); } +void txt_duplicate_line(Text *text) +{ + TextLine *textline; + + if (!text || !text->curl) return; + + if (text->curl == text->sell) { + textline = txt_new_line(text->curl->line); + BLI_insertlinkafter(&text->lines, text->curl, textline); + + txt_make_dirty(text); + txt_clean_text(text); + + if (!undoing) txt_undo_add_op(text, UNDO_DUPLICATE); + } +} + void txt_delete_char(Text *text) { unsigned int c='\n'; Index: source/blender/editors/space_text/space_text.c =================================================================== --- source/blender/editors/space_text/space_text.c (revision 45403) +++ source/blender/editors/space_text/space_text.c (working copy) @@ -187,6 +187,7 @@ WM_operatortype_append(TEXT_OT_paste); WM_operatortype_append(TEXT_OT_copy); WM_operatortype_append(TEXT_OT_cut); + WM_operatortype_append(TEXT_OT_duplicate_line); WM_operatortype_append(TEXT_OT_convert_whitespace); WM_operatortype_append(TEXT_OT_uncomment); @@ -297,6 +298,8 @@ WM_keymap_add_item(keymap, "TEXT_OT_cut", DELKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "TEXT_OT_copy", INSERTKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "TEXT_OT_paste", INSERTKEY, KM_PRESS, KM_SHIFT, 0); + + WM_keymap_add_item(keymap, "TEXT_OT_duplicate_line", DKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0); if (U.uiflag & USER_MMB_PASTE) { // XXX not dynamic kmi = WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0); Index: source/blender/editors/space_text/text_intern.h =================================================================== --- source/blender/editors/space_text/text_intern.h (revision 45403) +++ source/blender/editors/space_text/text_intern.h (working copy) @@ -118,6 +118,7 @@ void TEXT_OT_paste(struct wmOperatorType *ot); void TEXT_OT_copy(struct wmOperatorType *ot); void TEXT_OT_cut(struct wmOperatorType *ot); +void TEXT_OT_duplicate_line(struct wmOperatorType *ot); void TEXT_OT_convert_whitespace(struct wmOperatorType *ot); void TEXT_OT_uncomment(struct wmOperatorType *ot); Index: source/blender/editors/space_text/text_ops.c =================================================================== --- source/blender/editors/space_text/text_ops.c (revision 45403) +++ source/blender/editors/space_text/text_ops.c (working copy) @@ -826,6 +826,35 @@ RNA_def_boolean(ot->srna, "selection", 0, "Selection", "Paste text selected elsewhere rather than copied (X11 only)"); } +/**************** duplicate operator *******************/ + +static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Text *text= CTX_data_edit_text(C); + + txt_duplicate_line(text); + + WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + + /* run the script while editing, evil but useful */ + if (CTX_wm_space_text(C)->live_edit) + text_run_script(C, NULL); + + return OPERATOR_FINISHED; +} + +void TEXT_OT_duplicate_line(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Duplicate Line"; + ot->idname = "TEXT_OT_duplicate_line"; + ot->description = "Duplicate the current line"; + + /* api callbacks */ + ot->exec = text_duplicate_line_exec; + ot->poll = text_edit_poll; +} + /******************* copy operator *********************/ static void txt_copy_clipboard(Text *text)