diff options
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 43 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_python.c | 2 |
5 files changed, 50 insertions, 23 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 80e6c89fc34..be90834a371 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -127,14 +127,6 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn) if(!wmn->reference || wmn->reference == st->text) { ED_area_tag_redraw(sa); - if(wmn->data == ND_CURSOR || wmn->action == NA_EDITED) { - ARegion *ar; - - for(ar=sa->regionbase.first; ar; ar= ar->next) - if(ar->regiontype==RGN_TYPE_WINDOW) - text_update_cursor_moved(st, ar); - } - if(wmn->action == NA_EDITED) if(st->text) text_update_edited(st->text); diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 035c56005fe..b74e1f6cfb2 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -43,6 +43,7 @@ #include "DNA_screen_types.h" #include "DNA_userdef_types.h" +#include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_suggestions.h" @@ -1311,10 +1312,19 @@ void text_update_character_width(SpaceText *st) /* Moves the view to the cursor location, also used to make sure the view isnt outside the file */ -void text_update_cursor_moved(SpaceText *st, ARegion *ar) +void text_update_cursor_moved(bContext *C) { + ScrArea *sa= CTX_wm_area(C); + SpaceText *st= CTX_wm_space_text(C); Text *text= st->text; - int i, x; + ARegion *ar; + int i, x, winx= 0; + + if(!st) return; + + for(ar=sa->regionbase.first; ar; ar= ar->next) + if(ar->regiontype==RGN_TYPE_WINDOW) + winx= ar->winx; if(!text || !text->curl) return; @@ -1330,8 +1340,8 @@ void text_update_cursor_moved(SpaceText *st, ARegion *ar) else { x= text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL); - if(x==0 || x>ar->winx) - st->left= text->curc-0.5*(ar->winx)/st->cwidth; + if(x==0 || x>winx) + st->left= text->curc-0.5*winx/st->cwidth; } if(st->top < 0) st->top= 0; diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index 4847f2f0741..5e3070c4718 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -56,7 +56,7 @@ int text_font_width(struct SpaceText *st, char *str); void text_update_line_edited(struct Text *text, struct TextLine *line); void text_update_edited(struct Text *text); void text_update_character_width(struct SpaceText *st); -void text_update_cursor_moved(struct SpaceText *st, struct ARegion *ar); +void text_update_cursor_moved(struct bContext *C); #define TEXTXLOC (st->cwidth * st->linenrs_tot) diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index e5a1e772523..e385b2f5f2a 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -307,6 +307,7 @@ static int reload_exec(bContext *C, wmOperator *op) #endif text_update_edited(text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -337,10 +338,12 @@ static int unlink_exec(bContext *C, wmOperator *op) if(st) { if(text->id.prev) { st->text = text->id.prev; + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); } else if(text->id.next) { st->text = text->id.next; + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); } } @@ -378,6 +381,7 @@ static int make_internal_exec(bContext *C, wmOperator *op) text->name= NULL; } + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -447,6 +451,7 @@ static int save_exec(bContext *C, wmOperator *op) txt_write_file(text, op->reports); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -482,6 +487,7 @@ static int save_as_exec(bContext *C, wmOperator *op) txt_write_file(text, op->reports); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -720,7 +726,7 @@ static int paste_exec(bContext *C, wmOperator *op) MEM_freeN(buf); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); /* run the script while editing, evil but useful */ @@ -789,7 +795,7 @@ static int cut_exec(bContext *C, wmOperator *op) txt_copy_clipboard(text); txt_delete_selected(text); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); /* run the script while editing, evil but useful */ @@ -826,7 +832,7 @@ static int indent_exec(bContext *C, wmOperator *op) text_update_edited(text); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -856,7 +862,7 @@ static int unindent_exec(bContext *C, wmOperator *op) text_update_edited(text); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -897,7 +903,7 @@ static int line_break_exec(bContext *C, wmOperator *op) text_update_line_edited(text, text->curl); } - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_CANCELLED; @@ -926,6 +932,7 @@ static int comment_exec(bContext *C, wmOperator *op) comment(text); text_update_edited(text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; } @@ -956,6 +963,7 @@ static int uncomment_exec(bContext *C, wmOperator *op) uncomment(text); text_update_edited(text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1097,7 +1105,7 @@ static int convert_whitespace_exec(bContext *C, wmOperator *op) } text_update_edited(text); - + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1126,6 +1134,7 @@ static int select_all_exec(bContext *C, wmOperator *op) txt_sel_all(text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1151,6 +1160,7 @@ static int select_line_exec(bContext *C, wmOperator *op) txt_sel_line(text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1186,6 +1196,7 @@ static int previous_marker_exec(bContext *C, wmOperator *op) txt_move_to(text, mrk->lineno, mrk->end, 1); } + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1221,6 +1232,7 @@ static int next_marker_exec(bContext *C, wmOperator *op) txt_move_to(text, mrk->lineno, mrk->end, 1); } + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1246,6 +1258,7 @@ static int clear_all_markers_exec(bContext *C, wmOperator *op) txt_clear_markers(text, 0, 0); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1519,7 +1532,7 @@ static int move_cursor(bContext *C, int type, int select) break; } - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -1584,6 +1597,7 @@ static int jump_exec(bContext *C, wmOperator *op) txt_move_toline(text, line-1, 0); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); return OPERATOR_FINISHED; @@ -1630,7 +1644,7 @@ static int delete_exec(bContext *C, wmOperator *op) text_update_line_edited(text, text->curl); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); /* run the script while editing, evil but useful */ @@ -2057,6 +2071,7 @@ static void set_cursor_apply(bContext *C, wmOperator *op, wmEvent *event) set_cursor_to_pos(st, ar, event->mval[0], event->mval[1]<0?0:ar->winy, 1); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); } else if(!st->wordwrap && (event->mval[0]<0 || event->mval[0]>ar->winx)) { @@ -2065,12 +2080,14 @@ static void set_cursor_apply(bContext *C, wmOperator *op, wmEvent *event) set_cursor_to_pos(st, ar, event->mval[0], event->mval[1], 1); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); // XXX PIL_sleep_ms(10); } else { set_cursor_to_pos(st, ar, event->mval[0], event->mval[1], 1); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); scu->old[0]= event->mval[0]; @@ -2098,6 +2115,7 @@ static void set_cursor_exit(bContext *C, wmOperator *op) if(scu->sell!=linep2 || scu->selc!=charp2) txt_undo_add_toop(st->text, UNDO_STO, scu->sell, scu->selc, linep2, charp2); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); MEM_freeN(scu); @@ -2210,6 +2228,7 @@ static int line_number_invoke(bContext *C, wmOperator *op, wmEvent *event) txt_move_toline(text, jump_to-1, 0); last_jump= time; + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); return OPERATOR_FINISHED; @@ -2255,7 +2274,7 @@ static int insert_exec(bContext *C, wmOperator *op) text_update_line_edited(text, text->curl); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); return OPERATOR_FINISHED; @@ -2338,6 +2357,7 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) MEM_freeN(text->curl->format); text->curl->format= NULL; } + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); } else if(mode==TEXT_MARK_ALL) { @@ -2350,6 +2370,7 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) } txt_add_marker(text, text->curl, text->curc, text->selc, color, TMARK_GRP_FINDALL, TMARK_EDITALL); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); } } @@ -2359,6 +2380,7 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) /* Find next */ if(txt_find_string(text, st->findstr, flags & ST_FIND_WRAP)) { + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); } else if(flags & ST_FIND_ALL) { @@ -2369,6 +2391,7 @@ static int find_and_replace(bContext *C, wmOperator *op, short mode) else text= st->text= G.main->text.first; txt_move_toline(text, 0, 0); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); first= 1; } @@ -2679,7 +2702,7 @@ void ED_text_undo_step(bContext *C, int step) text_update_edited(text); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text); } diff --git a/source/blender/editors/space_text/text_python.c b/source/blender/editors/space_text/text_python.c index 92a64720210..9a8a8e7f976 100644 --- a/source/blender/editors/space_text/text_python.c +++ b/source/blender/editors/space_text/text_python.c @@ -401,6 +401,7 @@ short do_textmarkers(SpaceText *st, char ascii, unsigned short evnt, short val) if(marker) { txt_move_to(text, marker->lineno, marker->start, 0); txt_move_to(text, marker->lineno, marker->end, 1); + // XXX text_update_cursor_moved(C); // XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); evnt= ascii= val= 0; draw= 1; @@ -504,6 +505,7 @@ short do_textmarkers(SpaceText *st, char ascii, unsigned short evnt, short val) if(mrk) { txt_move_to(text, mrk->lineno, mrk->start, 0); txt_move_to(text, mrk->lineno, mrk->end, 1); + // XXX text_update_cursor_moved(C); // XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); } swallow= 1; |