320
315
static int text_reload_exec(bContext *C, wmOperator *op)
317
SpaceText *st = CTX_wm_space_text(C);
322
318
Text *text = CTX_data_edit_text(C);
319
ARegion *ar = CTX_wm_region(C);
321
/* store view & cursor state */
322
const int orig_top = st->top;
323
const int orig_curl = BLI_findindex(&text->lines, text->curl);
324
const int orig_curc = text->curc;
324
326
if (!BKE_text_reload(text)) {
325
327
BKE_report(op->reports, RPT_ERROR, "Could not reopen file");
1408
1415
for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe(linein->line + j)) {
1417
int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab */
1410
1419
/* Mimic replacement of tabs */
1411
1420
ch = linein->line[j];
1412
1421
if (ch == '\t') {
1413
1422
chars = st->tabnumber - i % st->tabnumber;
1418
1429
while (chars--) {
1419
if (rell == 0 && i - start == relc) {
1430
if (rell == 0 && i - start <= relc && i + columns - start > relc) {
1420
1431
/* current position could be wrapped to next line */
1421
1432
/* this should be checked when end of current line would be reached */
1425
else if (i - end == relc) {
1436
else if (i - end <= relc && i + columns - end > relc) {
1428
if (i - start >= max) {
1439
if (i + columns - start > max) {
1430
1443
/* exact cursor position was found, check if it's */
1431
1444
/* still on needed line (hasn't been wrapped) */
1964
1999
static int text_delete_exec(bContext *C, wmOperator *op)
2001
SpaceText *st = CTX_wm_space_text(C);
1966
2002
Text *text = CTX_data_edit_text(C);
1967
2003
int type = RNA_enum_get(op->ptr, "type");
1969
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
1971
if (type == DEL_PREV_WORD)
2005
text_drawcache_tag_update(st, 0);
2007
/* behavior could be changed here,
2008
* but for now just don't jump words when we have a selection */
2009
if (txt_has_sel(text)) {
2010
if (type == DEL_PREV_WORD) type = DEL_PREV_CHAR;
2011
else if (type == DEL_NEXT_WORD) type = DEL_NEXT_CHAR;
2014
if (type == DEL_PREV_WORD) {
2015
if (txt_cursor_is_line_start(text)) {
2016
txt_backspace_char(text);
1972
2018
txt_backspace_word(text);
1973
else if (type == DEL_PREV_CHAR)
2020
else if (type == DEL_PREV_CHAR) {
1974
2021
txt_backspace_char(text);
1975
else if (type == DEL_NEXT_WORD)
2023
else if (type == DEL_NEXT_WORD) {
2024
if (txt_cursor_is_line_end(text)) {
2025
txt_delete_char(text);
1976
2027
txt_delete_word(text);
1977
else if (type == DEL_NEXT_CHAR)
2029
else if (type == DEL_NEXT_CHAR) {
1978
2030
txt_delete_char(text);
1980
2033
text_update_line_edited(text->curl);
2032
2085
/******************* scroll operator **********************/
2087
static void txt_screen_clamp(SpaceText *st, ARegion *ar)
2090
last = text_get_total_lines(st, ar);
2091
last = last - (st->viewlines / 2);
2092
CLAMP(st->top, 0, last);
2034
2095
/* Moves the view vertically by the specified number of lines */
2035
2096
static void txt_screen_skip(SpaceText *st, ARegion *ar, int lines)
2039
2098
st->top += lines;
2041
last = text_get_total_lines(st, ar);
2042
last = last - (st->viewlines / 2);
2044
if (st->top > last) st->top = last;
2045
if (st->top < 0) st->top = 0;
2099
txt_screen_clamp(st, ar);
2048
2102
/* quick enum for tsc->zone (scroller handles) */
2350
2397
if (str[i] == '\t') {
2351
2398
total += st->tabnumber - total % st->tabnumber;
2401
total += BLI_str_utf8_char_width_safe(str + i);
2359
static int flatten_index_to_offset(SpaceText *st, const char *str, int index)
2408
static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
2362
for (i = 0, j = 0; i < index; j += BLI_str_utf8_size_safe(str + j))
2410
int i = 0, j = 0, col;
2412
while (*(str + j)) {
2363
2413
if (str[j] == '\t')
2364
i += st->tabnumber - i % st->tabnumber;
2414
col = st->tabnumber - i % st->tabnumber;
2416
col = BLI_str_utf8_char_width_safe(str + j);
2418
if (i + col > index)
2422
j += BLI_str_utf8_size_safe(str + j);
2399
2456
TextLine *linep = get_first_visible_line(st, ar, &y);
2401
2458
while (loop && linep) {
2402
int i = 0, start = 0, end = max; /* view */
2459
int i = 0, start = 0, end = max; /* column */
2403
2460
int j = 0, curs = 0, endj = 0; /* mem */
2404
2461
int chop = 1; /* flags */
2406
2463
for (; loop; j += BLI_str_utf8_size_safe(linep->line + j)) {
2465
int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */
2409
2467
/* Mimic replacement of tabs */
2410
2468
ch = linep->line[j];
2535
w = flatten_len(st, (*linep)->line);
2536
if (x < w) *charp = flatten_index_to_offset(st, (*linep)->line, x);
2597
w = flatten_width(st, (*linep)->line);
2598
if (x < w) *charp = flatten_column_to_offset(st, (*linep)->line, x);
2537
2599
else *charp = (*linep)->len;
2539
2601
if (!sel) txt_pop_sel(text);
2542
static void text_cursor_set_apply(bContext *C, wmOperator *op, wmEvent *event)
2604
static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event)
2544
2606
SpaceText *st = CTX_wm_space_text(C);
2545
2607
ARegion *ar = CTX_wm_region(C);
3111
3173
if (text->flags & TXT_ISDIRTY) {
3112
3174
/* modified locally and externally, ahhh. offer more possibilites. */
3113
pup = uiPupMenuBegin(C, "File Modified Outside and Inside Blender", ICON_NONE);
3175
pup = uiPupMenuBegin(C, IFACE_("File Modified Outside and Inside Blender"), ICON_NONE);
3114
3176
layout = uiPupMenuLayout(pup);
3115
uiItemEnumO_ptr(layout, op->type, "Reload from disk (ignore local changes)", 0, "resolution", RESOLVE_RELOAD);
3116
uiItemEnumO_ptr(layout, op->type, "Save to disk (ignore outside changes)", 0, "resolution", RESOLVE_SAVE);
3117
uiItemEnumO_ptr(layout, op->type, "Make text internal (separate copy)", 0, "resolution", RESOLVE_MAKE_INTERNAL);
3177
uiItemEnumO_ptr(layout, op->type, IFACE_("Reload from disk (ignore local changes)"),
3178
0, "resolution", RESOLVE_RELOAD);
3179
uiItemEnumO_ptr(layout, op->type, IFACE_("Save to disk (ignore outside changes)"),
3180
0, "resolution", RESOLVE_SAVE);
3181
uiItemEnumO_ptr(layout, op->type, IFACE_("Make text internal (separate copy)"),
3182
0, "resolution", RESOLVE_MAKE_INTERNAL);
3118
3183
uiPupMenuEnd(C, pup);
3121
pup = uiPupMenuBegin(C, "File Modified Outside Blender", ICON_NONE);
3186
pup = uiPupMenuBegin(C, IFACE_("File Modified Outside Blender"), ICON_NONE);
3122
3187
layout = uiPupMenuLayout(pup);
3123
uiItemEnumO_ptr(layout, op->type, "Reload from disk", 0, "resolution", RESOLVE_RELOAD);
3124
uiItemEnumO_ptr(layout, op->type, "Make text internal (separate copy)", 0, "resolution", RESOLVE_MAKE_INTERNAL);
3125
uiItemEnumO_ptr(layout, op->type, "Ignore", 0, "resolution", RESOLVE_IGNORE);
3188
uiItemEnumO_ptr(layout, op->type, IFACE_("Reload from disk"), 0, "resolution", RESOLVE_RELOAD);
3189
uiItemEnumO_ptr(layout, op->type, IFACE_("Make text internal (separate copy)"),
3190
0, "resolution", RESOLVE_MAKE_INTERNAL);
3191
uiItemEnumO_ptr(layout, op->type, IFACE_("Ignore"), 0, "resolution", RESOLVE_IGNORE);
3126
3192
uiPupMenuEnd(C, pup);
3130
pup = uiPupMenuBegin(C, "File Deleted Outside Blender", ICON_NONE);
3196
pup = uiPupMenuBegin(C, IFACE_("File Deleted Outside Blender"), ICON_NONE);
3131
3197
layout = uiPupMenuLayout(pup);
3132
uiItemEnumO_ptr(layout, op->type, "Make text internal", 0, "resolution", RESOLVE_MAKE_INTERNAL);
3133
uiItemEnumO_ptr(layout, op->type, "Recreate file", 0, "resolution", RESOLVE_SAVE);
3198
uiItemEnumO_ptr(layout, op->type, IFACE_("Make text internal"), 0, "resolution", RESOLVE_MAKE_INTERNAL);
3199
uiItemEnumO_ptr(layout, op->type, IFACE_("Recreate file"), 0, "resolution", RESOLVE_SAVE);
3134
3200
uiPupMenuEnd(C, pup);