Cleanup: use "space_text" prefix for functions taking a SpaceText

Differentiate between utility functions that take a Text & a SpaceText.
Also pass in const arguments.
This commit is contained in:
Campbell Barton 2024-01-15 15:33:00 +11:00
parent 0efb5a39e2
commit 5082b644da
9 changed files with 249 additions and 222 deletions

View File

@ -17,22 +17,20 @@ struct bContext;
/* `text_draw.cc` */
int ED_text_visible_lines_get(const SpaceText *st);
bool ED_text_activate_in_screen(bContext *C, Text *text);
int ED_space_text_visible_lines_get(const SpaceText *st);
/**
* Moves the view to the cursor location, also used to make sure the view isn't outside the file.
*/
void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, bool center);
void ED_space_text_scroll_to_cursor(SpaceText *st, ARegion *region, bool center);
/**
* Takes a cursor (row, character) and returns x,y pixel coords.
*/
bool ED_text_region_location_from_cursor(SpaceText *st,
ARegion *region,
const int cursor_co[2],
int r_pixel_co[2]);
bool ED_space_text_region_location_from_cursor(const SpaceText *st,
const ARegion *region,
const int cursor_co[2],
int r_pixel_co[2]);
/* `text_undo.cc` */

View File

@ -91,7 +91,7 @@ static SpaceLink *text_create(const ScrArea * /*area*/, const Scene * /*scene*/)
static void text_free(SpaceLink *sl)
{
SpaceText *stext = (SpaceText *)sl;
text_free_caches(stext);
space_text_free_caches(stext);
MEM_delete(stext->runtime);
stext->text = nullptr;
}
@ -135,7 +135,7 @@ static void text_listener(const wmSpaceTypeListenerParams *params)
switch (wmn->action) {
case NA_EDITED:
if (st->text) {
text_drawcache_tag_update(st, true);
space_text_drawcache_tag_update(st, true);
text_update_edited(st->text);
}

View File

@ -37,7 +37,7 @@
/** \name Public API
* \{ */
bool text_do_suggest_select(SpaceText *st, ARegion *region, const int mval[2])
bool space_text_do_suggest_select(SpaceText *st, const ARegion *region, const int mval[2])
{
const int lheight = TXT_LINE_HEIGHT(st);
SuggItem *item, *first, *last /* , *sel */ /* UNUSED */;
@ -69,7 +69,7 @@ bool text_do_suggest_select(SpaceText *st, ARegion *region, const int mval[2])
return false;
}
text_update_character_width(st);
space_text_update_character_width(st);
x = TXT_BODY_LEFT(st) + (st->runtime->cwidth_px * (st->text->curc - st->left));
y = region->winy - lheight * l - 2;
@ -333,7 +333,7 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
switch (event->type) {
case MOUSEMOVE: {
if (text_do_suggest_select(st, region, event->mval)) {
if (space_text_do_suggest_select(st, region, event->mval)) {
draw = 1;
}
swallow = 1;
@ -341,7 +341,7 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
}
case LEFTMOUSE:
if (event->val == KM_PRESS) {
if (text_do_suggest_select(st, region, event->mval)) {
if (space_text_do_suggest_select(st, region, event->mval)) {
if (tools & TOOL_SUGG_LIST) {
ED_text_undo_push_init(C);
confirm_suggestion(st->text);

View File

@ -40,7 +40,7 @@
/** \name Text Run-Time Access
* \{ */
int ED_text_visible_lines_get(const SpaceText *st)
int ED_space_text_visible_lines_get(const SpaceText *st)
{
return st->runtime->viewlines;
}
@ -58,7 +58,7 @@ struct TextDrawContext {
bool syntax_highlight;
};
static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
static void space_text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
{
tdc->font_id = blf_mono_font;
tdc->cwidth_px = 0;
@ -191,7 +191,7 @@ static void format_draw_color(const TextDrawContext *tdc, char formatchar)
*
* \{ */
int wrap_width(const SpaceText *st, ARegion *region)
int space_text_wrap_width(const SpaceText *st, const ARegion *region)
{
int winx = region->winx - TXT_SCROLL_WIDTH;
int x, max;
@ -201,8 +201,8 @@ int wrap_width(const SpaceText *st, ARegion *region)
return max > 8 ? max : 8;
}
void wrap_offset(
const SpaceText *st, ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
void space_text_wrap_offset(
const SpaceText *st, const ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
{
Text *text;
TextLine *linep;
@ -225,7 +225,7 @@ void wrap_offset(
linep = static_cast<TextLine *>(text->lines.first);
i = st->top;
while (i > 0 && linep) {
int lines = text_get_visible_lines(st, region, linep->line);
int lines = space_text_get_visible_lines(st, region, linep->line);
/* Line before top */
if (linep == linein) {
@ -244,7 +244,7 @@ void wrap_offset(
i -= lines;
}
max = wrap_width(st, region);
max = space_text_wrap_width(st, region);
cursin = BLI_str_utf8_offset_to_column(linein->line, linein->len, cursin);
while (linep) {
@ -306,8 +306,8 @@ void wrap_offset(
}
}
void wrap_offset_in_line(
const SpaceText *st, ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
void space_text_wrap_offset_in_line(
const SpaceText *st, const ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
{
int i, j, start, end, chars, max;
bool chop;
@ -322,7 +322,7 @@ void wrap_offset_in_line(
return;
}
max = wrap_width(st, region);
max = space_text_wrap_width(st, region);
start = 0;
end = max;
@ -378,7 +378,7 @@ void wrap_offset_in_line(
}
}
int text_get_char_pos(const SpaceText *st, const char *line, int cur)
int space_text_get_char_pos(const SpaceText *st, const char *line, int cur)
{
int a = 0, i;
@ -414,14 +414,14 @@ static const char *txt_utf8_forward_columns(const char *str, int columns, int *p
return p;
}
static int text_draw_wrapped(const SpaceText *st,
const TextDrawContext *tdc,
const char *str,
int x,
int y,
int w,
const char *format,
int skip)
static int space_text_draw_wrapped(const SpaceText *st,
const TextDrawContext *tdc,
const char *str,
int x,
int y,
int w,
const char *format,
int skip)
{
const bool use_syntax = (tdc->syntax_highlight && format);
FlattenString fs;
@ -513,14 +513,14 @@ static int text_draw_wrapped(const SpaceText *st,
return lines;
}
static void text_draw(const SpaceText *st,
const TextDrawContext *tdc,
char *str,
int cshift,
int maxwidth,
int x,
int y,
const char *format)
static void space_text_draw(const SpaceText *st,
const TextDrawContext *tdc,
char *str,
int cshift,
int maxwidth,
int x,
int y,
const char *format)
{
const bool use_syntax = (tdc->syntax_highlight && format);
FlattenString fs;
@ -598,7 +598,7 @@ struct DrawCache {
int valid_head, valid_tail; /* amount of unchanged lines */
};
static void text_drawcache_init(SpaceText *st)
static void space_text_drawcache_init(SpaceText *st)
{
DrawCache *drawcache = static_cast<DrawCache *>(
MEM_callocN(sizeof(DrawCache), "text draw cache"));
@ -610,7 +610,7 @@ static void text_drawcache_init(SpaceText *st)
st->runtime->drawcache = drawcache;
}
static void text_update_drawcache(SpaceText *st, ARegion *region)
static void space_text_update_drawcache(SpaceText *st, const ARegion *region)
{
DrawCache *drawcache;
bool full_update = false;
@ -618,10 +618,10 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
Text *txt = st->text;
if (st->runtime->drawcache == nullptr) {
text_drawcache_init(st);
space_text_drawcache_init(st);
}
text_update_character_width(st);
space_text_update_character_width(st);
drawcache = static_cast<DrawCache *>(st->runtime->drawcache);
nlines = drawcache->nlines;
@ -686,7 +686,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
lines_count = fp[lineno];
}
else {
lines_count = text_get_visible_lines(st, region, line->line);
lines_count = space_text_get_visible_lines(st, region, line->line);
}
fp[lineno] = lines_count;
@ -731,7 +731,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
drawcache->valid_tail = 0;
}
void text_drawcache_tag_update(SpaceText *st, const bool full)
void space_text_drawcache_tag_update(SpaceText *st, const bool full)
{
/* This happens if text editor ops are called from Python. */
if (st == nullptr) {
@ -780,7 +780,7 @@ void text_drawcache_tag_update(SpaceText *st, const bool full)
}
}
void text_free_caches(SpaceText *st)
void space_text_free_caches(SpaceText *st)
{
DrawCache *drawcache = static_cast<DrawCache *>(st->runtime->drawcache);
@ -800,19 +800,19 @@ void text_free_caches(SpaceText *st)
* \{ */
/* cache should be updated in caller */
static int text_get_visible_lines_no(const SpaceText *st, int lineno)
static int space_text_get_visible_lines_no(const SpaceText *st, int lineno)
{
const DrawCache *drawcache = static_cast<const DrawCache *>(st->runtime->drawcache);
return drawcache->line_height[lineno];
}
int text_get_visible_lines(const SpaceText *st, ARegion *region, const char *str)
int space_text_get_visible_lines(const SpaceText *st, const ARegion *region, const char *str)
{
int i, j, start, end, max, lines, chars;
char ch;
max = wrap_width(st, region);
max = space_text_wrap_width(st, region);
lines = 1;
start = 0;
end = max;
@ -846,7 +846,10 @@ int text_get_visible_lines(const SpaceText *st, ARegion *region, const char *str
return lines;
}
int text_get_span_wrap(const SpaceText *st, ARegion *region, TextLine *from, TextLine *to)
int space_text_get_span_wrap(const SpaceText *st,
const ARegion *region,
TextLine *from,
TextLine *to)
{
if (st->wordwrap) {
int ret = 0;
@ -857,7 +860,7 @@ int text_get_span_wrap(const SpaceText *st, ARegion *region, TextLine *from, Tex
if (tmp == to) {
return ret;
}
ret += text_get_visible_lines(st, region, tmp->line);
ret += space_text_get_visible_lines(st, region, tmp->line);
tmp = tmp->next;
}
@ -866,11 +869,11 @@ int text_get_span_wrap(const SpaceText *st, ARegion *region, TextLine *from, Tex
return txt_get_span(from, to);
}
int text_get_total_lines(SpaceText *st, ARegion *region)
int space_text_get_total_lines(SpaceText *st, const ARegion *region)
{
DrawCache *drawcache;
text_update_drawcache(st, region);
space_text_update_drawcache(st, region);
drawcache = static_cast<DrawCache *>(st->runtime->drawcache);
return drawcache->total_lines;
@ -891,7 +894,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *scroll, rcti *b
pix_top_margin = (0.4 * U.widget_unit);
pix_bottom_margin = (0.4 * U.widget_unit);
pix_available = region->winy - pix_top_margin - pix_bottom_margin;
ltexth = text_get_total_lines(st, region);
ltexth = space_text_get_total_lines(st, region);
blank_lines = st->runtime->viewlines / 2;
/* nicer code: use scroll rect for entire bar */
@ -933,9 +936,9 @@ static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *scroll, rcti *b
st->runtime->scroll_px_per_line = 0.1f;
}
curl_off = text_get_span_wrap(
curl_off = space_text_get_span_wrap(
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->curl);
sell_off = text_get_span_wrap(
sell_off = space_text_get_span_wrap(
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->sell);
lhlstart = MIN2(curl_off, sell_off);
lhlend = std::max(curl_off, sell_off);
@ -1081,10 +1084,10 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
sel = texttool_suggest_selected();
top = texttool_suggest_top();
wrap_offset(st, region, st->text->curl, st->text->curc, &offl, &offc);
space_text_wrap_offset(st, region, st->text->curl, st->text->curc, &offl, &offc);
vcurl = txt_get_span(static_cast<TextLine *>(st->text->lines.first), st->text->curl) - st->top +
offl;
vcurc = text_get_char_pos(st, st->text->curl->line, st->text->curc) - st->left + offc;
vcurc = space_text_get_char_pos(st, st->text->curl->line, st->text->curc) - st->left + offc;
x = TXT_BODY_LEFT(st) + (vcurc * st->runtime->cwidth_px);
y = region->winy - (vcurl + 1) * lheight - 2;
@ -1134,7 +1137,7 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
BLI_strncpy(str, item->name, len + 1);
w = st->runtime->cwidth_px * text_get_char_pos(st, str, len);
w = st->runtime->cwidth_px * space_text_get_char_pos(st, str, len);
if (item == sel) {
uint posi = GPU_vertformat_attr_add(
@ -1148,7 +1151,7 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
}
format_draw_color(tdc, item->type);
text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, nullptr);
space_text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, nullptr);
if (item == last) {
break;
@ -1172,9 +1175,9 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
const int lheight = TXT_LINE_HEIGHT(st);
/* Convert to view space character coordinates to determine if cursor is hidden */
wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
space_text_wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
vsell = txt_get_span(static_cast<TextLine *>(text->lines.first), text->sell) - st->top + offl;
vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
vselc = space_text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
if (vselc < 0) {
vselc = 0;
@ -1193,9 +1196,9 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
/* Draw the selection */
if (text->curl != text->sell || text->curc != text->selc) {
/* Convert all to view space character coordinates */
wrap_offset(st, region, text->curl, text->curc, &offl, &offc);
space_text_wrap_offset(st, region, text->curl, text->curc, &offl, &offc);
vcurl = txt_get_span(static_cast<TextLine *>(text->lines.first), text->curl) - st->top + offl;
vcurc = text_get_char_pos(st, text->curl->line, text->curc) - st->left + offc;
vcurc = space_text_get_char_pos(st, text->curl->line, text->curc) - st->left + offc;
if (vcurc < 0) {
vcurc = 0;
@ -1265,9 +1268,9 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
int y1, y2;
if (st->wordwrap) {
int visible_lines = text_get_visible_lines(st, region, text->sell->line);
int visible_lines = space_text_get_visible_lines(st, region, text->sell->line);
wrap_offset_in_line(st, region, text->sell, text->selc, &offl, &offc);
space_text_wrap_offset_in_line(st, region, text->sell, text->selc, &offl, &offc);
y1 = region->winy - (vsell - offl) * lheight;
if (st->flags & ST_SCROLL_SELECT) {
@ -1465,8 +1468,8 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
/* draw opening bracket */
ch = startl->line[startc];
wrap_offset(st, region, startl, startc, &offl, &offc);
viewc = text_get_char_pos(st, startl->line, startc) - st->left + offc;
space_text_wrap_offset(st, region, startl, startc, &offl, &offc);
viewc = space_text_get_char_pos(st, startl->line, startc) - st->left + offc;
if (viewc >= 0) {
viewl = txt_get_span(static_cast<TextLine *>(text->lines.first), startl) - st->top + offl;
@ -1479,8 +1482,8 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
/* draw closing bracket */
ch = endl->line[endc];
wrap_offset(st, region, endl, endc, &offl, &offc);
viewc = text_get_char_pos(st, endl->line, endc) - st->left + offc;
space_text_wrap_offset(st, region, endl, endc, &offl, &offc);
viewc = space_text_get_char_pos(st, endl->line, endc) - st->left + offc;
if (viewc >= 0) {
viewl = txt_get_span(static_cast<TextLine *>(text->lines.first), endl) - st->top + offl;
@ -1525,9 +1528,9 @@ void draw_text_main(SpaceText *st, ARegion *region)
int(region->winy - clip_min_y) / TXT_LINE_HEIGHT(st) :
0;
text_draw_context_init(st, &tdc);
space_text_draw_context_init(st, &tdc);
text_update_drawcache(st, region);
space_text_update_drawcache(st, region);
/* make sure all the positional pointers exist */
if (!text->curl || !text->sell || !text->lines.first || !text->lines.last) {
@ -1547,7 +1550,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
}
if (st->wordwrap) {
int lines = text_get_visible_lines_no(st, lineno);
int lines = space_text_get_visible_lines_no(st, lineno);
if (wraplinecount + lines > st->top) {
wrap_skip = st->top - wraplinecount;
@ -1616,12 +1619,13 @@ void draw_text_main(SpaceText *st, ARegion *region)
if (st->wordwrap) {
/* draw word wrapped text */
int lines = text_draw_wrapped(st, &tdc, tmp->line, x, y, winx - x, tmp->format, wrap_skip);
int lines = space_text_draw_wrapped(
st, &tdc, tmp->line, x, y, winx - x, tmp->format, wrap_skip);
y -= lines * TXT_LINE_HEIGHT(st);
}
else {
/* draw unwrapped text */
text_draw(
space_text_draw(
st, &tdc, tmp->line, st->left, region->winx / st->runtime->cwidth_px, x, y, tmp->format);
y -= TXT_LINE_HEIGHT(st);
}
@ -1661,11 +1665,11 @@ void draw_text_main(SpaceText *st, ARegion *region)
/** \name Update & Coordinate Conversion
* \{ */
void text_update_character_width(SpaceText *st)
void space_text_update_character_width(SpaceText *st)
{
TextDrawContext tdc = {0};
text_draw_context_init(st, &tdc);
space_text_draw_context_init(st, &tdc);
text_font_begin(&tdc);
st->runtime->cwidth_px = BLF_fixed_width(tdc.font_id);
@ -1681,7 +1685,7 @@ bool ED_text_activate_in_screen(bContext *C, Text *text)
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
st->text = text;
if (region) {
ED_text_scroll_to_cursor(st, region, true);
ED_space_text_scroll_to_cursor(st, region, true);
}
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
return true;
@ -1690,7 +1694,7 @@ bool ED_text_activate_in_screen(bContext *C, Text *text)
return false;
}
void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
void ED_space_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
{
Text *text;
int i, x, winx = region->winx;
@ -1701,12 +1705,12 @@ void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
text = st->text;
text_update_character_width(st);
space_text_update_character_width(st);
i = txt_get_span(static_cast<TextLine *>(text->lines.first), text->sell);
if (st->wordwrap) {
int offl, offc;
wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
space_text_wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
i += offl;
}
@ -1728,7 +1732,8 @@ void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
st->left = 0;
}
else {
x = st->runtime->cwidth_px * (text_get_char_pos(st, text->sell->line, text->selc) - st->left);
x = st->runtime->cwidth_px *
(space_text_get_char_pos(st, text->sell->line, text->selc) - st->left);
winx -= TXT_BODY_LEFT(st) + TXT_SCROLL_WIDTH;
if (center) {
@ -1757,7 +1762,7 @@ void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
st->runtime->scroll_ofs_px[1] = 0;
}
void text_scroll_to_cursor__area(SpaceText *st, ScrArea *area, const bool center)
void space_text_scroll_to_cursor_with_area(SpaceText *st, ScrArea *area, const bool center)
{
ARegion *region;
@ -1768,22 +1773,22 @@ 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) {
ED_text_scroll_to_cursor(st, region, center);
ED_space_text_scroll_to_cursor(st, region, center);
}
}
void text_update_cursor_moved(bContext *C)
void space_text_update_cursor_moved(bContext *C)
{
ScrArea *area = CTX_wm_area(C);
SpaceText *st = CTX_wm_space_text(C);
text_scroll_to_cursor__area(st, area, true);
space_text_scroll_to_cursor_with_area(st, area, true);
}
bool ED_text_region_location_from_cursor(SpaceText *st,
ARegion *region,
const int cursor_co[2],
int r_pixel_co[2])
bool ED_space_text_region_location_from_cursor(const SpaceText *st,
const ARegion *region,
const int cursor_co[2],
int r_pixel_co[2])
{
TextLine *line = nullptr;
@ -1799,9 +1804,9 @@ bool ED_text_region_location_from_cursor(SpaceText *st,
int offl, offc;
int linenr_offset = TXT_BODY_LEFT(st);
/* handle tabs as well! */
int char_pos = text_get_char_pos(st, line->line, cursor_co[1]);
int char_pos = space_text_get_char_pos(st, line->line, cursor_co[1]);
wrap_offset(st, region, line, cursor_co[1], &offl, &offc);
space_text_wrap_offset(st, region, line, cursor_co[1], &offl, &offc);
r_pixel_co[0] = (char_pos + offc - st->left) * st->runtime->cwidth_px + linenr_offset;
r_pixel_co[1] = (cursor_co[0] + offl - st->top) * TXT_LINE_HEIGHT(st);
r_pixel_co[1] = (region->winy - (r_pixel_co[1] + (TXT_BODY_LPAD * st->runtime->cwidth_px))) -

View File

@ -30,12 +30,13 @@ void draw_text_main(SpaceText *st, ARegion *region);
void text_update_line_edited(TextLine *line);
void text_update_edited(Text *text);
void text_update_character_width(SpaceText *st);
void space_text_update_character_width(SpaceText *st);
/**
* Takes an area instead of a region, use for listeners.
*/
void text_scroll_to_cursor__area(SpaceText *st, ScrArea *area, bool center);
void text_update_cursor_moved(bContext *C);
void space_text_scroll_to_cursor_with_area(SpaceText *st, ScrArea *area, bool center);
void space_text_update_cursor_moved(bContext *C);
/* Padding around line numbers in character widths. */
#define TXT_NUMCOL_PAD 1.0f
@ -64,28 +65,39 @@ void text_update_cursor_moved(bContext *C);
#define TOOL_SUGG_LIST 0x01
int wrap_width(const SpaceText *st, ARegion *region);
int space_text_wrap_width(const SpaceText *st, const ARegion *region);
/**
* Sets (offl, offc) for transforming (line, curs) to its wrapped position.
*/
void wrap_offset(
const SpaceText *st, ARegion *region, TextLine *linein, int cursin, int *offl, int *offc);
void space_text_wrap_offset(const SpaceText *st,
const ARegion *region,
TextLine *linein,
int cursin,
int *offl,
int *offc);
/**
* cursin - mem, offc - view.
*/
void wrap_offset_in_line(
const SpaceText *st, ARegion *region, TextLine *linein, int cursin, int *offl, int *offc);
int text_get_char_pos(const SpaceText *st, const char *line, int cur);
void space_text_wrap_offset_in_line(const SpaceText *st,
const ARegion *region,
TextLine *linein,
int cursin,
int *offl,
int *offc);
int space_text_get_char_pos(const SpaceText *st, const char *line, int cur);
void text_drawcache_tag_update(SpaceText *st, bool full);
void text_free_caches(SpaceText *st);
void space_text_drawcache_tag_update(SpaceText *st, bool full);
void space_text_free_caches(SpaceText *st);
bool text_do_suggest_select(SpaceText *st, ARegion *region, const int mval[2]);
bool space_text_do_suggest_select(SpaceText *st, const ARegion *region, const int mval[2]);
void text_pop_suggest_list();
int text_get_visible_lines(const SpaceText *st, ARegion *region, const char *str);
int text_get_span_wrap(const SpaceText *st, ARegion *region, TextLine *from, TextLine *to);
int text_get_total_lines(SpaceText *st, ARegion *region);
int space_text_get_visible_lines(const SpaceText *st, const ARegion *region, const char *str);
int space_text_get_span_wrap(const SpaceText *st,
const ARegion *region,
TextLine *from,
TextLine *to);
int space_text_get_total_lines(SpaceText *st, const ARegion *region);
/* `text_ops.cc` */

View File

@ -50,7 +50,7 @@
#include "text_format.hh"
#include "text_intern.hh"
static void txt_screen_clamp(SpaceText *st, ARegion *region);
static void space_text_screen_clamp(SpaceText *st, const ARegion *region);
/* -------------------------------------------------------------------- */
/** \name Utilities
@ -203,7 +203,7 @@ static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size, int *r_o
return out_buf;
}
BLI_INLINE int text_pixel_x_to_column(SpaceText *st, const int x)
BLI_INLINE int space_text_pixel_x_to_column(const SpaceText *st, const int x)
{
/* Add half the char width so mouse cursor selection is in between letters. */
return (x + (st->runtime->cwidth_px / 2)) / st->runtime->cwidth_px;
@ -353,7 +353,7 @@ static int text_new_exec(bContext *C, wmOperator * /*op*/)
st->top = 0;
st->runtime->scroll_ofs_px[0] = 0;
st->runtime->scroll_ofs_px[1] = 0;
text_drawcache_tag_update(st, true);
space_text_drawcache_tag_update(st, true);
}
WM_event_add_notifier(C, NC_TEXT | NA_ADDED, text);
@ -436,7 +436,7 @@ static int text_open_exec(bContext *C, wmOperator *op)
st->runtime->scroll_ofs_px[1] = 0;
}
text_drawcache_tag_update(st, true);
space_text_drawcache_tag_update(st, true);
WM_event_add_notifier(C, NC_TEXT | NA_ADDED, text);
MEM_freeN(op->customdata);
@ -525,15 +525,15 @@ static int text_reload_exec(bContext *C, wmOperator *op)
#endif
text_update_edited(text);
text_update_cursor_moved(C);
text_drawcache_tag_update(st, true);
space_text_update_cursor_moved(C);
space_text_drawcache_tag_update(st, true);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
text->flags &= ~TXT_ISDIRTY;
/* return to scroll position */
st->top = orig_top;
txt_screen_clamp(st, region);
space_text_screen_clamp(st, region);
/* return cursor */
txt_move_to(text, orig_curl, orig_curc, false);
@ -575,17 +575,17 @@ static int text_unlink_exec(bContext *C, wmOperator * /*op*/)
if (st) {
if (text->id.prev) {
st->text = static_cast<Text *>(text->id.prev);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
}
else if (text->id.next) {
st->text = static_cast<Text *>(text->id.next);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
}
}
BKE_id_delete(bmain, text);
text_drawcache_tag_update(st, true);
space_text_drawcache_tag_update(st, true);
WM_event_add_notifier(C, NC_TEXT | NA_REMOVED, nullptr);
return OPERATOR_FINISHED;
@ -621,7 +621,7 @@ static int text_make_internal_exec(bContext *C, wmOperator * /*op*/)
MEM_SAFE_FREE(text->filepath);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -713,7 +713,7 @@ static int text_save_exec(bContext *C, wmOperator *op)
txt_write_file(bmain, text, op->reports);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -770,7 +770,7 @@ static int text_save_as_exec(bContext *C, wmOperator *op)
txt_write_file(bmain, text, op->reports);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -853,7 +853,7 @@ static int text_run_script(bContext *C, ReportList *reports)
/* text may have freed itself */
if (CTX_data_edit_text(C) == text) {
if (text->curl != curl_prev || curc_prev != text->curc) {
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
}
}
@ -984,7 +984,7 @@ static int text_paste_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
text_drawcache_tag_update(st, false);
space_text_drawcache_tag_update(st, false);
ED_text_undo_push_init(C);
@ -1000,7 +1000,7 @@ static int text_paste_exec(bContext *C, wmOperator *op)
MEM_freeN(buf);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
@ -1128,14 +1128,14 @@ static int text_cut_exec(bContext *C, wmOperator * /*op*/)
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
text_drawcache_tag_update(st, false);
space_text_drawcache_tag_update(st, false);
txt_copy_clipboard(text);
ED_text_undo_push_init(C);
txt_delete_selected(text);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
@ -1207,7 +1207,7 @@ static int text_indent_exec(bContext *C, wmOperator * /*op*/)
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
text_drawcache_tag_update(st, false);
space_text_drawcache_tag_update(st, false);
ED_text_undo_push_init(C);
@ -1221,7 +1221,7 @@ static int text_indent_exec(bContext *C, wmOperator * /*op*/)
text_update_edited(text);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -1253,7 +1253,7 @@ static int text_unindent_exec(bContext *C, wmOperator * /*op*/)
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
text_drawcache_tag_update(st, false);
space_text_drawcache_tag_update(st, false);
ED_text_undo_push_init(C);
@ -1262,7 +1262,7 @@ static int text_unindent_exec(bContext *C, wmOperator * /*op*/)
text_update_edited(text);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -1296,7 +1296,7 @@ static int text_line_break_exec(bContext *C, wmOperator * /*op*/)
int a, curts;
int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1;
text_drawcache_tag_update(st, false);
space_text_drawcache_tag_update(st, false);
/* Double check tabs/spaces before splitting the line. */
curts = txt_setcurr_tab_spaces(text, space);
@ -1319,7 +1319,7 @@ static int text_line_break_exec(bContext *C, wmOperator * /*op*/)
text_update_line_edited(text->curl);
}
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -1353,7 +1353,7 @@ static int text_comment_exec(bContext *C, wmOperator *op)
int type = RNA_enum_get(op->ptr, "type");
const char *prefix = ED_text_format_comment_line_prefix(text);
text_drawcache_tag_update(st, false);
space_text_drawcache_tag_update(st, false);
ED_text_undo_push_init(C);
@ -1377,7 +1377,7 @@ static int text_comment_exec(bContext *C, wmOperator *op)
text_update_edited(text);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -1551,8 +1551,8 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
}
text_update_edited(text);
text_update_cursor_moved(C);
text_drawcache_tag_update(st, true);
space_text_update_cursor_moved(C);
space_text_drawcache_tag_update(st, true);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -1593,7 +1593,7 @@ static int text_select_all_exec(bContext *C, wmOperator * /*op*/)
txt_sel_all(text);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
text_select_update_primary_clipboard(text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@ -1625,7 +1625,7 @@ static int text_select_line_exec(bContext *C, wmOperator * /*op*/)
txt_sel_line(text);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
text_select_update_primary_clipboard(text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@ -1658,7 +1658,7 @@ static int text_select_word_exec(bContext *C, wmOperator * /*op*/)
BLI_str_cursor_step_bounds_utf8(
text->curl->line, text->curl->len, text->selc, &text->curc, &text->selc);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
text_select_update_primary_clipboard(text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@ -1693,7 +1693,7 @@ static int move_lines_exec(bContext *C, wmOperator *op)
txt_move_lines(text, direction);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
@ -1750,15 +1750,17 @@ static const EnumPropertyItem move_type_items[] = {
{0, nullptr, 0, nullptr, nullptr},
};
/* get cursor position in line by relative wrapped line and column positions */
static int text_get_cursor_rel(
SpaceText *st, ARegion *region, TextLine *linein, int rell, int relc)
/**
* Get cursor position in line by relative wrapped line and column positions.
*/
static int space_text_get_cursor_rel(
const SpaceText *st, const ARegion *region, TextLine *linein, int rell, int relc)
{
int i, j, start, end, max, curs, endj, selc;
bool chop, loop, found;
char ch;
max = wrap_width(st, region);
max = space_text_wrap_width(st, region);
selc = start = endj = curs = found = false;
end = max;
@ -1845,18 +1847,23 @@ static int text_get_cursor_rel(
return selc;
}
static int cursor_skip_find_line(
SpaceText *st, ARegion *region, int lines, TextLine **linep, int *charp, int *rell, int *relc)
static int cursor_skip_find_line(const SpaceText *st,
const ARegion *region,
int lines,
TextLine **linep,
int *charp,
int *rell,
int *relc)
{
int offl, offc, visible_lines;
wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
*relc = text_get_char_pos(st, (*linep)->line, *charp) + offc;
space_text_wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
*relc = space_text_get_char_pos(st, (*linep)->line, *charp) + offc;
*rell = lines;
/* handle current line */
if (lines > 0) {
visible_lines = text_get_visible_lines(st, region, (*linep)->line);
visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
if (*rell - visible_lines + offl >= 0) {
if (!(*linep)->next) {
@ -1900,7 +1907,7 @@ static int cursor_skip_find_line(
/* skip lines and find destination line and offsets */
while (*linep) {
visible_lines = text_get_visible_lines(st, region, (*linep)->line);
visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
if (lines < 0) { /* moving top */
if (*rell + visible_lines >= 0) {
@ -1943,7 +1950,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
bool chop, loop;
char ch;
text_update_character_width(st);
space_text_update_character_width(st);
if (sel) {
linep = &text->sell;
@ -1956,7 +1963,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
oldc = *charp;
max = wrap_width(st, region);
max = space_text_wrap_width(st, region);
start = endj = 0;
end = max;
@ -2030,7 +2037,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
bool chop, loop;
char ch;
text_update_character_width(st);
space_text_update_character_width(st);
if (sel) {
linep = &text->sell;
@ -2043,7 +2050,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
oldc = *charp;
max = wrap_width(st, region);
max = space_text_wrap_width(st, region);
start = endj = 0;
end = max;
@ -2113,7 +2120,7 @@ static void txt_wrap_move_up(SpaceText *st, ARegion *region, const bool sel)
int *charp;
int offl, offc, col;
text_update_character_width(st);
space_text_update_character_width(st);
if (sel) {
linep = &text->sell;
@ -2124,18 +2131,18 @@ static void txt_wrap_move_up(SpaceText *st, ARegion *region, const bool sel)
charp = &text->curc;
}
wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
col = text_get_char_pos(st, (*linep)->line, *charp) + offc;
space_text_wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
col = space_text_get_char_pos(st, (*linep)->line, *charp) + offc;
if (offl) {
*charp = text_get_cursor_rel(st, region, *linep, offl - 1, col);
*charp = space_text_get_cursor_rel(st, region, *linep, offl - 1, col);
}
else {
if ((*linep)->prev) {
int visible_lines;
*linep = (*linep)->prev;
visible_lines = text_get_visible_lines(st, region, (*linep)->line);
*charp = text_get_cursor_rel(st, region, *linep, visible_lines - 1, col);
visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
*charp = space_text_get_cursor_rel(st, region, *linep, visible_lines - 1, col);
}
else {
*charp = 0;
@ -2154,7 +2161,7 @@ static void txt_wrap_move_down(SpaceText *st, ARegion *region, const bool sel)
int *charp;
int offl, offc, col, visible_lines;
text_update_character_width(st);
space_text_update_character_width(st);
if (sel) {
linep = &text->sell;
@ -2165,16 +2172,16 @@ static void txt_wrap_move_down(SpaceText *st, ARegion *region, const bool sel)
charp = &text->curc;
}
wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
col = text_get_char_pos(st, (*linep)->line, *charp) + offc;
visible_lines = text_get_visible_lines(st, region, (*linep)->line);
space_text_wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
col = space_text_get_char_pos(st, (*linep)->line, *charp) + offc;
visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
if (offl < visible_lines - 1) {
*charp = text_get_cursor_rel(st, region, *linep, offl + 1, col);
*charp = space_text_get_cursor_rel(st, region, *linep, offl + 1, col);
}
else {
if ((*linep)->next) {
*linep = (*linep)->next;
*charp = text_get_cursor_rel(st, region, *linep, 0, col);
*charp = space_text_get_cursor_rel(st, region, *linep, 0, col);
}
else {
*charp = (*linep)->len;
@ -2186,13 +2193,15 @@ static void txt_wrap_move_down(SpaceText *st, ARegion *region, const bool sel)
}
}
/* Moves the cursor vertically by the specified number of lines.
/**
* Moves the cursor vertically by the specified number of lines.
* If the destination line is shorter than the current cursor position, the
* cursor will be positioned at the end of this line.
*
* This is to replace screen_skip for PageUp/Down operations.
*/
static void cursor_skip(SpaceText *st, ARegion *region, Text *text, int lines, const bool sel)
static void space_text_cursor_skip(
const SpaceText *st, const ARegion *region, Text *text, int lines, const bool sel)
{
TextLine **linep;
int *charp;
@ -2211,7 +2220,7 @@ static void cursor_skip(SpaceText *st, ARegion *region, Text *text, int lines, c
/* find line and offsets inside it needed to set cursor position */
if (cursor_skip_find_line(st, region, lines, linep, charp, &rell, &relc)) {
*charp = text_get_cursor_rel(st, region, *linep, rell, relc);
*charp = space_text_get_cursor_rel(st, region, *linep, rell, relc);
}
}
else {
@ -2332,24 +2341,24 @@ static int text_move_cursor(bContext *C, int type, bool select)
case PREV_PAGE:
if (st) {
cursor_skip(st, region, st->text, -st->runtime->viewlines, select);
space_text_cursor_skip(st, region, st->text, -st->runtime->viewlines, select);
}
else {
cursor_skip(nullptr, nullptr, text, -10, select);
space_text_cursor_skip(nullptr, nullptr, text, -10, select);
}
break;
case NEXT_PAGE:
if (st) {
cursor_skip(st, region, st->text, st->runtime->viewlines, select);
space_text_cursor_skip(st, region, st->text, st->runtime->viewlines, select);
}
else {
cursor_skip(nullptr, nullptr, text, 10, select);
space_text_cursor_skip(nullptr, nullptr, text, 10, select);
}
break;
}
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
if (select) {
text_select_update_primary_clipboard(st->text);
}
@ -2438,7 +2447,7 @@ static int text_jump_exec(bContext *C, wmOperator *op)
txt_move_toline(text, line - 1, false);
}
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
return OPERATOR_FINISHED;
@ -2488,7 +2497,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
Text *text = CTX_data_edit_text(C);
int type = RNA_enum_get(op->ptr, "type");
text_drawcache_tag_update(st, true);
space_text_drawcache_tag_update(st, true);
/* behavior could be changed here,
* but for now just don't jump words when we have a selection */
@ -2561,7 +2570,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
text_update_line_edited(text->curl);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
@ -2632,14 +2641,14 @@ void TEXT_OT_overwrite_toggle(wmOperatorType *ot)
/** \name Scroll Operator
* \{ */
static void txt_screen_clamp(SpaceText *st, ARegion *region)
static void space_text_screen_clamp(SpaceText *st, const ARegion *region)
{
if (st->top <= 0) {
st->top = 0;
}
else {
int last;
last = text_get_total_lines(st, region);
last = space_text_get_total_lines(st, region);
last = last - (st->runtime->viewlines / 2);
if (last > 0 && st->top > last) {
st->top = last;
@ -2648,10 +2657,10 @@ static void txt_screen_clamp(SpaceText *st, ARegion *region)
}
/* Moves the view vertically by the specified number of lines */
static void txt_screen_skip(SpaceText *st, ARegion *region, int lines)
static void space_text_screen_skip(SpaceText *st, ARegion *region, int lines)
{
st->top += lines;
txt_screen_clamp(st, region);
space_text_screen_clamp(st, region);
}
/* quick enum for tsc->zone (scroller handles) */
@ -2687,8 +2696,8 @@ static void text_scroll_state_init(TextScroll *tsc, SpaceText *st, ARegion *regi
tsc->state.ofs_init[1] = st->top;
tsc->state.ofs_max[0] = INT_MAX;
tsc->state.ofs_max[1] = max_ii(0,
text_get_total_lines(st, region) - (st->runtime->viewlines / 2));
tsc->state.ofs_max[1] = max_ii(
0, space_text_get_total_lines(st, region) - (st->runtime->viewlines / 2));
tsc->state.size_px[0] = st->runtime->cwidth_px;
tsc->state.size_px[1] = TXT_LINE_HEIGHT(st);
@ -2712,7 +2721,7 @@ static int text_scroll_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
txt_screen_skip(st, region, lines * 3);
space_text_screen_skip(st, region, lines * 3);
ED_area_tag_redraw(CTX_wm_area(C));
@ -2725,7 +2734,7 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
const int mval[2] = {event->xy[0], event->xy[1]};
text_update_character_width(st);
space_text_update_character_width(st);
/* compute mouse move distance */
if (tsc->is_first) {
@ -2843,10 +2852,10 @@ static int text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
case MIDDLEMOUSE:
if (event->val == KM_RELEASE) {
if (ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
txt_screen_skip(st,
region,
st->runtime->viewlines *
(tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1));
space_text_screen_skip(st,
region,
st->runtime->viewlines *
(tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1));
ED_area_tag_redraw(CTX_wm_area(C));
}
@ -2885,7 +2894,7 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
st->flags |= ST_SCROLL_SELECT;
if (event->type == MOUSEPAN) {
text_update_character_width(st);
space_text_update_character_width(st);
copy_v2_v2_int(tsc->mval_prev, event->xy);
/* Sensitivity of scroll set to 4pix per line/char */
@ -3088,7 +3097,9 @@ static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
return j;
}
static TextLine *get_line_pos_wrapped(SpaceText *st, ARegion *region, int *y)
static TextLine *space_text_get_line_pos_wrapped(const SpaceText *st,
const ARegion *region,
int *y)
{
TextLine *linep = static_cast<TextLine *>(st->text->lines.first);
int i, lines;
@ -3098,7 +3109,7 @@ static TextLine *get_line_pos_wrapped(SpaceText *st, ARegion *region, int *y)
}
for (i = -st->top; i <= *y && linep; linep = linep->next, i += lines) {
lines = text_get_visible_lines(st, region, linep->line);
lines = space_text_get_visible_lines(st, region, linep->line);
if (i + lines > *y) {
/* We found the line matching given vertical 'coordinate',
@ -3110,16 +3121,16 @@ static TextLine *get_line_pos_wrapped(SpaceText *st, ARegion *region, int *y)
return linep;
}
static void text_cursor_set_to_pos_wrapped(
SpaceText *st, ARegion *region, int x, int y, const bool sel)
static void space_text_cursor_set_to_pos_wrapped(
const SpaceText *st, const ARegion *region, int x, int y, const bool sel)
{
Text *text = st->text;
int max = wrap_width(st, region); /* column */
int charp = -1; /* mem */
bool found = false; /* flags */
int max = space_text_wrap_width(st, region); /* column */
int charp = -1; /* mem */
bool found = false; /* flags */
/* Point to line matching given y position, if any. */
TextLine *linep = get_line_pos_wrapped(st, region, &y);
TextLine *linep = space_text_get_line_pos_wrapped(st, region, &y);
if (linep) {
int i = 0, start = 0, end = max; /* column */
@ -3236,20 +3247,21 @@ static void text_cursor_set_to_pos_wrapped(
}
}
static void text_cursor_set_to_pos(SpaceText *st, ARegion *region, int x, int y, const bool sel)
static void text_cursor_set_to_pos(
SpaceText *st, const ARegion *region, int x, int y, const bool sel)
{
Text *text = st->text;
text_update_character_width(st);
space_text_update_character_width(st);
y = (region->winy - 2 - y) / TXT_LINE_HEIGHT(st);
x -= TXT_BODY_LEFT(st);
if (x < 0) {
x = 0;
}
x = text_pixel_x_to_column(st, x) + st->left;
x = space_text_pixel_x_to_column(st, x) + st->left;
if (st->wordwrap) {
text_cursor_set_to_pos_wrapped(st, region, x, y, sel);
space_text_cursor_set_to_pos_wrapped(st, region, x, y, sel);
}
else {
TextLine **linep;
@ -3327,7 +3339,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], true);
ED_text_scroll_to_cursor(st, region, false);
ED_space_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
}
@ -3337,7 +3349,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], true);
ED_text_scroll_to_cursor(st, region, false);
ED_space_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
}
@ -3346,7 +3358,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], true);
ED_text_scroll_to_cursor(st, region, false);
ED_space_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];
@ -3360,7 +3372,7 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
SpaceText *st = CTX_wm_space_text(C);
SetSelection *ssel = static_cast<SetSelection *>(op->customdata);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
text_select_update_primary_clipboard(st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
@ -3445,7 +3457,7 @@ static int text_cursor_set_exec(bContext *C, wmOperator *op)
text_cursor_set_to_pos(st, region, x, y, false);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
return OPERATOR_PASS_THROUGH;
@ -3498,7 +3510,7 @@ static int text_line_number_invoke(bContext *C, wmOperator * /*op*/, const wmEve
static int jump_to = 0;
static double last_jump = 0;
text_update_character_width(st);
space_text_update_character_width(st);
if (!st->showlinenrs) {
return OPERATOR_PASS_THROUGH;
@ -3527,7 +3539,7 @@ static int text_line_number_invoke(bContext *C, wmOperator * /*op*/, const wmEve
txt_move_toline(text, jump_to - 1, false);
last_jump = time;
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
return OPERATOR_FINISHED;
@ -3561,7 +3573,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
size_t i = 0;
uint code;
text_drawcache_tag_update(st, false);
space_text_drawcache_tag_update(st, false);
str = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, &str_len);
@ -3588,7 +3600,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
text_update_line_edited(text->curl);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
@ -3789,9 +3801,9 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
MEM_freeN(text->curl->format);
text->curl->format = nullptr;
}
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
text_drawcache_tag_update(st, true);
space_text_drawcache_tag_update(st, true);
}
}
MEM_freeN(tmp);
@ -3800,7 +3812,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
/* Find next */
if (txt_find_string(text, st->findstr, flags & ST_FIND_WRAP, flags & ST_MATCH_CASE)) {
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
}
else if (flags & ST_FIND_ALL) {
@ -3811,7 +3823,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
text = st->text = static_cast<Text *>(bmain->texts.first);
}
txt_move_toline(text, 0, false);
text_update_cursor_moved(C);
space_text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
}
else {
@ -3877,7 +3889,7 @@ static int text_replace_all(bContext *C)
} while (found);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
text_drawcache_tag_update(st, true);
space_text_drawcache_tag_update(st, true);
}
else {
/* Restore position */

View File

@ -207,8 +207,8 @@ static void text_undosys_step_decode(
/* Not essential, always show text being undo where possible. */
st->text = text;
}
text_update_cursor_moved(C);
text_drawcache_tag_update(st, true);
space_text_update_cursor_moved(C);
space_text_drawcache_tag_update(st, true);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
}

View File

@ -1938,7 +1938,7 @@ static void rna_SpaceTextEditor_text_set(PointerRNA *ptr,
if (area) {
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
if (region) {
ED_text_scroll_to_cursor(st, region, true);
ED_space_text_scroll_to_cursor(st, region, true);
}
}
}
@ -1960,7 +1960,7 @@ static void rna_SpaceTextEditor_updateEdited(Main * /*bmain*/, Scene * /*scene*/
static int rna_SpaceTextEditor_visible_lines_get(PointerRNA *ptr)
{
const SpaceText *st = static_cast<SpaceText *>(ptr->data);
return ED_text_visible_lines_get(st);
return ED_space_text_visible_lines_get(st);
}
/* Space Properties */

View File

@ -71,7 +71,7 @@ static void rna_SpaceTextEditor_region_location_from_cursor(
if (area) {
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
const int cursor_co[2] = {line, column};
ED_text_region_location_from_cursor(st, region, cursor_co, r_pixel_pos);
ED_space_text_region_location_from_cursor(st, region, cursor_co, r_pixel_pos);
}
}