Text Editor: don't force other views to follow the cursor
While the existing behavior worked as intended, it wasn't possible to have two views on the same file at different locations. Since there isn't much use in having two views open at the same location allow one view to be at a different scroll location. UI edit-source and selecting a text data block now need explicit calls to scroll to the cursor location. Resolves T87284
This commit is contained in:
parent
945b1143df
commit
89b3c9da48
Notes:
blender-bot
2023-02-14 09:02:41 +01:00
Referenced by issue #87284, Multiple Text Editors with same file are always scrolled on current line.
|
@ -34,6 +34,8 @@ struct UndoStep;
|
|||
struct UndoType;
|
||||
struct bContext;
|
||||
|
||||
void ED_text_scroll_to_cursor(struct SpaceText *st, struct ARegion *region, bool center);
|
||||
|
||||
bool ED_text_region_location_from_cursor(struct SpaceText *st,
|
||||
struct ARegion *region,
|
||||
const int cursor_co[2],
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
#include "BKE_main.h"
|
||||
#include "BLI_ghash.h"
|
||||
#include "ED_screen.h"
|
||||
#include "ED_text.h"
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Copy Data Path Operator
|
||||
|
@ -1336,18 +1337,23 @@ static int editsource_text_edit(bContext *C,
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
txt_move_toline(text, line - 1, false);
|
||||
|
||||
/* naughty!, find text area to set, not good behavior
|
||||
* but since this is a dev tool lets allow it - campbell */
|
||||
ScrArea *area = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
|
||||
if (area) {
|
||||
SpaceText *st = area->spacedata.first;
|
||||
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
|
||||
st->text = text;
|
||||
if (region) {
|
||||
ED_text_scroll_to_cursor(st, region, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BKE_reportf(op->reports, RPT_INFO, "See '%s' in the text editor", text->id.name + 2);
|
||||
}
|
||||
|
||||
txt_move_toline(text, line - 1, false);
|
||||
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
|
|
|
@ -138,13 +138,7 @@ static void text_listener(const wmSpaceTypeListenerParams *params)
|
|||
|
||||
switch (wmn->data) {
|
||||
case ND_DISPLAY:
|
||||
ED_area_tag_redraw(area);
|
||||
break;
|
||||
case ND_CURSOR:
|
||||
if (st->text && st->text == wmn->reference) {
|
||||
text_scroll_to_cursor__area(st, area, true);
|
||||
}
|
||||
|
||||
ED_area_tag_redraw(area);
|
||||
break;
|
||||
}
|
||||
|
@ -160,13 +154,8 @@ static void text_listener(const wmSpaceTypeListenerParams *params)
|
|||
ATTR_FALLTHROUGH; /* fall down to tag redraw */
|
||||
case NA_ADDED:
|
||||
case NA_REMOVED:
|
||||
ED_area_tag_redraw(area);
|
||||
break;
|
||||
case NA_SELECTED:
|
||||
if (st->text && st->text == wmn->reference) {
|
||||
text_scroll_to_cursor__area(st, area, true);
|
||||
}
|
||||
|
||||
ED_area_tag_redraw(area);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1739,7 +1739,7 @@ void text_update_character_width(SpaceText *st)
|
|||
|
||||
/* Moves the view to the cursor location,
|
||||
* also used to make sure the view isn't outside the file */
|
||||
void text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
|
||||
void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
|
||||
{
|
||||
Text *text;
|
||||
int i, x, winx = region->winx;
|
||||
|
@ -1818,7 +1818,7 @@ void text_scroll_to_cursor__area(SpaceText *st, ScrArea *area, const bool center
|
|||
region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
|
||||
|
||||
if (region) {
|
||||
text_scroll_to_cursor(st, region, center);
|
||||
ED_text_scroll_to_cursor(st, region, center);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ void draw_text_main(struct SpaceText *st, struct ARegion *region);
|
|||
void text_update_line_edited(struct TextLine *line);
|
||||
void text_update_edited(struct Text *text);
|
||||
void text_update_character_width(struct SpaceText *st);
|
||||
void text_scroll_to_cursor(struct SpaceText *st, struct ARegion *region, const bool center);
|
||||
void text_scroll_to_cursor__area(struct SpaceText *st, struct ScrArea *area, const bool center);
|
||||
void text_update_cursor_moved(struct bContext *C);
|
||||
|
||||
|
|
|
@ -506,12 +506,10 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3200,7 +3198,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
|
|||
|
||||
if (event->type == TIMER) {
|
||||
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], 1);
|
||||
text_scroll_to_cursor(st, region, false);
|
||||
ED_text_scroll_to_cursor(st, region, false);
|
||||
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
|
||||
}
|
||||
}
|
||||
|
@ -3210,7 +3208,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
|
|||
if (event->type == TIMER) {
|
||||
text_cursor_set_to_pos(
|
||||
st, region, CLAMPIS(event->mval[0], 0, region->winx), event->mval[1], 1);
|
||||
text_scroll_to_cursor(st, region, false);
|
||||
ED_text_scroll_to_cursor(st, region, false);
|
||||
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
|
||||
}
|
||||
}
|
||||
|
@ -3219,7 +3217,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
|
|||
|
||||
if (event->type != TIMER) {
|
||||
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], 1);
|
||||
text_scroll_to_cursor(st, region, false);
|
||||
ED_text_scroll_to_cursor(st, region, false);
|
||||
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
|
||||
|
||||
ssel->mval_prev[0] = event->mval[0];
|
||||
|
|
|
@ -1793,7 +1793,13 @@ static void rna_SpaceTextEditor_text_set(PointerRNA *ptr,
|
|||
|
||||
st->text = value.data;
|
||||
|
||||
WM_main_add_notifier(NC_TEXT | NA_SELECTED, st->text);
|
||||
ScrArea *area = rna_area_from_space(ptr);
|
||||
if (area) {
|
||||
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
|
||||
if (region) {
|
||||
ED_text_scroll_to_cursor(st, region, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool rna_SpaceTextEditor_text_is_syntax_highlight_supported(struct SpaceText *space)
|
||||
|
|
Loading…
Reference in New Issue