text editor reload no-longer resets scroll & cursor - annoying when making tweaks to UI scripts.

also restrict freestyle hack to WITH_FREESTYLE define.
This commit is contained in:
Campbell Barton 2013-04-17 04:53:23 +00:00
parent 7abc2243b6
commit 8ee1de2de3
2 changed files with 32 additions and 18 deletions

@ -2341,8 +2341,13 @@ void DAG_ids_check_recalc(Main *bmain, Scene *scene, int time)
/* we tag based on first ID type character to avoid /* we tag based on first ID type character to avoid
* looping over all ID's in case there are no tags */ * looping over all ID's in case there are no tags */
if (id &&
#ifdef WITH_FREESTYLE
/* XXX very weak... added check for '27' to ignore freestyle added objects */ /* XXX very weak... added check for '27' to ignore freestyle added objects */
if (id && id->name[2] > 27 && bmain->id_tag_update[id->name[0]]) { id->name[2] > 27 &&
#endif
bmain->id_tag_update[id->name[0]])
{
updated = 1; updated = 1;
break; break;
} }

@ -69,6 +69,8 @@
#include "text_intern.h" #include "text_intern.h"
#include "text_format.h" #include "text_format.h"
static void txt_screen_clamp(SpaceText *st, ARegion *ar);
/************************ poll ***************************/ /************************ poll ***************************/
@ -319,7 +321,14 @@ void TEXT_OT_open(wmOperatorType *ot)
static int text_reload_exec(bContext *C, wmOperator *op) static int text_reload_exec(bContext *C, wmOperator *op)
{ {
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C); Text *text = CTX_data_edit_text(C);
ARegion *ar = CTX_wm_region(C);
/* store view & cursor state */
const int orig_top = st->top;
const int orig_curl = BLI_findindex(&text->lines, text->curl);
const int orig_curc = text->curc;
if (!BKE_text_reload(text)) { if (!BKE_text_reload(text)) {
BKE_report(op->reports, RPT_ERROR, "Could not reopen file"); BKE_report(op->reports, RPT_ERROR, "Could not reopen file");
@ -336,6 +345,12 @@ static int text_reload_exec(bContext *C, wmOperator *op)
text_drawcache_tag_update(CTX_wm_space_text(C), 1); text_drawcache_tag_update(CTX_wm_space_text(C), 1);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* return to scroll position */
st->top = orig_top;
txt_screen_clamp(st, ar);
/* return cursor */
txt_move_to(text, orig_curl, orig_curc, false);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
@ -2053,18 +2068,19 @@ void TEXT_OT_overwrite_toggle(wmOperatorType *ot)
/******************* scroll operator **********************/ /******************* scroll operator **********************/
static void txt_screen_clamp(SpaceText *st, ARegion *ar)
{
int last;
last = text_get_total_lines(st, ar);
last = last - (st->viewlines / 2);
CLAMP(st->top, 0, last);
}
/* Moves the view vertically by the specified number of lines */ /* Moves the view vertically by the specified number of lines */
static void txt_screen_skip(SpaceText *st, ARegion *ar, int lines) static void txt_screen_skip(SpaceText *st, ARegion *ar, int lines)
{ {
int last;
st->top += lines; st->top += lines;
txt_screen_clamp(st, ar);
last = text_get_total_lines(st, ar);
last = last - (st->viewlines / 2);
if (st->top > last) st->top = last;
if (st->top < 0) st->top = 0;
} }
/* quick enum for tsc->zone (scroller handles) */ /* quick enum for tsc->zone (scroller handles) */
@ -2179,14 +2195,7 @@ static int text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
case RIGHTMOUSE: case RIGHTMOUSE:
case MIDDLEMOUSE: case MIDDLEMOUSE:
if (ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) { if (ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
int last; txt_screen_skip(st, ar, st->viewlines * (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1));
st->top += st->viewlines * (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1);
last = text_get_total_lines(st, ar);
last = last - (st->viewlines / 2);
CLAMP(st->top, 0, last);
ED_area_tag_redraw(CTX_wm_area(C)); ED_area_tag_redraw(CTX_wm_area(C));
} }