Blender V5.3
text_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cerrno>
11#include <cstring>
12#include <sstream>
13
14#include "MEM_guardedalloc.h"
15
16#include "DNA_camera_types.h"
17#include "DNA_text_types.h"
18
19#include "BLI_fileops.hh"
20#include "BLI_listbase.hh"
21#include "BLI_math_base_c.hh"
22#include "BLI_math_vector_c.hh"
23#include "BLI_path_utils.hh"
24#include "BLI_rect.hh"
25#include "BLI_string.hh"
27#include "BLI_string_utf8.hh"
28#include "BLI_time.hh"
29#include "BLI_vector_set.hh"
30
31#include "BLT_translation.hh"
32
33#include "BKE_context.hh"
34#include "BKE_global.hh"
35#include "BKE_lib_id.hh"
36#include "BKE_main.hh"
37#include "BKE_node.hh"
39#include "BKE_node_runtime.hh"
40#include "BKE_report.hh"
41#include "BKE_text.h"
42
43#include "WM_api.hh"
44#include "WM_types.hh"
45
46#include "ED_curve.hh"
47#include "ED_screen.hh"
48#include "ED_text.hh"
49
50#include "UI_interface.hh"
52#include "UI_resources.hh"
53
54#include "RE_engine.h"
55
56#include "RNA_access.hh"
57#include "RNA_define.hh"
58
59#ifdef WITH_PYTHON
60# include "BPY_extern.hh"
61# include "BPY_extern_run.hh"
62#endif
63
64#include "text_format.hh"
65#include "text_intern.hh"
66
67namespace blender {
68
69static void space_text_screen_clamp(SpaceText *st, const ARegion *region);
70
71/* -------------------------------------------------------------------- */
74
82static void test_line_start(char c, bool *r_last_state)
83{
84 if (c == '\n') {
85 *r_last_state = true;
86 }
87 else if (!ELEM(c, '\t', ' ')) {
88 *r_last_state = false;
89 }
90}
91
97static char text_closing_character_pair_get(const char character)
98{
99
100 switch (character) {
101 case '(':
102 return ')';
103 case '[':
104 return ']';
105 case '{':
106 return '}';
107 case '"':
108 return '"';
109 case '\'':
110 return '\'';
111 default:
112 return 0;
113 }
114}
115
124static bool text_span_is_blank(TextLine *line1,
125 const int line1_char,
126 TextLine *line2,
127 const int line2_char)
128{
129 const TextLine *start_line;
130 const TextLine *end_line;
131 int start_char;
132 int end_char;
133
134 /* Get the start and end lines. */
135 if (txt_get_span(line1, line2) > 0 || (line1 == line2 && line1_char <= line2_char)) {
136 start_line = line1;
137 end_line = line2;
138 start_char = line1_char;
139 end_char = line2_char;
140 }
141 else {
142 start_line = line2;
143 end_line = line1;
144 start_char = line2_char;
145 end_char = line1_char;
146 }
147
148 for (const TextLine *line = start_line; line != end_line->next; line = line->next) {
149 const int start = (line == start_line) ? start_char : 0;
150 const int end = (line == end_line) ? end_char : line->len;
151
152 for (int i = start; i < end; i++) {
153 if (!ELEM(line->line[i], ' ', '\t', '\n')) {
154 return false;
155 }
156 }
157 }
158
159 return true;
160}
161
168static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size, int *r_out_buf_len)
169{
170 /* Get the number of tab characters in buffer. */
171 bool line_start = true;
172 int num_tabs = 0;
173
174 for (int in_offset = 0; in_buf[in_offset]; in_offset++) {
175 /* Verify if is an indentation whitespace character. */
176 test_line_start(in_buf[in_offset], &line_start);
177
178 if (in_buf[in_offset] == '\t' && line_start) {
179 num_tabs++;
180 }
181 }
182
183 /* Allocate output before with extra space for expanded tabs. */
184 const int out_size = strlen(in_buf) + num_tabs * (tab_size - 1) + 1;
185 char *out_buf = MEM_new_array_uninitialized<char>(out_size, __func__);
186
187 /* Fill output buffer. */
188 int spaces_until_tab = 0;
189 int out_offset = 0;
190 line_start = true;
191
192 for (int in_offset = 0; in_buf[in_offset]; in_offset++) {
193 /* Verify if is an indentation whitespace character. */
194 test_line_start(in_buf[in_offset], &line_start);
195
196 if (in_buf[in_offset] == '\t' && line_start) {
197 /* Calculate tab size so it fills until next indentation. */
198 int num_spaces = tab_size - (spaces_until_tab % tab_size);
199 spaces_until_tab = 0;
200
201 /* Write to buffer. */
202 memset(&out_buf[out_offset], ' ', num_spaces);
203 out_offset += num_spaces;
204 }
205 else {
206 if (in_buf[in_offset] == ' ') {
207 spaces_until_tab++;
208 }
209 else if (in_buf[in_offset] == '\n') {
210 spaces_until_tab = 0;
211 }
212
213 out_buf[out_offset++] = in_buf[in_offset];
214 }
215 }
216
217 out_buf[out_offset] = '\0';
218 *r_out_buf_len = out_offset;
219 return out_buf;
220}
221
223{
224 /* Add half the char width so mouse cursor selection is in between letters. */
225 return (x + (st->runtime->char_width_px / 2)) / st->runtime->char_width_px;
226}
227
229{
230 if (G.background) {
231 return;
232 }
234 return;
235 }
236 if (!txt_has_sel(text)) {
237 return;
238 }
239 char *buf = txt_sel_to_buf(text, nullptr);
240 if (buf == nullptr) {
241 return;
242 }
243 WM_clipboard_text_set(buf, true);
244 MEM_delete(buf);
245}
246
248
249/* -------------------------------------------------------------------- */
252
253static bool text_new_poll(bContext * /*C*/)
254{
255 return true;
256}
257
259{
260 Text *text = CTX_data_edit_text(C);
261 if (!text) {
262 return false;
263 }
264 return true;
265}
266
268{
269 Text *text = CTX_data_edit_text(C);
270
271 if (!text) {
272 return false;
273 }
274
275 if (!BKE_id_is_editable(CTX_data_main(C), &text->id)) {
276 // BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
277 return false;
278 }
279
280 return true;
281}
282
284{
286 Text *text = CTX_data_edit_text(C);
287
288 if (!st || !text) {
289 return false;
290 }
291
292 if (!BKE_id_is_editable(CTX_data_main(C), &text->id)) {
293 // BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
294 return false;
295 }
296
297 return true;
298}
299
301{
303 Text *text = CTX_data_edit_text(C);
304 ARegion *region = CTX_wm_region(C);
305
306 if (!st || !text) {
307 return false;
308 }
309
310 if (!region || region->regiontype != RGN_TYPE_WINDOW) {
311 return false;
312 }
313
314 if (!BKE_id_is_editable(CTX_data_main(C), &text->id)) {
315 // BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
316 return false;
317 }
318
319 return true;
320}
321
323
324/* -------------------------------------------------------------------- */
327
329{
330 if (!line) {
331 return;
332 }
333
334 /* We just free format here, and let it rebuild during draw. */
335 MEM_SAFE_DELETE(line->format);
336}
337
339{
340 for (TextLine &line : text->lines) {
342 }
343}
344
346
347/* -------------------------------------------------------------------- */
350
352{
354 Main *bmain = CTX_data_main(C);
355 Text *text;
356 PointerRNA ptr;
357 PropertyRNA *prop;
358
359 text = BKE_text_add(bmain, DATA_("Text"));
360
361 /* Hook into UI. */
363
364 if (prop) {
365 PointerRNA idptr = RNA_id_pointer_create(&text->id);
366 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
367 RNA_property_update(C, &ptr, prop);
368 }
369 else if (st) {
370 st->text = text;
371 st->left = 0;
372 st->top = 0;
373 st->runtime->scroll_ofs_px[0] = 0;
374 st->runtime->scroll_ofs_px[1] = 0;
376 }
377
379
380 return OPERATOR_FINISHED;
381}
382
384{
385 /* Identifiers. */
386 ot->name = "New Text";
387 ot->idname = "TEXT_OT_new";
388 ot->description = "Create a new text data-block";
389
390 /* API callbacks. */
391 ot->exec = text_new_exec;
392 ot->poll = text_new_poll;
393
394 /* Flags. */
395 ot->flag = OPTYPE_UNDO;
396}
397
399
400/* -------------------------------------------------------------------- */
403
405{
406 PropertyPointerRNA *pprop = MEM_new<PropertyPointerRNA>(__func__);
407
408 op->customdata = pprop;
410}
411
412static void text_open_cancel(bContext * /*C*/, wmOperator *op)
413{
414 MEM_delete(static_cast<PropertyPointerRNA *>(op->customdata));
415}
416
418{
420 Main *bmain = CTX_data_main(C);
421 Text *text;
422 char filepath[FILE_MAX];
423 const bool internal = RNA_boolean_get(op->ptr, "internal");
424
425 RNA_string_get(op->ptr, "filepath", filepath);
426
427 text = BKE_text_load_ex(bmain, filepath, BKE_main_blendfile_path(bmain), internal);
428
429 if (!text) {
430 PropertyPointerRNA *pprop = static_cast<PropertyPointerRNA *>(op->customdata);
431 MEM_delete(pprop);
432 op->customdata = nullptr;
433 return OPERATOR_CANCELLED;
434 }
435
436 if (!op->customdata) {
437 text_open_init(C, op);
438 }
439
440 /* Hook into UI. */
441 PropertyPointerRNA *pprop = static_cast<PropertyPointerRNA *>(op->customdata);
442 if (pprop->prop) {
443 PointerRNA idptr = RNA_id_pointer_create(&text->id);
444 RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, nullptr);
445 RNA_property_update(C, &pprop->ptr, pprop->prop);
446 }
447 else if (st) {
448 st->text = text;
449 st->left = 0;
450 st->top = 0;
451 st->runtime->scroll_ofs_px[0] = 0;
452 st->runtime->scroll_ofs_px[1] = 0;
453 }
454
457
458 MEM_delete(pprop);
459
460 return OPERATOR_FINISHED;
461}
462
464{
465 Main *bmain = CTX_data_main(C);
466 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
467 return text_open_exec(C, op);
468 }
469
470 Text *text = CTX_data_edit_text(C);
471 const char *filepath = nullptr;
472 char filepath_buf[FILE_MAX];
473 if (text && text->filepath) {
474 if (BLI_path_is_rel(text->filepath)) {
475 STRNCPY(filepath_buf, text->filepath);
476 BLI_path_abs(filepath_buf, ID_BLEND_PATH(bmain, &text->id));
477 filepath = filepath_buf;
478 }
479 else {
480 filepath = text->filepath;
481 }
482 }
483 else {
484 filepath = BKE_main_blendfile_path(bmain);
485 }
486 BLI_assert(filepath != nullptr);
487
488 text_open_init(C, op);
489 RNA_string_set(op->ptr, "filepath", filepath);
491
493}
494
496{
497 /* Identifiers. */
498 ot->name = "Open Text";
499 ot->idname = "TEXT_OT_open";
500 ot->description = "Open a new text data-block";
501
502 /* API callbacks. */
503 ot->exec = text_open_exec;
506 ot->poll = text_new_poll;
507
508 /* Flags. */
509 ot->flag = OPTYPE_UNDO;
510
511 /* Properties. */
520 ot->srna, "internal", false, "Make Internal", "Make text file internal after loading");
521}
522
524
525/* -------------------------------------------------------------------- */
528
530{
532 Text *text = CTX_data_edit_text(C);
533 ARegion *region = CTX_wm_region(C);
534
535 /* Store view & cursor state. */
536 const int orig_top = st->top;
537 const int orig_curl = BLI_findindex(&text->lines, text->curl);
538 const int orig_curc = text->curc;
539
540 /* Don't make this part of `poll`, since `Alt-R` will type `R`,
541 * if poll checks for the filename. */
542 if (text->filepath == nullptr) {
543 BKE_report(op->reports, RPT_ERROR, "This text has not been saved");
544 return OPERATOR_CANCELLED;
545 }
546
547 if (!BKE_text_reload(text)) {
548 BKE_report(op->reports, RPT_ERROR, "Could not reopen file");
549 return OPERATOR_CANCELLED;
550 }
551
552#ifdef WITH_PYTHON
553 if (text->compiled) {
554 BPY_text_free_code(text);
555 }
556#endif
557
558 text_update_edited(text);
562
563 text->flags &= ~TXT_ISDIRTY;
564
565 /* Return to scroll position. */
566 st->top = orig_top;
567 space_text_screen_clamp(st, region);
568 /* Return cursor. */
569 txt_move_to(text, orig_curl, orig_curc, false);
570
571 return OPERATOR_FINISHED;
572}
573
575{
577 op,
578 IFACE_("Reload active text file?"),
579 nullptr,
580 IFACE_("Reload"),
582 false);
583}
584
586{
587 /* Identifiers. */
588 ot->name = "Reload";
589 ot->idname = "TEXT_OT_reload";
590 ot->description = "Reload active text data-block from its file";
591
592 /* API callbacks. */
595 ot->poll = text_edit_poll;
596}
597
599
600/* -------------------------------------------------------------------- */
603
605{
606 /* It should be possible to unlink texts if they're lib-linked in. */
607 return CTX_data_edit_text(C) != nullptr;
608}
609
611{
612 Main *bmain = CTX_data_main(C);
614 Text *text = CTX_data_edit_text(C);
615
616 /* Make the previous text active, if its not there make the next text active. */
617 if (st) {
618 if (text->id.prev) {
619 st->text = static_cast<Text *>(text->id.prev);
621 }
622 else if (text->id.next) {
623 st->text = static_cast<Text *>(text->id.next);
625 }
626 }
627
628 BKE_id_delete(bmain, text);
629
632
633 return OPERATOR_FINISHED;
634}
635
637{
639 op,
640 IFACE_("Delete active text file?"),
641 nullptr,
642 IFACE_("Delete"),
644 false);
645}
646
648{
649 /* Identifiers. */
650 ot->name = "Unlink";
651 ot->idname = "TEXT_OT_unlink";
652 ot->description = "Unlink active text data-block";
653
654 /* API callbacks. */
658
659 /* Flags. */
660 ot->flag = OPTYPE_UNDO;
661}
662
664
665/* -------------------------------------------------------------------- */
668
670{
671 Text *text = CTX_data_edit_text(C);
672
673 text->flags |= TXT_ISMEM | TXT_ISDIRTY;
674
675 MEM_SAFE_DELETE(text->filepath);
676
679
680 return OPERATOR_FINISHED;
681}
682
684{
685 /* Identifiers. */
686 ot->name = "Make Internal";
687 ot->idname = "TEXT_OT_make_internal";
688 ot->description = "Make active text file internal";
689
690 /* API callbacks. */
692 ot->poll = text_edit_poll;
693
694 /* Flags. */
695 ot->flag = OPTYPE_UNDO;
696}
697
699
700/* -------------------------------------------------------------------- */
703
704static void txt_write_file(Main *bmain, Text *text, ReportList *reports)
705{
706 FILE *fp;
707 BLI_stat_t st;
708 char filepath[FILE_MAX];
709
710 if (text->filepath == nullptr) {
711 BKE_reportf(reports, RPT_ERROR, "No file path for \"%s\"", text->id.name + 2);
712 return;
713 }
714
715 STRNCPY(filepath, text->filepath);
716 BLI_path_abs(filepath, BKE_main_blendfile_path(bmain));
717
718 /* Check if file write permission is ok. */
719 if (BLI_exists(filepath) && !BLI_file_is_writable(filepath)) {
721 reports, RPT_ERROR, "Cannot save text file, path \"%s\" is not writable", filepath);
722 return;
723 }
724
725 fp = BLI_fopen(filepath, "w");
726 if (fp == nullptr) {
727 BKE_reportf(reports,
728 RPT_ERROR,
729 "Unable to save '%s': %s",
730 filepath,
731 errno ? strerror(errno) : RPT_("unknown error writing file"));
732 return;
733 }
734
735 for (TextLine &tmp : text->lines) {
736 fputs(tmp.line, fp);
737 if (tmp.next) {
738 fputc('\n', fp);
739 }
740 }
741
742 fclose(fp);
743
744 if (BLI_stat(filepath, &st) == 0) {
745 text->mtime = st.st_mtime;
746
747 /* Report since this can be called from key shortcuts. */
748 BKE_reportf(reports, RPT_INFO, "Saved text \"%s\"", filepath);
749 }
750 else {
751 text->mtime = 0;
752 BKE_reportf(reports,
754 "Unable to stat '%s': %s",
755 filepath,
756 errno ? strerror(errno) : RPT_("unknown error statting file"));
757 }
758
759 text->flags &= ~TXT_ISDIRTY;
760}
761
763{
764 Main *bmain = CTX_data_main(C);
765 Text *text = CTX_data_edit_text(C);
766
767 txt_write_file(bmain, text, op->reports);
768
771
772 return OPERATOR_FINISHED;
773}
774
776{
777 Text *text = CTX_data_edit_text(C);
778
779 /* Internal and texts without a filepath will go to "Save As". */
780 if (text->filepath == nullptr || (text->flags & TXT_ISMEM)) {
781 WM_operator_name_call(C, "TEXT_OT_save_as", wm::OpCallContext::InvokeDefault, nullptr, event);
782 return OPERATOR_CANCELLED;
783 }
784 return text_save_exec(C, op);
785}
786
788{
789 /* Identifiers. */
790 ot->name = "Save";
791 ot->idname = "TEXT_OT_save";
792 ot->description = "Save active text data-block";
793
794 /* API callbacks. */
795 ot->exec = text_save_exec;
797 ot->poll = text_edit_poll;
798}
799
801
802/* -------------------------------------------------------------------- */
805
807{
808 Main *bmain = CTX_data_main(C);
809 Text *text = CTX_data_edit_text(C);
810 char filepath[FILE_MAX];
811
812 if (!text) {
813 return OPERATOR_CANCELLED;
814 }
815
816 RNA_string_get(op->ptr, "filepath", filepath);
817
818 if (text->filepath) {
819 MEM_delete(text->filepath);
820 }
821 text->filepath = BLI_strdup(filepath);
822 text->flags &= ~TXT_ISMEM;
823
824 txt_write_file(bmain, text, op->reports);
825
828
829 return OPERATOR_FINISHED;
830}
831
833{
834 Main *bmain = CTX_data_main(C);
835 Text *text = CTX_data_edit_text(C);
836
837 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
838 return text_save_as_exec(C, op);
839 }
840
841 const char *filepath = nullptr;
842 char filepath_buf[FILE_MAX];
843 if (text->filepath) {
844 if (BLI_path_is_rel(text->filepath)) {
845 STRNCPY(filepath_buf, text->filepath);
846 BLI_path_abs(filepath_buf, ID_BLEND_PATH(bmain, &text->id));
847 filepath = filepath_buf;
848 }
849 else {
850 filepath = text->filepath;
851 }
852 }
853 else if (text->flags & TXT_ISMEM) {
854 filepath = text->id.name + 2;
855 }
856 else {
857 filepath = BKE_main_blendfile_path(bmain);
858 }
859 BLI_assert(filepath != nullptr);
860
861 RNA_string_set(op->ptr, "filepath", filepath);
863
865}
866
868{
869 /* Identifiers. */
870 ot->name = "Save As";
871 ot->idname = "TEXT_OT_save_as";
872 ot->description = "Save active text file with options";
873
874 /* API callbacks. */
877 ot->poll = text_edit_poll;
878
879 /* Properties. */
883 FILE_SAVE,
886 FILE_SORT_DEFAULT); /* XXX TODO: relative_path. */
887}
888
890
891/* -------------------------------------------------------------------- */
894
896{
897#ifdef WITH_PYTHON
898 Text *text = CTX_data_edit_text(C);
899 const bool is_live = (reports == nullptr);
900
901 /* Only for comparison. */
902 void *curl_prev = text->curl;
903 int curc_prev = text->curc;
904 int selc_prev = text->selc;
905
906 if (BPY_run_text(C, text, reports, !is_live)) {
907 if (is_live) {
908 /* For nice live updates. */
910 }
911 return OPERATOR_FINISHED;
912 }
913
914 /* Don't report error messages while live editing. */
915 if (!is_live) {
916 /* Text may have freed itself. */
917 if (CTX_data_edit_text(C) == text) {
918 if (text->curl != curl_prev || curc_prev != text->curc || selc_prev != text->selc) {
921 }
922 }
923
924 /* No need to report the error, this has already been handled by #BPY_run_text. */
925 return OPERATOR_FINISHED;
926 }
927#else
928 (void)C;
929 (void)reports;
930#endif /* !WITH_PYTHON */
931 return OPERATOR_CANCELLED;
932}
933
935{
936#ifndef WITH_PYTHON
937 UNUSED_VARS(C);
938
939 BKE_report(op->reports, RPT_ERROR, "Python disabled in this build");
940
941 return OPERATOR_CANCELLED;
942#else
943 return text_run_script(C, op->reports);
944#endif /* WITH_PYTHON */
945}
946
948{
949 /* Identifiers. */
950 ot->name = "Run Script";
951 ot->idname = "TEXT_OT_run_script";
952 ot->description = "Run active script";
953
954 /* API callbacks. */
955 ot->poll = text_data_poll;
957
958 /* Flags. */
960}
961
963
964/* -------------------------------------------------------------------- */
967
969{
971 Text *text = CTX_data_edit_text(C);
972
973 const bool selection = RNA_boolean_get(op->ptr, "selection");
974
975 char *buf;
976 int buf_len;
977
978 /* No need for UTF8 validation as the conversion handles invalid sequences gracefully. */
979 buf = WM_clipboard_text_get(selection, false, &buf_len);
980
981 if (!buf) {
982 return OPERATOR_CANCELLED;
983 }
984
986
988
989 /* Convert clipboard content indentation to spaces if specified. */
990 if (text->flags & TXT_TABSTOSPACES) {
991 char *new_buf = buf_tabs_to_spaces(buf, TXT_TABSIZE, &buf_len);
992 MEM_delete(buf);
993 buf = new_buf;
994 }
995
996 txt_insert_buf(text, buf, buf_len);
997 text_update_edited(text);
998
999 MEM_delete(buf);
1000
1003
1004 /* Run the script while editing, evil but useful. */
1005 if (st->live_edit) {
1006 text_run_script(C, nullptr);
1007 }
1008
1009 return OPERATOR_FINISHED;
1010}
1011
1013{
1014 /* Identifiers. */
1015 ot->name = "Paste";
1016 ot->idname = "TEXT_OT_paste";
1017 ot->description = "Paste text from clipboard";
1018
1019 /* API callbacks. */
1020 ot->exec = text_paste_exec;
1021 ot->poll = text_edit_poll;
1022
1023 /* Flags. */
1024 ot->flag = OPTYPE_UNDO;
1025
1026 /* Properties. */
1027 PropertyRNA *prop;
1028 prop = RNA_def_boolean(ot->srna,
1029 "selection",
1030 false,
1031 "Selection",
1032 "Paste text selected elsewhere rather than copied (X11/Wayland only)");
1034}
1035
1037
1038/* -------------------------------------------------------------------- */
1041
1043{
1044 Text *text = CTX_data_edit_text(C);
1045
1047
1048 txt_duplicate_line(text);
1049
1051
1052 /* Run the script while editing, evil but useful. */
1053 if (CTX_wm_space_text(C)->live_edit) {
1054 text_run_script(C, nullptr);
1055 }
1056
1057 return OPERATOR_FINISHED;
1058}
1059
1061{
1062 /* Identifiers. */
1063 ot->name = "Duplicate Line";
1064 ot->idname = "TEXT_OT_duplicate_line";
1065 ot->description = "Duplicate the current line";
1066
1067 /* API callbacks. */
1069 ot->poll = text_edit_poll;
1070
1071 /* Flags. */
1072 ot->flag = OPTYPE_UNDO;
1073}
1074
1076
1077/* -------------------------------------------------------------------- */
1080
1081static void txt_copy_clipboard(const Text *text)
1082{
1083 char *buf;
1084
1085 if (!txt_has_sel(text)) {
1086 return;
1087 }
1088
1089 buf = txt_sel_to_buf(text, nullptr);
1090
1091 if (buf) {
1092 WM_clipboard_text_set(buf, false);
1093 MEM_delete(buf);
1094 }
1095}
1096
1098{
1099 const Text *text = CTX_data_edit_text(C);
1100
1101 txt_copy_clipboard(text);
1102
1103 return OPERATOR_FINISHED;
1104}
1105
1107{
1108 /* Identifiers. */
1109 ot->name = "Copy";
1110 ot->idname = "TEXT_OT_copy";
1111 ot->description = "Copy selected text to clipboard";
1112
1113 /* API callbacks. */
1114 ot->exec = text_copy_exec;
1115 ot->poll = text_edit_poll;
1116}
1117
1119
1120/* -------------------------------------------------------------------- */
1123
1125{
1127 Text *text = CTX_data_edit_text(C);
1128
1130
1131 txt_copy_clipboard(text);
1132
1134 txt_delete_selected(text);
1135
1138
1139 /* Run the script while editing, evil but useful. */
1140 if (st->live_edit) {
1141 text_run_script(C, nullptr);
1142 }
1143
1144 return OPERATOR_FINISHED;
1145}
1146
1148{
1149 /* Identifiers. */
1150 ot->name = "Cut";
1151 ot->idname = "TEXT_OT_cut";
1152 ot->description = "Cut selected text to clipboard";
1153
1154 /* API callbacks. */
1155 ot->exec = text_cut_exec;
1156 ot->poll = text_edit_poll;
1157
1158 /* Flags. */
1159 ot->flag = OPTYPE_UNDO;
1160}
1161
1163
1164/* -------------------------------------------------------------------- */
1167
1169{
1170 Text *text = CTX_data_edit_text(C);
1171 TextLine *line = text->curl;
1172 bool text_before_cursor = text->curc != 0 && !ELEM(line->line[text->curc - 1], ' ', '\t');
1173 if (text_before_cursor && (txt_has_sel(text) == false)) {
1175 C, "TEXT_OT_autocomplete", wm::OpCallContext::InvokeDefault, nullptr, nullptr);
1176 }
1177 else {
1178 WM_operator_name_call(C, "TEXT_OT_indent", wm::OpCallContext::ExecDefault, nullptr, nullptr);
1179 }
1180 return OPERATOR_FINISHED;
1181}
1182
1184{
1185 /* Identifiers. */
1186 ot->name = "Indent or Autocomplete";
1187 ot->idname = "TEXT_OT_indent_or_autocomplete";
1188 ot->description = "Indent selected text or autocomplete";
1189
1190 /* API callbacks. */
1192 ot->poll = text_edit_poll;
1193
1194 /* Flags. */
1195 ot->flag = 0;
1196}
1197
1199
1200/* -------------------------------------------------------------------- */
1203
1205{
1207 Text *text = CTX_data_edit_text(C);
1208
1210
1212
1213 if (txt_has_sel(text)) {
1214 txt_order_cursors(text, false);
1215 txt_indent(text);
1216 }
1217 else {
1218 txt_add_char(text, '\t');
1219 }
1220
1221 text_update_edited(text);
1222
1225
1226 return OPERATOR_FINISHED;
1227}
1228
1230{
1231 /* Identifiers. */
1232 ot->name = "Indent";
1233 ot->idname = "TEXT_OT_indent";
1234 ot->description = "Indent selected text";
1235
1236 /* API callbacks. */
1237 ot->exec = text_indent_exec;
1238 ot->poll = text_edit_poll;
1239
1240 /* Flags. */
1241 ot->flag = OPTYPE_UNDO;
1242}
1243
1245
1246/* -------------------------------------------------------------------- */
1249
1251{
1253 Text *text = CTX_data_edit_text(C);
1254
1256
1258
1259 txt_order_cursors(text, false);
1260 txt_unindent(text);
1261
1262 text_update_edited(text);
1263
1266
1267 return OPERATOR_FINISHED;
1268}
1269
1271{
1272 /* Identifiers. */
1273 ot->name = "Unindent";
1274 ot->idname = "TEXT_OT_unindent";
1275 ot->description = "Unindent selected text";
1276
1277 /* API callbacks. */
1279 ot->poll = text_edit_poll;
1280
1281 /* Flags. */
1282 ot->flag = OPTYPE_UNDO;
1283}
1284
1286
1287/* -------------------------------------------------------------------- */
1290
1292{
1294 Text *text = CTX_data_edit_text(C);
1295 int a, curts;
1296 int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1;
1297
1299
1300 /* Double check tabs/spaces before splitting the line. */
1301 curts = txt_setcurr_tab_spaces(text, space);
1303 txt_split_curline(text);
1304
1305 for (a = 0; a < curts; a++) {
1306 if (text->flags & TXT_TABSTOSPACES) {
1307 txt_add_char(text, ' ');
1308 }
1309 else {
1310 txt_add_char(text, '\t');
1311 }
1312 }
1313
1314 if (text->curl) {
1315 if (text->curl->prev) {
1316 text_update_line_edited(text->curl->prev);
1317 }
1318 text_update_line_edited(text->curl);
1319 }
1320
1323
1324 return OPERATOR_FINISHED;
1325}
1326
1328{
1329 /* Identifiers. */
1330 ot->name = "Line Break";
1331 ot->idname = "TEXT_OT_line_break";
1332 ot->description = "Insert line break at cursor position";
1333
1334 /* API callbacks. */
1336 ot->poll = text_edit_poll;
1337
1338 /* Flags. */
1339 ot->flag = OPTYPE_UNDO;
1340}
1341
1343
1344/* -------------------------------------------------------------------- */
1347
1349{
1351 Text *text = CTX_data_edit_text(C);
1352 int type = RNA_enum_get(op->ptr, "type");
1353 const char *prefix = ED_text_format_comment_line_prefix(text);
1354
1356
1358
1359 if (txt_has_sel(text)) {
1360 txt_order_cursors(text, false);
1361 }
1362
1363 switch (type) {
1364 case 1:
1365 txt_comment(text, prefix);
1366 break;
1367 case -1:
1368 txt_uncomment(text, prefix);
1369 break;
1370 default:
1371 if (txt_uncomment(text, prefix) == false) {
1372 txt_comment(text, prefix);
1373 }
1374 break;
1375 }
1376
1377 text_update_edited(text);
1378
1381
1382 return OPERATOR_FINISHED;
1383}
1384
1386{
1387 static const EnumPropertyItem comment_items[] = {
1388 {0, "TOGGLE", 0, "Toggle Comments", nullptr},
1389 {1, "COMMENT", 0, "Comment", nullptr},
1390 {-1, "UNCOMMENT", 0, "Un-Comment", nullptr},
1391 {0, nullptr, 0, nullptr, nullptr},
1392 };
1393
1394 /* Identifiers. */
1395 ot->name = "Toggle Comments";
1396 ot->idname = "TEXT_OT_comment_toggle";
1397
1398 /* API callbacks. */
1399 ot->exec = text_comment_exec;
1400 ot->poll = text_edit_poll;
1401
1402 /* Flags. */
1403 ot->flag = OPTYPE_UNDO;
1404
1405 /* Properties. */
1406 PropertyRNA *prop;
1407 prop = RNA_def_enum(ot->srna, "type", comment_items, 0, "Type", "Add or remove comments");
1409}
1410
1412
1413/* -------------------------------------------------------------------- */
1416
1419 {TO_SPACES, "SPACES", 0, "To Spaces", nullptr},
1420 {TO_TABS, "TABS", 0, "To Tabs", nullptr},
1421 {0, nullptr, 0, nullptr, nullptr},
1422};
1423
1425{
1427 Text *text = CTX_data_edit_text(C);
1428 FlattenString fs;
1429 size_t a, j, max_len = 0;
1430 int type = RNA_enum_get(op->ptr, "type");
1431
1432 const int curc_column = text->curl ?
1434 text->curl->line, text->curl->len, text->curc, TXT_TABSIZE) :
1435 -1;
1436 const int selc_column = text->sell ?
1438 text->sell->line, text->sell->len, text->selc, TXT_TABSIZE) :
1439 -1;
1440
1441 /* First convert to all space, this make it a lot easier to convert to tabs
1442 * because there is no mixtures of ` ` && `\t`. */
1443 for (TextLine &tmp : text->lines) {
1444 char *new_line;
1445
1446 BLI_assert(tmp.line);
1447
1448 flatten_string(st, &fs, tmp.line);
1449 new_line = BLI_strdup(fs.buf);
1451
1452 MEM_delete(tmp.line);
1453 if (tmp.format) {
1454 MEM_delete(tmp.format);
1455 }
1456
1457 /* Put new_line in the tmp->line spot still need to try and set the curc correctly. */
1458 tmp.line = new_line;
1459 tmp.len = strlen(new_line);
1460 tmp.format = nullptr;
1461 max_len = std::max<size_t>(tmp.len, max_len);
1462 }
1463
1464 if (type == TO_TABS) {
1465 char *tmp_line = MEM_new_array_uninitialized<char>(max_len + 1, __func__);
1466
1467 for (TextLine &tmp : text->lines) {
1468 const char *text_check_line = tmp.line;
1469 const int text_check_line_len = tmp.len;
1470 char *tmp_line_cur = tmp_line;
1471 const size_t tab_len = st->tabnumber;
1472
1473 BLI_assert(text_check_line);
1474
1475 for (a = 0; a < text_check_line_len;) {
1476 /* A tab can only start at a position multiple of `tab_len`. */
1477 if (!(a % tab_len) && (text_check_line[a] == ' ')) {
1478 /* A + 0 we already know to be ` ` character. */
1479 for (j = 1;
1480 (j < tab_len) && (a + j < text_check_line_len) && (text_check_line[a + j] == ' ');
1481 j++)
1482 {
1483 /* Pass. */
1484 }
1485
1486 if (j == tab_len) {
1487 /* We found a set of spaces that can be replaced by a tab... */
1488 if ((tmp_line_cur == tmp_line) && a != 0) {
1489 /* Copy all *valid* string already *parsed*. */
1490 memcpy(tmp_line_cur, text_check_line, a);
1491 tmp_line_cur += a;
1492 }
1493 *tmp_line_cur = '\t';
1494 tmp_line_cur++;
1495 a += j;
1496 }
1497 else {
1498 if (tmp_line_cur != tmp_line) {
1499 memcpy(tmp_line_cur, &text_check_line[a], j);
1500 tmp_line_cur += j;
1501 }
1502 a += j;
1503 }
1504 }
1505 else {
1506 size_t len = BLI_str_utf8_size_safe(&text_check_line[a]);
1507 if (tmp_line_cur != tmp_line) {
1508 memcpy(tmp_line_cur, &text_check_line[a], len);
1509 tmp_line_cur += len;
1510 }
1511 a += len;
1512 }
1513 }
1514
1515 if (tmp_line_cur != tmp_line) {
1516 *tmp_line_cur = '\0';
1517
1518#ifndef NDEBUG
1519 BLI_assert(tmp_line_cur - tmp_line <= max_len);
1520
1521 flatten_string(st, &fs, tmp_line);
1522 BLI_assert(STREQ(fs.buf, tmp.line));
1524#endif
1525
1526 MEM_delete(tmp.line);
1527 if (tmp.format) {
1528 MEM_delete(tmp.format);
1529 }
1530
1531 /* Put new_line in the `tmp->line` spot. */
1532 tmp.len = strlen(tmp_line);
1533 tmp.line = BLI_strdupn(tmp_line, tmp.len);
1534 tmp.format = nullptr;
1535 }
1536 }
1537
1538 MEM_delete(tmp_line);
1539 }
1540
1541 if (curc_column != -1) {
1543 text->curl->line, text->curl->len, curc_column, TXT_TABSIZE);
1544 }
1545 if (selc_column != -1) {
1547 text->sell->line, text->sell->len, selc_column, TXT_TABSIZE);
1548 }
1549
1550 text_update_edited(text);
1554
1555 return OPERATOR_FINISHED;
1556}
1557
1559{
1560 /* Identifiers. */
1561 ot->name = "Convert Whitespace";
1562 ot->idname = "TEXT_OT_convert_whitespace";
1563 ot->description = "Convert whitespaces by type";
1564
1565 /* API callbacks. */
1567 ot->poll = text_edit_poll;
1568
1569 /* Flags. */
1570 ot->flag = OPTYPE_UNDO;
1571
1572 /* Properties. */
1573 RNA_def_enum(ot->srna,
1574 "type",
1576 TO_SPACES,
1577 "Type",
1578 "Type of whitespace to convert to");
1579}
1580
1582
1583/* -------------------------------------------------------------------- */
1586
1600
1602{
1603 /* Identifiers. */
1604 ot->name = "Select All";
1605 ot->idname = "TEXT_OT_select_all";
1606 ot->description = "Select all text";
1607
1608 /* API callbacks. */
1610 ot->poll = text_edit_poll;
1611}
1612
1614
1615/* -------------------------------------------------------------------- */
1618
1632
1634{
1635 /* Identifiers. */
1636 ot->name = "Select Line";
1637 ot->idname = "TEXT_OT_select_line";
1638 ot->description = "Select text by line";
1639
1640 /* API callbacks. */
1642 ot->poll = text_edit_poll;
1643}
1644
1646
1647/* -------------------------------------------------------------------- */
1650
1652{
1653 Text *text = CTX_data_edit_text(C);
1654
1656 text->curl->line, text->curl->len, text->selc, &text->curc, &text->selc);
1657
1660
1662
1663 return OPERATOR_FINISHED;
1664}
1665
1667{
1668 /* Identifiers. */
1669 ot->name = "Select Word";
1670 ot->idname = "TEXT_OT_select_word";
1671 ot->description = "Select word under cursor";
1672
1673 /* API callbacks. */
1675 ot->poll = text_edit_poll;
1676}
1677
1679
1680/* -------------------------------------------------------------------- */
1683
1685{
1686 Text *text = CTX_data_edit_text(C);
1687 const int direction = RNA_enum_get(op->ptr, "direction");
1688
1690
1691 txt_move_lines(text, direction);
1692
1695
1696 /* Run the script while editing, evil but useful. */
1697 if (CTX_wm_space_text(C)->live_edit) {
1698 text_run_script(C, nullptr);
1699 }
1700
1701 return OPERATOR_FINISHED;
1702}
1703
1705{
1706 static const EnumPropertyItem direction_items[] = {
1707 {TXT_MOVE_LINE_UP, "UP", 0, "Up", ""},
1708 {TXT_MOVE_LINE_DOWN, "DOWN", 0, "Down", ""},
1709 {0, nullptr, 0, nullptr, nullptr},
1710 };
1711
1712 /* Identifiers. */
1713 ot->name = "Move Lines";
1714 ot->idname = "TEXT_OT_move_lines";
1715 ot->description = "Move the currently selected line(s) up/down";
1716
1717 /* API callbacks. */
1718 ot->exec = move_lines_exec;
1719 ot->poll = text_edit_poll;
1720
1721 /* Flags. */
1722 ot->flag = OPTYPE_UNDO;
1723
1724 /* Properties. */
1725 RNA_def_enum(ot->srna, "direction", direction_items, 1, "Direction", "");
1726}
1727
1729
1730/* -------------------------------------------------------------------- */
1733
1735 {LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
1736 {LINE_END, "LINE_END", 0, "Line End", ""},
1737 {FILE_TOP, "FILE_TOP", 0, "File Top", ""},
1738 {FILE_BOTTOM, "FILE_BOTTOM", 0, "File Bottom", ""},
1739 {PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
1740 {NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
1741 {PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
1742 {NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
1743 {PREV_LINE, "PREVIOUS_LINE", 0, "Previous Line", ""},
1744 {NEXT_LINE, "NEXT_LINE", 0, "Next Line", ""},
1745 {PREV_PAGE, "PREVIOUS_PAGE", 0, "Previous Page", ""},
1746 {NEXT_PAGE, "NEXT_PAGE", 0, "Next Page", ""},
1747 {0, nullptr, 0, nullptr, nullptr},
1748};
1749
1754 const SpaceText *st, const ARegion *region, TextLine *linein, int rell, int relc)
1755{
1756 int i, j, start, end, max, curs, endj, selc;
1757 bool chop, loop, found;
1758 char ch;
1759
1760 max = space_text_wrap_width(st, region);
1761
1762 selc = start = endj = curs = found = false;
1763 end = max;
1764 chop = loop = true;
1765
1766 for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe(linein->line + j)) {
1767 int chars;
1768 const int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab. */
1769
1770 /* Mimic replacement of tabs. */
1771 ch = linein->line[j];
1772 if (ch == '\t') {
1773 chars = st->tabnumber - i % st->tabnumber;
1774 ch = ' ';
1775 }
1776 else {
1777 chars = 1;
1778 }
1779
1780 while (chars--) {
1781 if (rell == 0 && i - start <= relc && i + columns - start > relc) {
1782 /* Current position could be wrapped to next line. */
1783 /* This should be checked when end of current line would be reached. */
1784 selc = j;
1785 found = true;
1786 }
1787 else if (i - end <= relc && i + columns - end > relc) {
1788 curs = j;
1789 }
1790 if (i + columns - start > max) {
1791 end = std::min(end, i);
1792
1793 if (found) {
1794 /* Exact cursor position was found, check if it's
1795 * still on needed line (hasn't been wrapped). */
1796 if (selc > endj && !chop) {
1797 selc = endj;
1798 }
1799 loop = false;
1800 break;
1801 }
1802
1803 if (chop) {
1804 endj = j;
1805 }
1806
1807 start = end;
1808 end += max;
1809 chop = true;
1810 rell--;
1811
1812 if (rell == 0 && i + columns - start > relc) {
1813 selc = curs;
1814 loop = false;
1815 break;
1816 }
1817 }
1818 else if (ch == '\0') {
1819 if (!found) {
1820 selc = linein->len;
1821 }
1822 loop = false;
1823 break;
1824 }
1825 else if (ELEM(ch, ' ', '-')) {
1826 if (found) {
1827 loop = false;
1828 break;
1829 }
1830
1831 if (rell == 0 && i + columns - start > relc) {
1832 selc = curs;
1833 loop = false;
1834 break;
1835 }
1836 end = i + 1;
1837 endj = j;
1838 chop = false;
1839 }
1840 i += columns;
1841 }
1842 }
1843
1844 return selc;
1845}
1846
1848 const ARegion *region,
1849 int lines,
1850 TextLine **linep,
1851 int *charp,
1852 int *rell,
1853 int *relc)
1854{
1855 int offl, offc, visible_lines;
1856
1857 space_text_wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
1858 *relc = space_text_get_char_pos(st, (*linep)->line, *charp) + offc;
1859 *rell = lines;
1860
1861 /* Handle current line. */
1862 if (lines > 0) {
1863 visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
1864
1865 if (*rell - visible_lines + offl >= 0) {
1866 if (!(*linep)->next) {
1867 if (offl < visible_lines - 1) {
1868 *rell = visible_lines - 1;
1869 return 1;
1870 }
1871
1872 *charp = (*linep)->len;
1873 return 0;
1874 }
1875
1876 *rell -= visible_lines - offl;
1877 *linep = (*linep)->next;
1878 }
1879 else {
1880 *rell += offl;
1881 return 1;
1882 }
1883 }
1884 else {
1885 if (*rell + offl <= 0) {
1886 if (!(*linep)->prev) {
1887 if (offl) {
1888 *rell = 0;
1889 return 1;
1890 }
1891
1892 *charp = 0;
1893 return 0;
1894 }
1895
1896 *rell += offl;
1897 *linep = (*linep)->prev;
1898 }
1899 else {
1900 *rell += offl;
1901 return 1;
1902 }
1903 }
1904
1905 /* Skip lines and find destination line and offsets. */
1906 while (*linep) {
1907 visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
1908
1909 if (lines < 0) { /* Moving top. */
1910 if (*rell + visible_lines >= 0) {
1911 *rell += visible_lines;
1912 break;
1913 }
1914
1915 if (!(*linep)->prev) {
1916 *rell = 0;
1917 break;
1918 }
1919
1920 *rell += visible_lines;
1921 *linep = (*linep)->prev;
1922 }
1923 else { /* Moving bottom. */
1924 if (*rell - visible_lines < 0) {
1925 break;
1926 }
1927
1928 if (!(*linep)->next) {
1929 *rell = visible_lines - 1;
1930 break;
1931 }
1932
1933 *rell -= visible_lines;
1934 *linep = (*linep)->next;
1935 }
1936 }
1937
1938 return 1;
1939}
1940
1941static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
1942{
1943 Text *text = st->text;
1944 TextLine **linep;
1945 int *charp;
1946 int oldc, i, j, max, start, end, endj;
1947 bool chop, loop;
1948 char ch;
1949
1951
1952 if (sel) {
1953 linep = &text->sell;
1954 charp = &text->selc;
1955 }
1956 else {
1957 linep = &text->curl;
1958 charp = &text->curc;
1959 }
1960
1961 oldc = *charp;
1962
1963 max = space_text_wrap_width(st, region);
1964
1965 start = endj = 0;
1966 end = max;
1967 chop = loop = true;
1968 *charp = 0;
1969
1970 for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
1971 int chars;
1972 const int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab. */
1973
1974 /* Mimic replacement of tabs. */
1975 ch = (*linep)->line[j];
1976 if (ch == '\t') {
1977 chars = st->tabnumber - i % st->tabnumber;
1978 ch = ' ';
1979 }
1980 else {
1981 chars = 1;
1982 }
1983
1984 while (chars--) {
1985 if (i + columns - start > max) {
1986 end = std::min(end, i);
1987
1988 *charp = endj;
1989
1990 if (j >= oldc) {
1991 if (ch == '\0') {
1993 (*linep)->line, (*linep)->len, start, TXT_TABSIZE);
1994 }
1995 loop = false;
1996 break;
1997 }
1998
1999 if (chop) {
2000 endj = j;
2001 }
2002
2003 start = end;
2004 end += max;
2005 chop = true;
2006 }
2007 else if (ELEM(ch, ' ', '-', '\0')) {
2008 if (j >= oldc) {
2010 (*linep)->line, (*linep)->len, start, TXT_TABSIZE);
2011 loop = false;
2012 break;
2013 }
2014
2015 end = i + 1;
2016 endj = j + 1;
2017 chop = false;
2018 }
2019 i += columns;
2020 }
2021 }
2022
2023 if (!sel) {
2024 txt_pop_sel(text);
2025 }
2026}
2027
2028static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
2029{
2030 Text *text = st->text;
2031 TextLine **linep;
2032 int *charp;
2033 int oldc, i, j, max, start, end, endj;
2034 bool chop, loop;
2035 char ch;
2036
2038
2039 if (sel) {
2040 linep = &text->sell;
2041 charp = &text->selc;
2042 }
2043 else {
2044 linep = &text->curl;
2045 charp = &text->curc;
2046 }
2047
2048 oldc = *charp;
2049
2050 max = space_text_wrap_width(st, region);
2051
2052 start = endj = 0;
2053 end = max;
2054 chop = loop = true;
2055 *charp = 0;
2056
2057 for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
2058 int chars;
2059 const int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab. */
2060
2061 /* Mimic replacement of tabs. */
2062 ch = (*linep)->line[j];
2063 if (ch == '\t') {
2064 chars = st->tabnumber - i % st->tabnumber;
2065 ch = ' ';
2066 }
2067 else {
2068 chars = 1;
2069 }
2070
2071 while (chars--) {
2072 if (i + columns - start > max) {
2073 end = std::min(end, i);
2074
2075 if (chop) {
2076 endj = BLI_str_find_prev_char_utf8((*linep)->line + j, (*linep)->line) - (*linep)->line;
2077 }
2078
2079 if (endj >= oldc) {
2080 if (ch == '\0') {
2081 *charp = (*linep)->len;
2082 }
2083 else {
2084 *charp = endj;
2085 }
2086 loop = false;
2087 break;
2088 }
2089
2090 start = end;
2091 end += max;
2092 chop = true;
2093 }
2094 else if (ch == '\0') {
2095 *charp = (*linep)->len;
2096 loop = false;
2097 break;
2098 }
2099 else if (ELEM(ch, ' ', '-')) {
2100 end = i + 1;
2101 endj = j;
2102 chop = false;
2103 }
2104 i += columns;
2105 }
2106 }
2107
2108 if (!sel) {
2109 txt_pop_sel(text);
2110 }
2111}
2112
2113static void txt_wrap_move_up(SpaceText *st, ARegion *region, const bool sel)
2114{
2115 Text *text = st->text;
2116 TextLine **linep;
2117 int *charp;
2118 int offl, offc, col;
2119
2121
2122 if (sel) {
2123 linep = &text->sell;
2124 charp = &text->selc;
2125 }
2126 else {
2127 linep = &text->curl;
2128 charp = &text->curc;
2129 }
2130
2131 space_text_wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
2132 col = space_text_get_char_pos(st, (*linep)->line, *charp) + offc;
2133 if (offl) {
2134 *charp = space_text_get_cursor_rel(st, region, *linep, offl - 1, col);
2135 }
2136 else {
2137 if ((*linep)->prev) {
2138 int visible_lines;
2139
2140 *linep = (*linep)->prev;
2141 visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
2142 *charp = space_text_get_cursor_rel(st, region, *linep, visible_lines - 1, col);
2143 }
2144 else {
2145 *charp = 0;
2146 }
2147 }
2148
2149 if (!sel) {
2150 txt_pop_sel(text);
2151 }
2152}
2153
2154static void txt_wrap_move_down(SpaceText *st, ARegion *region, const bool sel)
2155{
2156 Text *text = st->text;
2157 TextLine **linep;
2158 int *charp;
2159 int offl, offc, col, visible_lines;
2160
2162
2163 if (sel) {
2164 linep = &text->sell;
2165 charp = &text->selc;
2166 }
2167 else {
2168 linep = &text->curl;
2169 charp = &text->curc;
2170 }
2171
2172 space_text_wrap_offset_in_line(st, region, *linep, *charp, &offl, &offc);
2173 col = space_text_get_char_pos(st, (*linep)->line, *charp) + offc;
2174 visible_lines = space_text_get_visible_lines(st, region, (*linep)->line);
2175 if (offl < visible_lines - 1) {
2176 *charp = space_text_get_cursor_rel(st, region, *linep, offl + 1, col);
2177 }
2178 else {
2179 if ((*linep)->next) {
2180 *linep = (*linep)->next;
2181 *charp = space_text_get_cursor_rel(st, region, *linep, 0, col);
2182 }
2183 else {
2184 *charp = (*linep)->len;
2185 }
2186 }
2187
2188 if (!sel) {
2189 txt_pop_sel(text);
2190 }
2191}
2192
2201 const SpaceText *st, const ARegion *region, Text *text, int lines, const bool sel)
2202{
2203 TextLine **linep;
2204 int *charp;
2205
2206 if (sel) {
2207 linep = &text->sell;
2208 charp = &text->selc;
2209 }
2210 else {
2211 linep = &text->curl;
2212 charp = &text->curc;
2213 }
2214
2215 if (st && region && st->wordwrap) {
2216 int rell, relc;
2217
2218 /* Find line and offsets inside it needed to set cursor position. */
2219 if (cursor_skip_find_line(st, region, lines, linep, charp, &rell, &relc)) {
2220 *charp = space_text_get_cursor_rel(st, region, *linep, rell, relc);
2221 }
2222 }
2223 else {
2224 while (lines > 0 && (*linep)->next) {
2225 *linep = (*linep)->next;
2226 lines--;
2227 }
2228 while (lines < 0 && (*linep)->prev) {
2229 *linep = (*linep)->prev;
2230 lines++;
2231 }
2232 }
2233
2234 *charp = std::min(*charp, (*linep)->len);
2235
2236 if (!sel) {
2237 txt_pop_sel(text);
2238 }
2239}
2240
2242{
2244 Text *text = CTX_data_edit_text(C);
2245 ARegion *region = CTX_wm_region(C);
2246
2247 /* Ensure we have the right region, it's optional. */
2248 if (region && region->regiontype != RGN_TYPE_WINDOW) {
2249 region = nullptr;
2250 }
2251
2252 switch (type) {
2253 case LINE_BEGIN:
2254 if (!select) {
2255 txt_sel_clear(text);
2256 }
2257 if (st && st->wordwrap && region) {
2258 txt_wrap_move_bol(st, region, select);
2259 }
2260 else {
2261 txt_move_bol(text, select);
2262 }
2263 break;
2264
2265 case LINE_END:
2266 if (!select) {
2267 txt_sel_clear(text);
2268 }
2269 if (st && st->wordwrap && region) {
2270 txt_wrap_move_eol(st, region, select);
2271 }
2272 else {
2273 txt_move_eol(text, select);
2274 }
2275 break;
2276
2277 case FILE_TOP:
2278 txt_move_bof(text, select);
2279 break;
2280
2281 case FILE_BOTTOM:
2282 txt_move_eof(text, select);
2283 break;
2284
2285 case PREV_WORD:
2286 if (txt_cursor_is_line_start(text)) {
2287 txt_move_left(text, select);
2288 }
2289 txt_jump_left(text, select, true);
2290 break;
2291
2292 case NEXT_WORD:
2293 if (txt_cursor_is_line_end(text)) {
2294 txt_move_right(text, select);
2295 }
2296 txt_jump_right(text, select, true);
2297 break;
2298
2299 case PREV_CHAR:
2300 if (txt_has_sel(text) && !select) {
2301 txt_order_cursors(text, false);
2302 txt_pop_sel(text);
2303 }
2304 else {
2305 txt_move_left(text, select);
2306 }
2307 break;
2308
2309 case NEXT_CHAR:
2310 if (txt_has_sel(text) && !select) {
2311 txt_order_cursors(text, true);
2312 txt_pop_sel(text);
2313 }
2314 else {
2315 txt_move_right(text, select);
2316 }
2317 break;
2318
2319 case PREV_LINE:
2320 if (st && st->wordwrap && region) {
2321 txt_wrap_move_up(st, region, select);
2322 }
2323 else {
2324 txt_move_up(text, select);
2325 }
2326 break;
2327
2328 case NEXT_LINE:
2329 if (st && st->wordwrap && region) {
2330 txt_wrap_move_down(st, region, select);
2331 }
2332 else {
2333 txt_move_down(text, select);
2334 }
2335 break;
2336
2337 case PREV_PAGE:
2338 if (st) {
2339 space_text_cursor_skip(st, region, st->text, -st->runtime->viewlines, select);
2340 }
2341 else {
2342 space_text_cursor_skip(nullptr, nullptr, text, -10, select);
2343 }
2344 break;
2345
2346 case NEXT_PAGE:
2347 if (st) {
2348 space_text_cursor_skip(st, region, st->text, st->runtime->viewlines, select);
2349 }
2350 else {
2351 space_text_cursor_skip(nullptr, nullptr, text, 10, select);
2352 }
2353 break;
2354 }
2355
2357 if (select) {
2359 }
2360
2362
2363 return OPERATOR_FINISHED;
2364}
2365
2367{
2368 int type = RNA_enum_get(op->ptr, "type");
2369
2370 return text_move_cursor(C, type, false);
2371}
2372
2374{
2375 /* Identifiers. */
2376 ot->name = "Move Cursor";
2377 ot->idname = "TEXT_OT_move";
2378 ot->description = "Move cursor to position type";
2379
2380 /* API callbacks. */
2381 ot->exec = text_move_exec;
2382 ot->poll = text_edit_poll;
2383
2384 /* Properties. */
2385 RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to");
2386}
2387
2389
2390/* -------------------------------------------------------------------- */
2393
2395{
2396 int type = RNA_enum_get(op->ptr, "type");
2397
2398 return text_move_cursor(C, type, true);
2399}
2400
2402{
2403 /* Identifiers. */
2404 ot->name = "Move Select";
2405 ot->idname = "TEXT_OT_move_select";
2406 ot->description = "Move the cursor while selecting";
2407
2408 /* API callbacks. */
2411
2412 /* Properties. */
2413 RNA_def_enum(ot->srna,
2414 "type",
2416 LINE_BEGIN,
2417 "Type",
2418 "Where to move cursor to, to make a selection");
2419}
2420
2422
2423/* -------------------------------------------------------------------- */
2426
2428{
2429 Text *text = CTX_data_edit_text(C);
2430 int line = RNA_int_get(op->ptr, "line");
2431 short nlines = txt_get_span(text->lines.first(), text->lines.last()) + 1;
2432
2433 if (line < 1) {
2434 txt_move_toline(text, 1, false);
2435 }
2436 else if (line > nlines) {
2437 txt_move_toline(text, nlines - 1, false);
2438 }
2439 else {
2440 txt_move_toline(text, line - 1, false);
2441 }
2442
2445
2446 return OPERATOR_FINISHED;
2447}
2448
2450{
2451 return WM_operator_props_dialog_popup(C, op, 200, IFACE_("Jump to Line Number"));
2452}
2453
2455{
2456 /* Identifiers. */
2457 ot->name = "Jump";
2458 ot->idname = "TEXT_OT_jump";
2459 ot->description = "Jump cursor to line";
2460
2461 /* API callbacks. */
2463 ot->exec = text_jump_exec;
2464 ot->poll = text_edit_poll;
2465
2466 /* Properties. */
2467 ot->prop = RNA_def_int(
2468 ot->srna, "line", 1, 1, INT_MAX, "Line", "Line number to jump to", 1, 10000);
2470}
2471
2473
2474/* -------------------------------------------------------------------- */
2477
2479 {DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
2480 {DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
2481 {DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
2482 {DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
2483 {0, nullptr, 0, nullptr, nullptr},
2484};
2485
2487{
2488#ifdef WITH_INPUT_IME
2489 if (const std::optional<wmOperatorStatus> status = WM_operator_IME_edit_maybe(C)) {
2490 return *status;
2491 }
2492#endif
2493
2495 Text *text = CTX_data_edit_text(C);
2496 int type = RNA_enum_get(op->ptr, "type");
2497
2499
2500 /* Behavior could be changed here,
2501 * but for now just don't jump words when we have a selection. */
2502 if (txt_has_sel(text)) {
2503 if (type == DEL_PREV_WORD) {
2504 type = DEL_PREV_CHAR;
2505 }
2506 else if (type == DEL_NEXT_WORD) {
2507 type = DEL_NEXT_CHAR;
2508 }
2509 }
2510
2512
2513 if (type == DEL_PREV_WORD) {
2514 if (txt_cursor_is_line_start(text)) {
2515 txt_backspace_char(text);
2516 }
2517 txt_backspace_word(text);
2518 }
2519 else if (type == DEL_PREV_CHAR) {
2520
2521 if (text->flags & TXT_TABSTOSPACES) {
2522 if (!txt_has_sel(text) && !txt_cursor_is_line_start(text)) {
2523 int tabsize = 0;
2524 tabsize = txt_calc_tab_left(text->curl, text->curc);
2525 if (tabsize) {
2526 text->sell = text->curl;
2527 text->selc = text->curc - tabsize;
2528 txt_order_cursors(text, false);
2529 }
2530 }
2531 }
2532 if (U.text_flag & USER_TEXT_EDIT_AUTO_CLOSE) {
2533 const char *curr = text->curl->line + text->curc;
2534 if (*curr != '\0') {
2535 const char *prev = BLI_str_find_prev_char_utf8(curr, text->curl->line);
2536 if ((curr != prev) && /* When back-spacing from the start of the line. */
2537 (*curr == text_closing_character_pair_get(*prev)))
2538 {
2539 txt_move_right(text, false);
2540 txt_backspace_char(text);
2541 }
2542 }
2543 }
2544 txt_backspace_char(text);
2545 }
2546 else if (type == DEL_NEXT_WORD) {
2547 if (txt_cursor_is_line_end(text)) {
2548 txt_delete_char(text);
2549 }
2550 txt_delete_word(text);
2551 }
2552 else if (type == DEL_NEXT_CHAR) {
2553
2554 if (text->flags & TXT_TABSTOSPACES) {
2555 if (!txt_has_sel(text) && !txt_cursor_is_line_end(text)) {
2556 int tabsize = 0;
2557 tabsize = txt_calc_tab_right(text->curl, text->curc);
2558 if (tabsize) {
2559 text->sell = text->curl;
2560 text->selc = text->curc + tabsize;
2561 txt_order_cursors(text, true);
2562 }
2563 }
2564 }
2565
2566 txt_delete_char(text);
2567 }
2568
2569 text_update_line_edited(text->curl);
2570
2573
2574 /* Run the script while editing, evil but useful. */
2575 if (st->live_edit) {
2576 text_run_script(C, nullptr);
2577 }
2578
2579 return OPERATOR_FINISHED;
2580}
2581
2583{
2584 /* Identifiers. */
2585 ot->name = "Delete";
2586 ot->idname = "TEXT_OT_delete";
2587 ot->description = "Delete text by cursor position";
2588
2589 /* API callbacks. */
2590 ot->exec = text_delete_exec;
2591 ot->poll = text_edit_poll;
2592
2593 /* Flags. */
2594 ot->flag = OPTYPE_UNDO;
2595
2596 /* Properties. */
2597 PropertyRNA *prop;
2598 prop = RNA_def_enum(ot->srna,
2599 "type",
2602 "Type",
2603 "Which part of the text to delete");
2605}
2606
2608
2609/* -------------------------------------------------------------------- */
2612
2614{
2616
2617 st->overwrite = !st->overwrite;
2618
2620
2621 return OPERATOR_FINISHED;
2622}
2623
2625{
2626 /* Identifiers. */
2627 ot->name = "Toggle Overwrite";
2628 ot->idname = "TEXT_OT_overwrite_toggle";
2629 ot->description = "Toggle overwrite while typing";
2630
2631 /* API callbacks. */
2634}
2635
2637
2638/* -------------------------------------------------------------------- */
2641
2642static void space_text_screen_clamp(SpaceText *st, const ARegion *region)
2643{
2644 if (st->top <= 0) {
2645 st->top = 0;
2646 }
2647 else {
2648 int last;
2649 last = space_text_get_total_lines(st, region);
2650 last = last - (st->runtime->viewlines / 2);
2651 if (last > 0 && st->top > last) {
2652 st->top = last;
2653 }
2654 }
2655}
2656
2657/* Moves the view vertically by the specified number of lines. */
2658static void space_text_screen_skip(SpaceText *st, ARegion *region, int lines)
2659{
2660 st->top += lines;
2661 space_text_screen_clamp(st, region);
2662}
2663
2671
2675
2678
2680
2681 /* Store the state of the display, cache some constant vars. */
2682 struct {
2683 int ofs_init[2];
2684 int ofs_max[2];
2685 int size_px[2];
2689};
2690
2692{
2693 tsc->state.ofs_init[0] = st->left;
2694 tsc->state.ofs_init[1] = st->top;
2695
2696 tsc->state.ofs_max[0] = INT_MAX;
2697 tsc->state.ofs_max[1] = max_ii(
2698 0, space_text_get_total_lines(st, region) - (st->runtime->viewlines / 2));
2699
2700 tsc->state.size_px[0] = st->runtime->char_width_px;
2701 tsc->state.size_px[1] = TXT_LINE_HEIGHT(st);
2702}
2703
2705{
2706 /* It should be possible to still scroll linked texts to read them,
2707 * even if they can't be edited... */
2708 return CTX_data_edit_text(C) != nullptr;
2709}
2710
2712{
2714 ARegion *region = CTX_wm_region(C);
2715
2716 int lines = RNA_int_get(op->ptr, "lines");
2717
2718 if (lines == 0) {
2719 return OPERATOR_CANCELLED;
2720 }
2721
2722 space_text_screen_skip(st, region, lines * 3);
2723
2725
2726 return OPERATOR_FINISHED;
2727}
2728
2729static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
2730{
2732 TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
2733 const int mval[2] = {event->xy[0], event->xy[1]};
2734
2736
2737 /* Compute mouse move distance. */
2738 if (tsc->is_first) {
2739 copy_v2_v2_int(tsc->mval_prev, mval);
2740 tsc->is_first = false;
2741 }
2742
2743 if (event->type != MOUSEPAN) {
2744 sub_v2_v2v2_int(tsc->mval_delta, mval, tsc->mval_prev);
2745 }
2746
2747 /* Accumulate scroll, in float values for events that give less than one
2748 * line offset but taken together should still scroll. */
2749 if (!tsc->is_scrollbar) {
2750 tsc->ofs_delta_px[0] -= tsc->mval_delta[0];
2751 tsc->ofs_delta_px[1] += tsc->mval_delta[1];
2752 }
2753 else {
2754 tsc->ofs_delta_px[1] -= (tsc->mval_delta[1] * st->runtime->scroll_px_per_line) *
2755 tsc->state.size_px[1];
2756 }
2757
2758 for (int i = 0; i < 2; i += 1) {
2759 int lines_from_pixels = tsc->ofs_delta_px[i] / tsc->state.size_px[i];
2760 tsc->ofs_delta[i] += lines_from_pixels;
2761 tsc->ofs_delta_px[i] -= lines_from_pixels * tsc->state.size_px[i];
2762 }
2763
2764 /* The final values need to be calculated from the inputs,
2765 * so clamping and ensuring an unsigned pixel offset doesn't conflict with
2766 * updating the cursor mval_delta. */
2767 int scroll_ofs_new[2] = {
2768 tsc->state.ofs_init[0] + tsc->ofs_delta[0],
2769 tsc->state.ofs_init[1] + tsc->ofs_delta[1],
2770 };
2771 int scroll_ofs_px_new[2] = {
2772 tsc->ofs_delta_px[0],
2773 tsc->ofs_delta_px[1],
2774 };
2775
2776 for (int i = 0; i < 2; i += 1) {
2777 /* Ensure always unsigned (adjusting line/column accordingly). */
2778 while (scroll_ofs_px_new[i] < 0) {
2779 scroll_ofs_px_new[i] += tsc->state.size_px[i];
2780 scroll_ofs_new[i] -= 1;
2781 }
2782
2783 /* Clamp within usable region. */
2784 if (scroll_ofs_new[i] < 0) {
2785 scroll_ofs_new[i] = 0;
2786 scroll_ofs_px_new[i] = 0;
2787 }
2788 else if (scroll_ofs_new[i] >= tsc->state.ofs_max[i]) {
2789 scroll_ofs_new[i] = tsc->state.ofs_max[i];
2790 scroll_ofs_px_new[i] = 0;
2791 }
2792 }
2793
2794 /* Override for word-wrap. */
2795 if (st->wordwrap) {
2796 scroll_ofs_new[0] = 0;
2797 scroll_ofs_px_new[0] = 0;
2798 }
2799
2800 /* Apply to the screen. */
2801 if (scroll_ofs_new[0] != st->left || scroll_ofs_new[1] != st->top ||
2802 /* Horizontal sub-pixel offset currently isn't used. */
2803 /* `scroll_ofs_px_new[0] != st->scroll_ofs_px[0] ||`. */
2804 scroll_ofs_px_new[1] != st->runtime->scroll_ofs_px[1])
2805 {
2806
2807 st->left = scroll_ofs_new[0];
2808 st->top = scroll_ofs_new[1];
2809 st->runtime->scroll_ofs_px[0] = scroll_ofs_px_new[0];
2810 st->runtime->scroll_ofs_px[1] = scroll_ofs_px_new[1];
2812 }
2813
2814 tsc->mval_prev[0] = mval[0];
2815 tsc->mval_prev[1] = mval[1];
2816}
2817
2819{
2821 TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
2822
2823 st->flags &= ~ST_SCROLL_SELECT;
2824
2825 if (st->runtime->scroll_ofs_px[1] > tsc->state.size_px[1] / 2) {
2826 st->top += 1;
2827 }
2828
2829 st->runtime->scroll_ofs_px[0] = 0;
2830 st->runtime->scroll_ofs_px[1] = 0;
2832
2833 MEM_delete(tsc);
2834 op->customdata = nullptr;
2835}
2836
2838{
2839 TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
2841 ARegion *region = CTX_wm_region(C);
2842
2843 switch (event->type) {
2844 case MOUSEMOVE:
2845 if (tsc->zone == SCROLLHANDLE_BAR) {
2846 text_scroll_apply(C, op, event);
2847 }
2848 break;
2849 case LEFTMOUSE:
2850 case RIGHTMOUSE:
2851 case MIDDLEMOUSE:
2852 if (event->val == KM_RELEASE) {
2855 region,
2856 st->runtime->viewlines *
2857 (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1));
2858
2860 }
2861 scroll_exit(C, op);
2862 return OPERATOR_FINISHED;
2863 }
2864 default: {
2865 break;
2866 }
2867 }
2868
2870}
2871
2873{
2874 scroll_exit(C, op);
2875}
2876
2878{
2880 ARegion *region = CTX_wm_region(C);
2881
2882 TextScroll *tsc;
2883
2884 if (RNA_struct_property_is_set(op->ptr, "lines")) {
2885 return text_scroll_exec(C, op);
2886 }
2887
2888 tsc = MEM_new_zeroed<TextScroll>("TextScroll");
2889 tsc->is_first = true;
2890 tsc->zone = SCROLLHANDLE_BAR;
2891
2892 text_scroll_state_init(tsc, st, region);
2893
2894 op->customdata = tsc;
2895
2896 st->flags |= ST_SCROLL_SELECT;
2897
2898 if (event->type == MOUSEPAN) {
2900
2901 copy_v2_v2_int(tsc->mval_prev, event->xy);
2902 /* Sensitivity of scroll set to 4pix per line/char. */
2903 tsc->mval_delta[0] = (event->xy[0] - event->prev_xy[0]) * st->runtime->char_width_px / 4;
2904 tsc->mval_delta[1] = (event->xy[1] - event->prev_xy[1]) * st->runtime->line_height_px / 4;
2905 tsc->is_first = false;
2906 tsc->is_scrollbar = false;
2907 text_scroll_apply(C, op, event);
2908 scroll_exit(C, op);
2909 return OPERATOR_FINISHED;
2910 }
2911
2913
2915}
2916
2918{
2919 /* Identifiers. */
2920 ot->name = "Scroll";
2921 /* Don't really see the difference between this and scroll_bar.
2922 * Both do basically the same thing (aside from key-maps). */
2923 ot->idname = "TEXT_OT_scroll";
2924
2925 /* API callbacks. */
2926 ot->exec = text_scroll_exec;
2930 ot->poll = text_scroll_poll;
2931
2932 /* Flags. */
2934
2935 /* Properties. */
2936 PropertyRNA *prop;
2937 prop = RNA_def_int(
2938 ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll", -100, 100);
2940}
2941
2943
2944/* -------------------------------------------------------------------- */
2947
2949{
2950 /* Same as text_region_edit_poll except it works on libdata too. */
2952 Text *text = CTX_data_edit_text(C);
2953 ARegion *region = CTX_wm_region(C);
2954
2955 if (!st || !text) {
2956 return false;
2957 }
2958
2959 if (!region || region->regiontype != RGN_TYPE_WINDOW) {
2960 return false;
2961 }
2962
2963 return true;
2964}
2965
2967{
2969 ARegion *region = CTX_wm_region(C);
2970 TextScroll *tsc;
2971 const int *mval = event->mval;
2973
2974 if (RNA_struct_property_is_set(op->ptr, "lines")) {
2975 return text_scroll_exec(C, op);
2976 }
2977
2978 /* Verify we are in the right zone. */
2979 if (mval[0] > st->runtime->scroll_region_handle.xmin &&
2980 mval[0] < st->runtime->scroll_region_handle.xmax)
2981 {
2982 if (mval[1] >= st->runtime->scroll_region_handle.ymin &&
2983 mval[1] <= st->runtime->scroll_region_handle.ymax)
2984 {
2985 /* Mouse inside scroll handle. */
2986 zone = SCROLLHANDLE_BAR;
2987 }
2988 else if (mval[1] > TXT_SCROLL_SPACE && mval[1] < region->winy - TXT_SCROLL_SPACE) {
2989 if (mval[1] < st->runtime->scroll_region_handle.ymin) {
2991 }
2992 else {
2994 }
2995 }
2996 }
2997
2998 if (zone == SCROLLHANDLE_INVALID_OUTSIDE) {
2999 /* We are outside slider - nothing to do. */
3000 return OPERATOR_PASS_THROUGH;
3001 }
3002
3003 tsc = MEM_new_zeroed<TextScroll>("TextScroll");
3004 tsc->is_first = true;
3005 tsc->is_scrollbar = true;
3006 tsc->zone = zone;
3007 op->customdata = tsc;
3008 st->flags |= ST_SCROLL_SELECT;
3009
3010 text_scroll_state_init(tsc, st, region);
3011
3012 /* Jump scroll, works in `v2d` but needs to be added here too unfortunately. */
3013 if (event->type == MIDDLEMOUSE) {
3016
3017 tsc->is_first = false;
3018 tsc->zone = SCROLLHANDLE_BAR;
3019 text_scroll_apply(C, op, event);
3020 }
3021
3023
3025}
3026
3028{
3029 /* Identifiers. */
3030 ot->name = "Scrollbar";
3031 /* Don't really see the difference between this and scroll.
3032 * Both do basically the same thing (aside from key-maps). */
3033 ot->idname = "TEXT_OT_scroll_bar";
3034
3035 /* API callbacks. */
3040
3041 /* Flags. */
3043
3044 /* Properties. */
3045 PropertyRNA *prop;
3046 prop = RNA_def_int(
3047 ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll", -100, 100);
3049}
3050
3052
3053/* -------------------------------------------------------------------- */
3056
3059 short mval_prev[2];
3060 wmTimer *timer; /* Needed for scrolling when mouse at region bounds. */
3061};
3062
3063static int flatten_width(SpaceText *st, const char *str)
3064{
3065 int total = 0;
3066
3067 for (int i = 0; str[i]; i += BLI_str_utf8_size_safe(str + i)) {
3068 const int columns = (str[i] == '\t') ? (st->tabnumber - total % st->tabnumber) :
3070 total += columns;
3071 }
3072
3073 return total;
3074}
3075
3076static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
3077{
3078 int i = 0, j = 0;
3079
3080 while (*(str + j)) {
3081 const int col = (str[j] == '\t') ? (st->tabnumber - i % st->tabnumber) :
3083 if (i + col > index) {
3084 break;
3085 }
3086
3087 i += col;
3088 j += BLI_str_utf8_size_safe(str + j);
3089 }
3090
3091 return j;
3092}
3093
3095 const ARegion *region,
3096 int *y)
3097{
3098 TextLine *linep = st->text->lines.first();
3099 int i, lines;
3100
3101 if (*y < -st->top) {
3102 return nullptr; /* We are beyond the first line... */
3103 }
3104
3105 for (i = -st->top; i <= *y && linep; linep = linep->next, i += lines) {
3106 lines = space_text_get_visible_lines(st, region, linep->line);
3107
3108 if (i + lines > *y) {
3109 /* We found the line matching given vertical *coordinate*,
3110 * now set y relative to this line's start. */
3111 *y -= i;
3112 break;
3113 }
3114 }
3115 return linep;
3116}
3117
3119 const SpaceText *st, const ARegion *region, int x, int y, const bool sel)
3120{
3121 Text *text = st->text;
3122 int max = space_text_wrap_width(st, region); /* Column. */
3123 int charp = -1; /* Mem. */
3124 bool found = false; /* Flags. */
3125
3126 /* Point to line matching given y position, if any. */
3127 TextLine *linep = space_text_get_line_pos_wrapped(st, region, &y);
3128
3129 if (linep) {
3130 int i = 0, start = 0, end = max; /* Column. */
3131 int j, curs = 0, endj = 0; /* Mem. */
3132 bool chop = true; /* Flags. */
3133 char ch;
3134
3135 for (j = 0; !found && ((ch = linep->line[j]) != '\0');
3136 j += BLI_str_utf8_size_safe(linep->line + j))
3137 {
3138 int chars;
3139 const int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab. */
3140
3141 /* Mimic replacement of tabs. */
3142 if (ch == '\t') {
3143 chars = st->tabnumber - i % st->tabnumber;
3144 ch = ' ';
3145 }
3146 else {
3147 chars = 1;
3148 }
3149
3150 while (chars--) {
3151 /* Gone too far, go back to last wrap point. */
3152 if (y < 0) {
3153 charp = endj;
3154 y = 0;
3155 found = true;
3156 break;
3157 /* Exactly at the cursor. */
3158 }
3159 if (y == 0 && i - start <= x && i + columns - start > x) {
3160 /* Current position could be wrapped to next line. */
3161 /* This should be checked when end of current line would be reached. */
3162 charp = curs = j;
3163 found = true;
3164 /* Prepare curs for next wrap. */
3165 }
3166 else if (i - end <= x && i + columns - end > x) {
3167 curs = j;
3168 }
3169 if (i + columns - start > max) {
3170 end = std::min(end, i);
3171
3172 if (found) {
3173 /* Exact cursor position was found, check if it's still on needed line
3174 * (hasn't been wrapped). */
3175 if (charp > endj && !chop && ch != '\0') {
3176 charp = endj;
3177 }
3178 break;
3179 }
3180
3181 if (chop) {
3182 endj = j;
3183 }
3184 start = end;
3185 end += max;
3186
3187 if (j < linep->len) {
3188 y--;
3189 }
3190
3191 chop = true;
3192 if (y == 0 && i + columns - start > x) {
3193 charp = curs;
3194 found = true;
3195 break;
3196 }
3197 }
3198 else if (ELEM(ch, ' ', '-', '\0')) {
3199 if (found) {
3200 break;
3201 }
3202
3203 if (y == 0 && i + columns - start > x) {
3204 charp = curs;
3205 found = true;
3206 break;
3207 }
3208 end = i + 1;
3209 endj = j;
3210 chop = false;
3211 }
3212 i += columns;
3213 }
3214 }
3215
3216 BLI_assert(y == 0);
3217
3218 if (!found) {
3219 /* On correct line but didn't meet cursor, must be at end. */
3220 charp = linep->len;
3221 }
3222 }
3223 else if (y < 0) { /* Before start of text. */
3224 linep = st->text->lines.first();
3225 charp = 0;
3226 }
3227 else { /* Beyond end of text. */
3228 linep = st->text->lines.last();
3229 charp = linep->len;
3230 }
3231
3232 BLI_assert(linep && charp != -1);
3233
3234 if (sel) {
3235 text->sell = linep;
3236 text->selc = charp;
3237 }
3238 else {
3239 text->curl = linep;
3240 text->curc = charp;
3241 }
3242}
3243
3245 SpaceText *st, const ARegion *region, int x, int y, const bool sel)
3246{
3247 Text *text = st->text;
3249 y = (region->winy - 2 - y) / TXT_LINE_HEIGHT(st);
3250
3251 x -= TXT_BODY_LEFT(st);
3252 x = std::max(x, 0);
3253 x = space_text_pixel_x_to_column(st, x) + st->left;
3254
3255 if (st->wordwrap) {
3256 space_text_cursor_set_to_pos_wrapped(st, region, x, y, sel);
3257 }
3258 else {
3259 TextLine **linep;
3260 int *charp;
3261 int w;
3262
3263 if (sel) {
3264 linep = &text->sell;
3265 charp = &text->selc;
3266 }
3267 else {
3268 linep = &text->curl;
3269 charp = &text->curc;
3270 }
3271
3272 y -= txt_get_span(text->lines.first(), *linep) - st->top;
3273
3274 if (y > 0) {
3275 while (y-- != 0) {
3276 if ((*linep)->next) {
3277 *linep = (*linep)->next;
3278 }
3279 }
3280 }
3281 else if (y < 0) {
3282 while (y++ != 0) {
3283 if ((*linep)->prev) {
3284 *linep = (*linep)->prev;
3285 }
3286 }
3287 }
3288
3289 w = flatten_width(st, (*linep)->line);
3290 if (x < w) {
3291 *charp = flatten_column_to_offset(st, (*linep)->line, x);
3292 }
3293 else {
3294 *charp = (*linep)->len;
3295 }
3296 }
3297 if (!sel) {
3298 txt_pop_sel(text);
3299 }
3300}
3301
3303{
3304 if (ssel->timer == nullptr) {
3306 wmWindow *win = CTX_wm_window(C);
3307
3308 ssel->timer = WM_event_timer_add(wm, win, TIMER, 0.02f);
3309 }
3310}
3311
3313{
3314 if (ssel->timer) {
3316 wmWindow *win = CTX_wm_window(C);
3317
3318 WM_event_timer_remove(wm, win, ssel->timer);
3319 }
3320 ssel->timer = nullptr;
3321}
3322
3323static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event)
3324{
3326 ARegion *region = CTX_wm_region(C);
3327 SetSelection *ssel = static_cast<SetSelection *>(op->customdata);
3328
3329 if (event->mval[1] < 0 || event->mval[1] > region->winy) {
3331
3332 if (event->type == TIMER) {
3333 text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], true);
3334 ED_space_text_scroll_to_cursor(st, region, false);
3336 }
3337 }
3338 else if (!st->wordwrap && (event->mval[0] < 0 || event->mval[0] > region->winx)) {
3340
3341 if (event->type == TIMER) {
3343 st, region, std::clamp(event->mval[0], 0, int(region->winx)), event->mval[1], true);
3344 ED_space_text_scroll_to_cursor(st, region, false);
3346 }
3347 }
3348 else {
3350
3351 if (event->type != TIMER) {
3352 text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], true);
3353 ED_space_text_scroll_to_cursor(st, region, false);
3355
3356 ssel->mval_prev[0] = event->mval[0];
3357 ssel->mval_prev[1] = event->mval[1];
3358 }
3359 }
3360}
3361
3363{
3365 SetSelection *ssel = static_cast<SetSelection *>(op->customdata);
3366
3369
3371
3373 MEM_delete(ssel);
3374}
3375
3377 wmOperator *op,
3378 const wmEvent *event)
3379{
3381 SetSelection *ssel;
3382
3383 if (event->mval[0] >= st->runtime->scroll_region_handle.xmin) {
3384 return OPERATOR_PASS_THROUGH;
3385 }
3386
3387 op->customdata = MEM_new_zeroed<SetSelection>("SetCursor");
3388 ssel = static_cast<SetSelection *>(op->customdata);
3389
3390 ssel->mval_prev[0] = event->mval[0];
3391 ssel->mval_prev[1] = event->mval[1];
3392
3393 ssel->sell = txt_get_span(st->text->lines.first(), st->text->sell);
3394 ssel->selc = st->text->selc;
3395
3397
3398 text_cursor_set_apply(C, op, event);
3399
3401}
3402
3404{
3405 switch (event->type) {
3406 case LEFTMOUSE:
3407 case MIDDLEMOUSE:
3408 case RIGHTMOUSE:
3410 return OPERATOR_FINISHED;
3411 case TIMER:
3412 case MOUSEMOVE:
3413 text_cursor_set_apply(C, op, event);
3414 break;
3415 default: {
3416 break;
3417 }
3418 }
3419
3421}
3422
3424{
3426}
3427
3429{
3430 /* Identifiers. */
3431 ot->name = "Set Selection";
3432 ot->idname = "TEXT_OT_selection_set";
3433 ot->description = "Set text selection";
3434
3435 /* API callbacks. */
3440}
3441
3443
3444/* -------------------------------------------------------------------- */
3447
3449{
3451 ARegion *region = CTX_wm_region(C);
3452 int x = RNA_int_get(op->ptr, "x");
3453 int y = RNA_int_get(op->ptr, "y");
3454
3455 text_cursor_set_to_pos(st, region, x, y, false);
3456
3459
3460 return OPERATOR_PASS_THROUGH;
3461}
3462
3464{
3466
3467 if (event->mval[0] >= st->runtime->scroll_region_handle.xmin) {
3468 return OPERATOR_PASS_THROUGH;
3469 }
3470
3471 RNA_int_set(op->ptr, "x", event->mval[0]);
3472 RNA_int_set(op->ptr, "y", event->mval[1]);
3473
3474 return text_cursor_set_exec(C, op);
3475}
3476
3478{
3479 /* Identifiers. */
3480 ot->name = "Set Cursor";
3481 ot->idname = "TEXT_OT_cursor_set";
3482 ot->description = "Set cursor position";
3483
3484 /* API callbacks. */
3488
3489 /* Properties. */
3490 RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
3491 RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
3492}
3493
3495
3496/* -------------------------------------------------------------------- */
3499
3501 wmOperator * /*op*/,
3502 const wmEvent *event)
3503{
3505 Text *text = CTX_data_edit_text(C);
3506 ARegion *region = CTX_wm_region(C);
3507 const int *mval = event->mval;
3508 double time;
3509 static int jump_to = 0;
3510 static double last_jump = 0;
3511
3513
3514 if (!st->showlinenrs) {
3515 return OPERATOR_PASS_THROUGH;
3516 }
3517
3518 if (!(mval[0] > 2 &&
3519 mval[0] < (TXT_NUMCOL_WIDTH(st) + (TXT_BODY_LPAD * st->runtime->char_width_px)) &&
3520 mval[1] > 2 && mval[1] < region->winy - 2))
3521 {
3522 return OPERATOR_PASS_THROUGH;
3523 }
3524
3525 const char event_ascii = WM_event_utf8_to_ascii(event);
3526 if (!(event_ascii >= '0' && event_ascii <= '9')) {
3527 return OPERATOR_PASS_THROUGH;
3528 }
3529
3530 time = BLI_time_now_seconds();
3531 if (last_jump < time - 1) {
3532 jump_to = 0;
3533 }
3534
3535 jump_to *= 10;
3536 jump_to += int(event_ascii - '0');
3537
3538 txt_move_toline(text, jump_to - 1, false);
3539 last_jump = time;
3540
3543
3544 return OPERATOR_FINISHED;
3545}
3546
3548{
3549 /* Identifiers. */
3550 ot->name = "Line Number";
3551 ot->idname = "TEXT_OT_line_number";
3552 ot->description = "The current line number";
3553
3554 /* API callbacks. */
3557}
3558
3560
3561/* -------------------------------------------------------------------- */
3564
3566{
3568 Text *text = CTX_data_edit_text(C);
3569 char *str;
3570 int str_len;
3571 bool done = false;
3572 size_t i = 0;
3573 uint code;
3574
3576
3577 str = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, &str_len);
3578
3579 /* NOTE: we rely on this check to ensure `done` will never be false,
3580 * this area of code should be refactored not to depend on `done`
3581 * being set as a side-effect of a successful insert. */
3582 if (*str == '\0' || text->curl == nullptr) {
3583 MEM_delete(str);
3584 return OPERATOR_CANCELLED;
3585 }
3586
3588
3589 if (st && st->overwrite) {
3590 while (str[i]) {
3591 code = BLI_str_utf8_as_unicode_step_safe(str, str_len, &i);
3592 done |= txt_replace_char(text, code);
3593 }
3594 }
3595 else {
3596 while (str[i]) {
3597 code = BLI_str_utf8_as_unicode_step_safe(str, str_len, &i);
3598 done |= txt_add_char(text, code);
3599 }
3600 }
3601
3602 MEM_delete(str);
3603
3604 BLI_assert(done);
3605 UNUSED_VARS_NDEBUG(done);
3606
3607 text_update_line_edited(text->curl);
3608
3611
3612 return OPERATOR_FINISHED;
3613}
3614
3616{
3619
3620 /* Auto-close variables. */
3621 bool do_auto_close = false;
3622 bool do_auto_close_select = false;
3623
3624 uint auto_close_char_input = 0;
3625 uint auto_close_char_match = 0;
3626 /* Variables needed to restore the selection when auto-closing around an existing selection. */
3627 struct {
3628 TextLine *sell;
3629 TextLine *curl;
3630 int selc;
3631 int curc;
3632 } auto_close_select = {nullptr}, auto_close_select_backup = {nullptr};
3633
3634#ifdef WITH_INPUT_IME
3635 if (const std::optional<wmOperatorStatus> status = WM_operator_IME_insert_maybe(
3636 C, op, event, "text"))
3637 {
3638 return *status;
3639 }
3640#endif
3641
3642 /* NOTE: the "text" property is always set from key-map,
3643 * so we can't use #RNA_struct_property_is_set, check the length instead. */
3644 if (!RNA_string_length(op->ptr, "text")) {
3645 /* If Alt/Control/Super are pressed pass through except for UTF8 character event
3646 * (when input method are used for UTF8 inputs, the user may assign key event
3647 * including Alt/Control/Super like Control-M to commit UTF8 string.
3648 * In such case, the modifiers in the UTF8 character event make no sense). */
3649 if ((event->modifier & (KM_CTRL | KM_OSKEY)) && !event->utf8_buf[0]) {
3650 return OPERATOR_PASS_THROUGH;
3651 }
3652
3653 char str[BLI_UTF8_MAX + 1];
3654 const size_t len = BLI_str_utf8_size_safe(event->utf8_buf);
3655 memcpy(str, event->utf8_buf, len);
3656 str[len] = '\0';
3657 RNA_string_set(op->ptr, "text", str);
3658
3659 if (U.text_flag & USER_TEXT_EDIT_AUTO_CLOSE) {
3660 auto_close_char_input = BLI_str_utf8_as_unicode_or_error(str);
3661 if (isascii(auto_close_char_input)) {
3662 auto_close_char_match = text_closing_character_pair_get(auto_close_char_input);
3663 if (auto_close_char_match != 0) {
3664 do_auto_close = true;
3665
3666 if (txt_has_sel(st->text) &&
3667 !text_span_is_blank(st->text->sell, st->text->selc, st->text->curl, st->text->curc))
3668 {
3669 do_auto_close_select = true;
3670
3671 auto_close_select_backup.curl = st->text->curl;
3672 auto_close_select_backup.curc = st->text->curc;
3673 auto_close_select_backup.sell = st->text->sell;
3674 auto_close_select_backup.selc = st->text->selc;
3675
3676 /* Movers the cursor to the start of the selection. */
3677 txt_order_cursors(st->text, false);
3678
3679 auto_close_select.curl = st->text->curl;
3680 auto_close_select.curc = st->text->curc;
3681 auto_close_select.sell = st->text->sell;
3682 auto_close_select.selc = st->text->selc;
3683
3684 txt_pop_sel(st->text);
3685 }
3686 }
3687 }
3688 }
3689 }
3690
3691 ret = text_insert_exec(C, op);
3692
3693 if (do_auto_close) {
3694 if (ret == OPERATOR_FINISHED) {
3695 const int auto_close_char_len = BLI_str_utf8_from_unicode_len(auto_close_char_input);
3696 /* If there was a selection, move cursor to the end of it. */
3697 if (do_auto_close_select) {
3698 /* Update the value in-place as needed. */
3699 if (auto_close_select.curl == auto_close_select.sell) {
3700 auto_close_select.selc += auto_close_char_len;
3701 }
3702 /* Move the cursor to the end of the selection. */
3703 st->text->curl = auto_close_select.sell;
3704 st->text->curc = auto_close_select.selc;
3705 txt_pop_sel(st->text);
3706 }
3707
3708 txt_add_char(st->text, auto_close_char_match);
3709 txt_move_left(st->text, false);
3710
3711 /* If there was a selection, restore it. */
3712 if (do_auto_close_select) {
3713 /* Mark the selection as edited. */
3714 if (auto_close_select.curl != auto_close_select.sell) {
3715 TextLine *line = auto_close_select.curl;
3716 do {
3717 line = line->next;
3719 } while (line != auto_close_select.sell);
3720 }
3721 st->text->curl = auto_close_select.curl;
3722 st->text->curc = auto_close_select.curc + auto_close_char_len;
3723 st->text->sell = auto_close_select.sell;
3724 st->text->selc = auto_close_select.selc;
3725 }
3726 }
3727 else {
3728 /* If nothing was done & the selection was removed, restore the selection. */
3729 if (do_auto_close_select) {
3730 st->text->curl = auto_close_select_backup.curl;
3731 st->text->curc = auto_close_select_backup.curc;
3732 st->text->sell = auto_close_select_backup.sell;
3733 st->text->selc = auto_close_select_backup.selc;
3734 }
3735 }
3736 }
3737
3738 /* Run the script while editing, evil but useful. */
3739 if (ret == OPERATOR_FINISHED && st->live_edit) {
3740 text_run_script(C, nullptr);
3741 }
3742
3743 return ret;
3744}
3745
3747{
3748 PropertyRNA *prop;
3749
3750 /* Identifiers. */
3751 ot->name = "Insert";
3752 ot->idname = "TEXT_OT_insert";
3753 ot->description = "Insert text at cursor position";
3754
3755 /* API callbacks. */
3756 ot->exec = text_insert_exec;
3758 ot->poll = text_edit_poll;
3759
3760 /* Flags. */
3761 ot->flag = OPTYPE_UNDO;
3762
3763 /* Properties. */
3764 prop = RNA_def_string(
3765 ot->srna, "text", nullptr, 0, "Text", "Text to insert at the cursor position");
3767}
3768
3770
3771/* -------------------------------------------------------------------- */
3774
3775/* Mode. */
3776enum {
3779};
3780
3782{
3783 Main *bmain = CTX_data_main(C);
3785 Text *text = st->text;
3786 int flags;
3787 bool found = false;
3788 char *tmp;
3789
3790 if (!st->findstr[0]) {
3791 return OPERATOR_CANCELLED;
3792 }
3793
3794 flags = st->flags;
3795 if (flags & ST_FIND_ALL) {
3796 flags &= ~ST_FIND_WRAP;
3797 }
3798
3799 /* Replace current. */
3800 if (mode != TEXT_FIND && txt_has_sel(text)) {
3801 tmp = txt_sel_to_buf(text, nullptr);
3802
3803 if (flags & ST_MATCH_CASE) {
3804 found = STREQ(st->findstr, tmp);
3805 }
3806 else {
3807 found = BLI_strcasecmp(st->findstr, tmp) == 0;
3808 }
3809
3810 if (found) {
3811 if (mode == TEXT_REPLACE) {
3813 txt_insert_buf(text, st->replacestr, strlen(st->replacestr));
3814 if (text->curl && text->curl->format) {
3815 MEM_delete(text->curl->format);
3816 text->curl->format = nullptr;
3817 }
3821 }
3822 }
3823 MEM_delete(tmp);
3824 tmp = nullptr;
3825 }
3826
3827 /* Find next. */
3828 if (txt_find_string(text, st->findstr, flags & ST_FIND_WRAP, flags & ST_MATCH_CASE)) {
3831 }
3832 else if (flags & ST_FIND_ALL) {
3833 if (text->id.next) {
3834 text = st->text = static_cast<Text *>(text->id.next);
3835 }
3836 else {
3837 text = st->text = bmain->texts.first();
3838 }
3839 txt_move_toline(text, 0, false);
3842 }
3843 else {
3844 if (!found) {
3845 BKE_reportf(op->reports, RPT_INFO, "Text not found: %s", st->findstr);
3846 }
3847 }
3848
3849 return OPERATOR_FINISHED;
3850}
3851
3856
3858{
3859 /* Identifiers. */
3860 ot->name = "Find Next";
3861 ot->idname = "TEXT_OT_find";
3862 ot->description = "Find specified text";
3863
3864 /* API callbacks. */
3865 ot->exec = text_find_exec;
3867}
3868
3870
3871/* -------------------------------------------------------------------- */
3874
3876{
3878 Text *text = st->text;
3879 const int flags = st->flags;
3880 bool found = false;
3881
3882 if (!st->findstr[0]) {
3883 return OPERATOR_CANCELLED;
3884 }
3885
3886 const int orig_curl = BLI_findindex(&text->lines, text->curl);
3887 const int orig_curc = text->curc;
3888 bool has_sel = txt_has_sel(text);
3889
3890 txt_move_toline(text, 0, false);
3891
3892 found = txt_find_string(text, st->findstr, 0, flags & ST_MATCH_CASE);
3893 if (found) {
3895
3896 do {
3897 txt_insert_buf(text, st->replacestr, strlen(st->replacestr));
3898 if (text->curl && text->curl->format) {
3899 MEM_delete(text->curl->format);
3900 text->curl->format = nullptr;
3901 }
3902 found = txt_find_string(text, st->findstr, 0, flags & ST_MATCH_CASE);
3903 } while (found);
3904
3907 }
3908 else {
3909 /* Restore position. */
3910 txt_move_to(text, orig_curl, orig_curc, has_sel);
3911 return OPERATOR_CANCELLED;
3912 }
3913
3914 return OPERATOR_FINISHED;
3915}
3916
3918{
3919 bool replace_all = RNA_boolean_get(op->ptr, "all");
3920 if (replace_all) {
3921 return text_replace_all(C);
3922 }
3924}
3925
3927{
3928 /* Identifiers. */
3929 ot->name = "Replace";
3930 ot->idname = "TEXT_OT_replace";
3931 ot->description = "Replace text with the specified text";
3932
3933 /* API callbacks. */
3934 ot->exec = text_replace_exec;
3936
3937 /* Flags. */
3938 ot->flag = OPTYPE_UNDO;
3939
3940 /* Properties. */
3941 PropertyRNA *prop;
3942 prop = RNA_def_boolean(ot->srna, "all", false, "Replace All", "Replace all occurrences");
3944}
3945
3947
3948/* -------------------------------------------------------------------- */
3951
3953{
3955 Text *text = CTX_data_edit_text(C);
3956 char *tmp;
3957
3958 tmp = txt_sel_to_buf(text, nullptr);
3959 STRNCPY_UTF8(st->findstr, tmp);
3960 MEM_delete(tmp);
3961
3962 if (!st->findstr[0]) {
3963 return OPERATOR_FINISHED;
3964 }
3965
3966 return text_find_and_replace(C, op, TEXT_FIND);
3967}
3968
3970{
3971 /* Identifiers. */
3972 ot->name = "Find & Set Selection";
3973 ot->idname = "TEXT_OT_find_set_selected";
3974 ot->description = "Find specified text and set as selected";
3975
3976 /* API callbacks. */
3979}
3980
3982
3983/* -------------------------------------------------------------------- */
3986
3988{
3990 Text *text = CTX_data_edit_text(C);
3991 char *tmp;
3992
3993 tmp = txt_sel_to_buf(text, nullptr);
3994 STRNCPY_UTF8(st->replacestr, tmp);
3995 MEM_delete(tmp);
3996
3997 return OPERATOR_FINISHED;
3998}
3999
4001{
4002 /* Identifiers. */
4003 ot->name = "Replace & Set Selection";
4004 ot->idname = "TEXT_OT_replace_set_selected";
4005 ot->description = "Replace text with specified text and set as selected";
4006
4007 /* API callbacks. */
4010
4011 /* Flags. */
4012 ot->flag = OPTYPE_UNDO;
4013}
4014
4016
4017/* -------------------------------------------------------------------- */
4020
4022 ReportList *reports,
4023 const char *filepath,
4024 const int line_index,
4025 const int column_index)
4026{
4027 bool success = false;
4028#ifdef WITH_PYTHON
4029 BPy_RunErrInfo err_info = {};
4030 err_info.reports = reports;
4031 err_info.report_prefix = "External editor";
4032
4033 const char *expr_imports[] = {"_bl_text_utils", "_bl_text_utils.external_editor", "os", nullptr};
4034 std::string expr;
4035 {
4036 std::stringstream expr_stream;
4037 expr_stream << "_bl_text_utils.external_editor.open_external_editor(os.fsdecode(b'";
4038 for (const char *ch = filepath; *ch; ch++) {
4039 expr_stream << "\\x" << std::hex << int(*ch);
4040 }
4041 expr_stream << "'), " << std::dec << line_index << ", " << std::dec << column_index << ")";
4042 expr = expr_stream.str();
4043 }
4044
4045 char *expr_result = nullptr;
4046 if (BPY_run_string_as_string(C, expr_imports, expr.c_str(), &err_info, &expr_result)) {
4047 /* No error. */
4048 if (expr_result[0] == '\0') {
4050 reports, RPT_INFO, "See '%s' in the external editor", BLI_path_basename(filepath));
4051 success = true;
4052 }
4053 else {
4054 BKE_report(reports, RPT_ERROR, expr_result);
4055 }
4056 MEM_delete(expr_result);
4057 }
4058#else
4059 UNUSED_VARS(C, reports, filepath, line_index, column_index);
4060#endif /* WITH_PYTHON */
4061 return success;
4062}
4063
4065 ReportList *reports,
4066 const char *filepath,
4067 const int line_index,
4068 const int column_index)
4069{
4070 Main *bmain = CTX_data_main(C);
4071 Text *text = nullptr;
4072 BLI_assert(!BLI_path_is_rel(filepath));
4073
4074 for (Text &text_iter : bmain->texts) {
4075 if (text_iter.filepath == nullptr) {
4076 continue;
4077 }
4078 const char *filepath_iter;
4079 char filepath_iter_buf[FILE_MAX];
4080 if (BLI_path_is_rel(text_iter.filepath)) {
4081 STRNCPY(filepath_iter_buf, text_iter.filepath);
4082 BLI_path_abs(filepath_iter_buf, ID_BLEND_PATH(bmain, &text_iter.id));
4083 filepath_iter = filepath_iter_buf;
4084 }
4085 else {
4086 filepath_iter = text_iter.filepath;
4087 }
4088
4089 if (BLI_path_cmp(filepath, filepath_iter) == 0) {
4090 text = &text_iter;
4091 break;
4092 }
4093 }
4094
4095 if (text == nullptr) {
4096 text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
4097 }
4098
4099 if (text == nullptr) {
4100 BKE_reportf(reports, RPT_WARNING, "File '%s' cannot be opened", filepath);
4101 return false;
4102 }
4103
4104 txt_move_to(text, line_index, column_index, false);
4105
4106 /* NOTE(@ideasman42): it's bad practice that this operator searches for the text area to set.
4107 * not a good precedent, since this is a developer tool allow it. */
4108 if (!ED_text_activate_in_screen(C, text)) {
4109 BKE_reportf(reports, RPT_INFO, "See '%s' in the text editor", text->id.name + 2);
4110 }
4111
4113
4114 return true;
4115}
4116
4118{
4119 Main *bmain = CTX_data_main(C);
4120 PropertyRNA *prop_filepath = RNA_struct_find_property(op->ptr, "filepath");
4121 PropertyRNA *prop_line = RNA_struct_find_property(op->ptr, "line");
4122 PropertyRNA *prop_column = RNA_struct_find_property(op->ptr, "column");
4123
4124 if (!RNA_property_is_set(op->ptr, prop_filepath)) {
4125 if (const Text *text = CTX_data_edit_text(C)) {
4126 if (text->filepath != nullptr) {
4127 const TextLine *line = text->curl;
4128 const int line_index = BLI_findindex(&text->lines, text->curl);
4129 const int column_index = BLI_str_utf8_offset_to_index(line->line, line->len, text->curc);
4130
4131 char filepath[FILE_MAX];
4132 STRNCPY(filepath, text->filepath);
4133 BLI_path_abs(filepath, ID_BLEND_PATH(bmain, &text->id));
4134 RNA_property_string_set(op->ptr, prop_filepath, filepath);
4135 RNA_property_int_set(op->ptr, prop_line, line_index);
4136 RNA_property_int_set(op->ptr, prop_column, column_index);
4137 }
4138 }
4139 }
4140
4141 char filepath[FILE_MAX];
4142 RNA_property_string_get(op->ptr, prop_filepath, filepath);
4143 if (BLI_path_is_rel(filepath)) [[unlikely]] {
4144 BLI_path_abs(filepath, BKE_main_blendfile_path(bmain));
4145 }
4146 const int line_index = RNA_property_int_get(op->ptr, prop_line);
4147 const int column_index = RNA_property_int_get(op->ptr, prop_column);
4148
4149 if (filepath[0] == '\0') {
4150 BKE_report(op->reports, RPT_WARNING, "File path property not set");
4151 return OPERATOR_CANCELLED;
4152 }
4153
4154 /* Useful to copy-paste from the terminal. */
4155 printf("%s:%d:%d\n", filepath, line_index + 1, column_index);
4156
4157 bool success;
4158 if (U.text_editor[0] != '\0') {
4160 C, op->reports, filepath, line_index, column_index);
4161 }
4162 else {
4164 C, op->reports, filepath, line_index, column_index);
4165 }
4166
4167 return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
4168}
4169
4171{
4172 PropertyRNA *prop;
4173
4174 /* Identifiers. */
4175 ot->name = "Jump to File at Point";
4176 ot->idname = "TEXT_OT_jump_to_file_at_point";
4177 ot->description = "Jump to a file for the text editor";
4178
4179 /* API callbacks. */
4181
4182 /* Flags. */
4183 ot->flag = 0;
4184
4185 prop = RNA_def_string(ot->srna, "filepath", nullptr, FILE_MAX, "Filepath", "");
4188 prop = RNA_def_int(ot->srna, "line", 0, 0, INT_MAX, "Line", "Line to jump to", 1, 10000);
4191 prop = RNA_def_int(ot->srna, "column", 0, 0, INT_MAX, "Column", "Column to jump to", 1, 10000);
4193}
4194
4196
4197/* -------------------------------------------------------------------- */
4200
4203 {RESOLVE_IGNORE, "IGNORE", 0, "Ignore", ""},
4204 {RESOLVE_RELOAD, "RELOAD", 0, "Reload", ""},
4205 {RESOLVE_SAVE, "SAVE", 0, "Save", ""},
4206 {RESOLVE_MAKE_INTERNAL, "MAKE_INTERNAL", 0, "Make Internal", ""},
4207 {0, nullptr, 0, nullptr, nullptr},
4208};
4209
4211{
4212 Text *text = CTX_data_edit_text(C);
4213
4214 if (!text_edit_poll(C)) {
4215 return false;
4216 }
4217
4218 return ((text->filepath != nullptr) && !(text->flags & TXT_ISMEM));
4219}
4220
4222{
4223 Text *text = CTX_data_edit_text(C);
4224 int resolution = RNA_enum_get(op->ptr, "resolution");
4225
4226 switch (resolution) {
4227 case RESOLVE_RELOAD:
4228 return text_reload_exec(C, op);
4229 case RESOLVE_SAVE:
4230 return text_save_exec(C, op);
4232 return text_make_internal_exec(C, op);
4233 case RESOLVE_IGNORE:
4235 return OPERATOR_FINISHED;
4236 }
4237
4238 return OPERATOR_CANCELLED;
4239}
4240
4242 wmOperator *op,
4243 const wmEvent * /*event*/)
4244{
4245 Text *text = CTX_data_edit_text(C);
4246
4247 switch (BKE_text_file_modified_check(text)) {
4248 case 1:
4249 if (text->flags & TXT_ISDIRTY) {
4250 /* Modified locally and externally, ah. offer more possibilities. */
4252 C, IFACE_("File Modified Outside and Inside Blender"), ICON_NONE);
4253 ui::Layout &layout = *popup_menu_layout(pup);
4254 PointerRNA op_ptr = layout.op(
4255 op->type, IFACE_("Reload from disk (ignore local changes)"), ICON_NONE);
4256 RNA_enum_set(&op_ptr, "resolution", RESOLVE_RELOAD);
4257 op_ptr = layout.op(op->type, IFACE_("Save to disk (ignore outside changes)"), ICON_NONE);
4258 RNA_enum_set(&op_ptr, "resolution", RESOLVE_SAVE);
4259 op_ptr = layout.op(op->type, IFACE_("Make text internal (separate copy)"), ICON_NONE);
4260 RNA_enum_set(&op_ptr, "resolution", RESOLVE_MAKE_INTERNAL);
4261 popup_menu_end(C, pup);
4262 }
4263 else {
4265 C, IFACE_("File Modified Outside Blender"), ICON_NONE);
4266 ui::Layout &layout = *popup_menu_layout(pup);
4267 PointerRNA op_ptr = layout.op(op->type, IFACE_("Reload from disk"), ICON_NONE);
4268 RNA_enum_set(&op_ptr, "resolution", RESOLVE_RELOAD);
4269 op_ptr = layout.op(op->type, IFACE_("Make text internal (separate copy)"), ICON_NONE);
4270 RNA_enum_set(&op_ptr, "resolution", RESOLVE_MAKE_INTERNAL);
4271 op_ptr = layout.op(op->type, IFACE_("Ignore"), ICON_NONE);
4272 RNA_enum_set(&op_ptr, "resolution", RESOLVE_IGNORE);
4273 popup_menu_end(C, pup);
4274 }
4275 break;
4276 case 2:
4278 C, IFACE_("File Deleted Outside Blender"), ICON_NONE);
4279 ui::Layout &layout = *popup_menu_layout(pup);
4280 PointerRNA op_ptr = layout.op(op->type, IFACE_("Make text internal"), ICON_NONE);
4281 RNA_enum_set(&op_ptr, "resolution", RESOLVE_MAKE_INTERNAL);
4282 op_ptr = layout.op(op->type, IFACE_("Recreate file"), ICON_NONE);
4283 RNA_enum_set(&op_ptr, "resolution", RESOLVE_SAVE);
4284 popup_menu_end(C, pup);
4285 break;
4286 }
4287
4288 return OPERATOR_INTERFACE;
4289}
4290
4292{
4293 /* Identifiers. */
4294 ot->name = "Resolve Conflict";
4295 ot->idname = "TEXT_OT_resolve_conflict";
4296 ot->description = "When external text is out of sync, resolve the conflict";
4297
4298 /* API callbacks. */
4302
4303 /* Properties. */
4304 RNA_def_enum(ot->srna,
4305 "resolution",
4308 "Resolution",
4309 "How to solve conflict due to differences in internal and external text");
4310}
4311
4313
4314/* -------------------------------------------------------------------- */
4317
4319{
4320 const Text *text = CTX_data_edit_text(C);
4321 const bool split_lines = RNA_boolean_get(op->ptr, "split_lines");
4322
4323 ED_text_to_object(C, text, split_lines);
4324
4325 return OPERATOR_FINISHED;
4326}
4327
4329{
4330 /* Identifiers. */
4331 ot->name = "To 3D Object";
4332 ot->idname = "TEXT_OT_to_3d_object";
4333 ot->description = "Create 3D text object from active text data-block";
4334
4335 /* API callbacks. */
4337 ot->poll = text_data_poll;
4338
4339 /* Flags. */
4341
4342 /* Properties. */
4344 ot->srna, "split_lines", false, "Split Lines", "Create one object per line in the text");
4345}
4346
4348
4349/* -------------------------------------------------------------------- */
4352
4354{
4356 const Text *text = CTX_data_edit_text(C);
4357
4358 /* See if we have a text datablock in context. */
4359 if (text == nullptr) {
4360 return false;
4361 }
4362
4363 /* Test if we have a render engine that supports shaders scripts. */
4364 if (!(type && (type->update_script_node || type->update_custom_camera))) {
4365 return false;
4366 }
4367
4368 /* We don't check if text datablock is actually in use, too slow for poll. */
4369 return true;
4370}
4371
4374 RenderEngineType *type,
4375 bNodeTree *ntree,
4376 Text *text,
4377 VectorSet<bNodeTree *> &done_trees)
4378{
4379 bool found = false;
4380
4381 done_trees.add_new(ntree);
4382
4383 /* Update each script that is using this text datablock. */
4384 for (bNode *node : ntree->all_nodes()) {
4385 if (node->type_legacy == NODE_GROUP) {
4386 bNodeTree *ngroup = id_cast<bNodeTree *>(node->id);
4387 if (ngroup && !done_trees.contains(ngroup)) {
4388 found |= text_update_shader_text_recursive(engine, type, ngroup, text, done_trees);
4389 }
4390 }
4391 else if (node->type_legacy == SH_NODE_SCRIPT && node->id == &text->id) {
4392 type->update_script_node(engine, ntree, node);
4393 found = true;
4394 }
4395 }
4396
4397 return found;
4398}
4399
4401{
4402 Main *bmain = CTX_data_main(C);
4404 Text *text = CTX_data_edit_text(C);
4405 bool found = false;
4406
4407 /* Setup render engine. */
4408 RenderEngine *engine = RE_engine_create(type);
4409 engine->reports = op->reports;
4410
4411 /* Update all nodes using text datablock. */
4412 if (type->update_script_node != nullptr) {
4413 VectorSet<bNodeTree *> done_trees;
4414 FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
4415 if (ntree->type == NTREE_SHADER) {
4416 if (!done_trees.contains(ntree)) {
4417 found |= text_update_shader_text_recursive(engine, type, ntree, text, done_trees);
4418 }
4419 }
4420 }
4422 }
4423
4424 /* Update all cameras using text data-block. */
4425 if (type->update_custom_camera != nullptr) {
4426 for (Camera &cam : bmain->cameras) {
4427 if (cam.custom_shader == text) {
4428 type->update_custom_camera(engine, &cam);
4429 found = true;
4430 }
4431 }
4432 }
4433
4434 if (!found) {
4435 BKE_report(op->reports, RPT_INFO, "Text not used by any node or camera, no update done");
4436 }
4437
4438 RE_engine_free(engine);
4439
4440 return (found) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
4441}
4442
4444{
4445 /* Identifiers. */
4446 ot->name = "Shader Update";
4447 ot->description =
4448 "Update users of this shader, such as custom cameras and script nodes, with its new sockets "
4449 "and options";
4450 ot->idname = "TEXT_OT_update_shader";
4451
4452 /* API callbacks. */
4455
4456 /* Flags. */
4458}
4459
4461
4462} // namespace blender
#define FOREACH_NODETREE_END
Definition BKE_node.hh:936
#define NODE_GROUP
Definition BKE_node.hh:865
#define FOREACH_NODETREE_BEGIN(bmain, _nodetree, _id)
Definition BKE_node.hh:926
#define SH_NODE_SCRIPT
File and directory operations.
#define FILE_MAX
#define BLI_path_cmp
#define BLI_UTF8_MAX
#define STRNCPY_UTF8(dst, src)
Platform independent time functions.
#define BLT_I18NCONTEXT_ID_TEXT
#define RPT_(msgid)
#define IFACE_(msgid)
#define DATA_(msgid)
#define ID_BLEND_PATH(_bmain, _id)
Definition DNA_ID.h:688
#define TXT_TABSIZE
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_CURSOR
Definition WM_types.hh:533
#define NA_ADDED
Definition WM_types.hh:636
#define NA_EDITED
Definition WM_types.hh:634
#define NC_TEXT
Definition WM_types.hh:399
#define NA_REMOVED
Definition WM_types.hh:637
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define BLI_INLINE
#define ELEM(...)
#define STREQ(a, b)
btScalar max
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
bool contains(const Key &key) const
void add_new(const Key &key)
#define str(s)
#define INT_MAX
const int state
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
BMesh Iterators.
static bool text_update_shader_poll(bContext *C)
Definition text_ops.cc:4353
static wmOperatorStatus text_comment_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:1348
static wmOperatorStatus text_insert_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:3565
void ED_text_to_object(bContext *C, const Text *text, const bool split_lines)
Definition editfont.cc:909
UserDef U
Definition blender.cc:58
bool text_space_edit_poll(bContext *C)
Definition text_ops.cc:283
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static wmOperatorStatus text_resolve_conflict_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition text_ops.cc:4241
@ RESOLVE_IGNORE
Definition text_ops.cc:4201
@ RESOLVE_MAKE_INTERNAL
Definition text_ops.cc:4201
@ RESOLVE_SAVE
Definition text_ops.cc:4201
@ RESOLVE_RELOAD
Definition text_ops.cc:4201
int char char int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int flatten_string(const SpaceText *st, FlattenString *fs, const char *in)
void TEXT_OT_delete(wmOperatorType *ot)
Definition text_ops.cc:2582
struct Text * BKE_text_add(struct Main *bmain, const char *name)
Definition text.cc:284
static wmOperatorStatus text_unlink_exec(bContext *C, wmOperator *)
Definition text_ops.cc:610
static void text_open_init(bContext *C, wmOperator *op)
Definition text_ops.cc:404
static void txt_copy_clipboard(const Text *text)
Definition text_ops.cc:1081
static wmOperatorStatus text_line_number_invoke(bContext *C, wmOperator *, const wmEvent *event)
Definition text_ops.cc:3500
ScrArea * CTX_wm_area(const bContext *C)
int txt_get_span(const struct TextLine *from, const struct TextLine *to)
static bool text_new_poll(bContext *)
Definition text_ops.cc:253
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void txt_write_file(Main *bmain, Text *text, ReportList *reports)
Definition text_ops.cc:704
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
static wmOperatorStatus text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:2877
int txt_calc_tab_left(const struct TextLine *tl, int ch)
static bool text_span_is_blank(TextLine *line1, const int line1_char, TextLine *line2, const int line2_char)
Definition text_ops.cc:124
@ RPT_WARNING
Definition BKE_report.hh:40
void TEXT_OT_new(wmOperatorType *ot)
Definition text_ops.cc:383
void BKE_id_delete(Main *bmain, void *idv, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void txt_jump_left(struct Text *text, bool sel, bool use_init_step)
Definition text.cc:961
static int flatten_width(SpaceText *st, const char *str)
Definition text_ops.cc:3063
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
void txt_insert_buf(struct Text *text, const char *in_buffer, int in_buffer_len) ATTR_NONNULL(1
Definition text.cc:1545
void txt_indent(struct Text *text)
Definition text.cc:2163
unsigned int uint
Definition BKE_text.h:55
void space_text_drawcache_tag_update(SpaceText *st, const bool full)
Definition text_draw.cc:757
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
static char * buf_tabs_to_spaces(const char *in_buf, const int tab_size, int *r_out_buf_len)
Definition text_ops.cc:168
static wmOperatorStatus text_reload_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:529
void TEXT_OT_indent_or_autocomplete(wmOperatorType *ot)
Definition text_ops.cc:1183
void TEXT_OT_make_internal(wmOperatorType *ot)
Definition text_ops.cc:683
static wmOperatorStatus text_select_all_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1587
void text_update_line_edited(TextLine *line)
Definition text_ops.cc:328
static wmOperatorStatus text_select_line_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1619
PointerRNA RNA_id_pointer_create(ID *id)
static wmOperatorStatus text_open_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:417
int BLI_str_utf8_char_width_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void txt_move_eof(struct Text *text, bool sel)
Definition text.cc:1076
void TEXT_OT_cursor_set(wmOperatorType *ot)
Definition text_ops.cc:3477
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
static wmOperatorStatus text_move_select_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:2394
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static wmOperatorStatus text_line_break_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1291
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static wmOperatorStatus text_new_exec(bContext *C, wmOperator *)
Definition text_ops.cc:351
static wmOperatorStatus text_unindent_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1250
static wmOperatorStatus text_find_set_selected_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:3952
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void TEXT_OT_to_3d_object(wmOperatorType *ot)
Definition text_ops.cc:4328
static wmOperatorStatus text_indent_or_autocomplete_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1168
bool BKE_text_reload(struct Text *text)
Definition text.cc:419
void TEXT_OT_scroll_bar(wmOperatorType *ot)
Definition text_ops.cc:3027
void space_text_update_cursor_moved(bContext *C)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
static wmOperatorStatus text_replace_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:3917
void TEXT_OT_resolve_conflict(wmOperatorType *ot)
Definition text_ops.cc:4291
int RNA_int_get(PointerRNA *ptr, const char *name)
void TEXT_OT_select_all(wmOperatorType *ot)
Definition text_ops.cc:1601
void txt_backspace_char(struct Text *text)
Definition text.cc:1816
char WM_event_utf8_to_ascii(const wmEvent *event)
wmWindow * CTX_wm_window(const bContext *C)
static wmOperatorStatus move_lines_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:1684
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
@ TEXT_REPLACE
Definition text_ops.cc:3778
void TEXT_OT_convert_whitespace(wmOperatorType *ot)
Definition text_ops.cc:1558
static void text_scroll_cancel(bContext *C, wmOperator *op)
Definition text_ops.cc:2872
MINLINE int max_ii(int a, int b)
static wmOperatorStatus text_selection_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:3376
void txt_move_bof(struct Text *text, bool sel)
Definition text.cc:1053
MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2])
bool txt_has_sel(const struct Text *text)
static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
Definition text_ops.cc:3076
bool bool BPY_run_text(bContext *C, Text *text, ReportList *reports, bool do_jump) ATTR_NONNULL(1
void BPY_text_free_code(Text *text)
unsigned int BLI_str_utf8_as_unicode_step_safe(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
RenderEngineType * CTX_data_engine_type(const bContext *C)
Text * CTX_data_edit_text(const bContext *C)
static void space_text_cursor_skip(const SpaceText *st, const ARegion *region, Text *text, int lines, const bool sel)
Definition text_ops.cc:2200
bool ED_text_activate_in_screen(bContext *C, Text *text)
int space_text_get_total_lines(SpaceText *st, const ARegion *region)
Definition text_draw.cc:895
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void TEXT_OT_duplicate_line(wmOperatorType *ot)
Definition text_ops.cc:1060
static const EnumPropertyItem resolution_items[]
Definition text_ops.cc:4202
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
static wmOperatorStatus text_replace_all(bContext *C)
Definition text_ops.cc:3875
static wmOperatorStatus text_find_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:3852
void txt_sel_clear(struct Text *text)
Definition text.cc:1268
void txt_duplicate_line(struct Text *text)
Definition text.cc:1754
bool txt_add_char(struct Text *text, unsigned int add)
Definition text.cc:1924
void txt_comment(struct Text *text, const char *prefix)
Definition text.cc:2144
static void space_text_screen_skip(SpaceText *st, ARegion *region, int lines)
Definition text_ops.cc:2658
static bool text_scroll_poll(bContext *C)
Definition text_ops.cc:2704
static const EnumPropertyItem whitespace_type_items[]
Definition text_ops.cc:1418
static void text_update_edited(bContext *C, Object *obedit, const eEditFontMode mode)
Definition editfont.cc:408
void txt_move_toline(struct Text *text, unsigned int line, bool sel)
Definition text.cc:1099
void TEXT_OT_unindent(wmOperatorType *ot)
Definition text_ops.cc:1270
void ED_space_text_scroll_to_cursor(SpaceText *st, ARegion *region, bool center)
static bool text_jump_to_file_at_point_internal(bContext *C, ReportList *reports, const char *filepath, const int line_index, const int column_index)
Definition text_ops.cc:4064
static void scroll_exit(bContext *C, wmOperator *op)
Definition text_ops.cc:2818
void RE_engine_free(RenderEngine *engine)
Global G
Definition blender.cc:57
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void TEXT_OT_update_shader(wmOperatorType *ot)
Definition text_ops.cc:4443
static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:2729
static void text_selection_set_cancel(bContext *C, wmOperator *op)
Definition text_ops.cc:3423
static wmOperatorStatus text_save_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:775
static wmOperatorStatus text_to_3d_object_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:4318
bool txt_cursor_is_line_start(const struct Text *text)
SpaceText * CTX_wm_space_text(const bContext *C)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool txt_unindent(struct Text *text)
Definition text.cc:2174
static wmOperatorStatus text_make_internal_exec(bContext *C, wmOperator *)
Definition text_ops.cc:669
static wmOperatorStatus text_select_word_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1651
void TEXT_OT_save(wmOperatorType *ot)
Definition text_ops.cc:787
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
bool txt_find_string(struct Text *text, const char *findstr, int wrap, int match_case)
Definition text.cc:1599
@ TXT_MOVE_LINE_UP
Definition BKE_text.h:144
@ TXT_MOVE_LINE_DOWN
Definition BKE_text.h:145
static int space_text_get_cursor_rel(const SpaceText *st, const ARegion *region, TextLine *linein, int rell, int relc)
Definition text_ops.cc:1753
static bool text_region_edit_poll(bContext *C)
Definition text_ops.cc:300
void flatten_string_free(FlattenString *fs)
struct Text * BKE_text_load_ex(struct Main *bmain, const char *filepath, const char *relbase, bool is_internal) ATTR_NONNULL(1
Definition text.cc:456
void txt_delete_word(struct Text *text)
Definition text.cc:1809
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
void TEXT_OT_line_break(wmOperatorType *ot)
Definition text_ops.cc:1327
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
int txt_calc_tab_right(const struct TextLine *tl, int ch)
static wmOperatorStatus text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:3615
void TEXT_OT_select_word(wmOperatorType *ot)
Definition text_ops.cc:1666
BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct)
Definition BLI_rect.hh:190
static int cursor_skip_find_line(const SpaceText *st, const ARegion *region, int lines, TextLine **linep, int *charp, int *rell, int *relc)
Definition text_ops.cc:1847
static wmOperatorStatus text_find_and_replace(bContext *C, wmOperator *op, short mode)
Definition text_ops.cc:3781
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
Definition text_ops.cc:2028
int txt_setcurr_tab_spaces(struct Text *text, int space)
Definition text.cc:2216
bool txt_cursor_is_line_end(const struct Text *text)
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
@ WM_FILESEL_RELPATH
Definition WM_api.hh:1329
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
void TEXT_OT_unlink(wmOperatorType *ot)
Definition text_ops.cc:647
void txt_pop_sel(struct Text *text)
Definition text.cc:1181
static wmOperatorStatus text_unlink_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition text_ops.cc:636
wmWindowManager * CTX_wm_manager(const bContext *C)
static wmOperatorStatus text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:2966
int space_text_get_char_pos(const SpaceText *st, const char *line, int cur)
Definition text_draw.cc:387
static void test_line_start(char c, bool *r_last_state)
Definition text_ops.cc:82
static wmOperatorStatus text_move_cursor(bContext *C, int type, bool select)
Definition text_ops.cc:2241
void txt_sel_all(struct Text *text)
Definition text.cc:1259
void txt_move_lines(struct Text *text, int direction)
Definition text.cc:2185
void TEXT_OT_jump(wmOperatorType *ot)
Definition text_ops.cc:2454
int space_text_wrap_width(const SpaceText *st, const ARegion *region)
Definition text_draw.cc:200
void void txt_split_curline(struct Text *text)
Definition text.cc:1657
void TEXT_OT_scroll(wmOperatorType *ot)
Definition text_ops.cc:2917
void TEXT_OT_replace(wmOperatorType *ot)
Definition text_ops.cc:3926
static const EnumPropertyItem move_type_items[]
Definition editfont.cc:1315
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
void TEXT_OT_comment_toggle(wmOperatorType *ot)
Definition text_ops.cc:1385
static void txt_wrap_move_down(SpaceText *st, ARegion *region, const bool sel)
Definition text_ops.cc:2154
void txt_delete_selected(struct Text *text)
Definition text.cc:1934
@ USER_TEXT_EDIT_AUTO_CLOSE
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
void TEXT_OT_replace_set_selected(wmOperatorType *ot)
Definition text_ops.cc:4000
int BLI_str_utf8_offset_to_column_with_tabs(const char *str, size_t str_len, int offset_target, int tab_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void TEXT_OT_jump_to_file_at_point(wmOperatorType *ot)
Definition text_ops.cc:4170
bool BLI_file_is_writable(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition fileops_c.cc:293
void TEXT_OT_cut(wmOperatorType *ot)
Definition text_ops.cc:1147
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static wmOperatorStatus text_reload_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition text_ops.cc:574
static wmOperatorStatus text_update_shader_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:4400
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
int space_text_get_visible_lines(const SpaceText *st, const ARegion *region, const char *str)
Definition text_draw.cc:833
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus text_delete_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:2486
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
void TEXT_OT_select_line(wmOperatorType *ot)
Definition text_ops.cc:1633
static wmOperatorStatus text_resolve_conflict_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:4221
static wmOperatorStatus text_jump_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:2427
void TEXT_OT_open(wmOperatorType *ot)
Definition text_ops.cc:495
void txt_move_left(struct Text *text, bool sel)
Definition text.cc:874
const char * ED_text_format_comment_line_prefix(Text *text)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void txt_move_down(struct Text *text, bool sel)
Definition text.cc:801
char * txt_sel_to_buf(const struct Text *text, size_t *r_buf_strlen)
void TEXT_OT_move_lines(wmOperatorType *ot)
Definition text_ops.cc:1704
static wmOperatorStatus text_run_script(bContext *C, ReportList *reports)
Definition text_ops.cc:895
int RNA_string_length(PointerRNA *ptr, const char *name)
bool txt_uncomment(struct Text *text, const char *prefix)
Definition text.cc:2154
BLI_INLINE int space_text_pixel_x_to_column(const SpaceText *st, const int x)
Definition text_ops.cc:222
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
static wmOperatorStatus text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:2837
void int BKE_text_file_modified_check(const struct Text *text)
static void text_cursor_set_exit(bContext *C, wmOperator *op)
Definition text_ops.cc:3362
@ WM_CAPABILITY_CLIPBOARD_PRIMARY
Definition WM_api.hh:227
static void text_cursor_timer_remove(bContext *C, SetSelection *ssel)
Definition text_ops.cc:3312
void TEXT_OT_selection_set(wmOperatorType *ot)
Definition text_ops.cc:3428
static bool text_data_poll(bContext *C)
Definition text_ops.cc:258
void TEXT_OT_overwrite_toggle(wmOperatorType *ot)
Definition text_ops.cc:2624
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void txt_move_right(struct Text *text, bool sel)
Definition text.cc:917
static bool text_resolve_conflict_poll(bContext *C)
Definition text_ops.cc:4210
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:3323
RenderEngine * RE_engine_create(RenderEngineType *type)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
@ FILE_SAVE
Definition WM_api.hh:1342
@ FILE_OPENFILE
Definition WM_api.hh:1341
static wmOperatorStatus text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition text_ops.cc:832
void txt_sel_line(struct Text *text)
Definition text.cc:1276
static wmOperatorStatus text_scroll_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:2711
Main * CTX_data_main(const bContext *C)
void txt_move_bol(struct Text *text, bool sel)
Definition text.cc:1009
void TEXT_OT_find_set_selected(wmOperatorType *ot)
Definition text_ops.cc:3969
void txt_move_up(struct Text *text, bool sel)
Definition text.cc:769
void TEXT_OT_find(wmOperatorType *ot)
Definition text_ops.cc:3857
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void TEXT_OT_move_select(wmOperatorType *ot)
Definition text_ops.cc:2401
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
static void txt_wrap_move_up(SpaceText *st, ARegion *region, const bool sel)
Definition text_ops.cc:2113
UndoStep * ED_text_undo_push_init(bContext *C)
Definition text_undo.cc:250
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
eWM_CapabilitiesFlag WM_capabilities_flag()
void TEXT_OT_indent(wmOperatorType *ot)
Definition text_ops.cc:1229
void space_text_wrap_offset_in_line(const SpaceText *st, const ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
Definition text_draw.cc:315
void WM_clipboard_text_set(const char *buf, bool selection)
static void space_text_screen_clamp(SpaceText *st, const ARegion *region)
Definition text_ops.cc:2642
static wmOperatorStatus text_indent_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1204
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
struct Text struct Text * BKE_text_load(struct Main *bmain, const char *filepath, const char *relbase) ATTR_NONNULL(1
Definition text.cc:510
static wmOperatorStatus text_cut_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1124
static TextLine * space_text_get_line_pos_wrapped(const SpaceText *st, const ARegion *region, int *y)
Definition text_ops.cc:3094
static bool text_update_shader_text_recursive(RenderEngine *engine, RenderEngineType *type, bNodeTree *ntree, Text *text, VectorSet< bNodeTree * > &done_trees)
Definition text_ops.cc:4373
static bool text_unlink_poll(bContext *C)
Definition text_ops.cc:604
static char text_closing_character_pair_get(const char character)
Definition text_ops.cc:97
@ KM_RELEASE
Definition WM_types.hh:325
unsigned int BLI_str_utf8_as_unicode_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int unsigned int size_t BLI_str_utf8_from_unicode_len(unsigned int c) ATTR_WARN_UNUSED_RESULT
static bool text_edit_poll(bContext *C)
Definition text_ops.cc:267
static wmOperatorStatus text_replace_set_selected_exec(bContext *C, wmOperator *)
Definition text_ops.cc:3987
static void text_cursor_set_to_pos(SpaceText *st, const ARegion *region, int x, int y, const bool sel)
Definition text_ops.cc:3244
double BLI_time_now_seconds()
Definition time.cc:30
void txt_jump_right(struct Text *text, bool sel, bool use_init_step)
Definition text.cc:985
int BLI_str_utf8_offset_to_index(const char *str, size_t str_len, int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static void text_cursor_timer_ensure(bContext *C, SetSelection *ssel)
Definition text_ops.cc:3302
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
void TEXT_OT_move(wmOperatorType *ot)
Definition text_ops.cc:2373
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:196
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
static void text_open_cancel(bContext *, wmOperator *op)
Definition text_ops.cc:412
void TEXT_OT_paste(wmOperatorType *ot)
Definition text_ops.cc:1012
std::string RNA_string_get(PointerRNA *ptr, const char *name)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
static void space_text_cursor_set_to_pos_wrapped(const SpaceText *st, const ARegion *region, int x, int y, const bool sel)
Definition text_ops.cc:3118
struct stat BLI_stat_t
void txt_delete_char(struct Text *text)
Definition text.cc:1771
static wmOperatorStatus text_jump_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition text_ops.cc:2449
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
Definition BLI_rect.hh:186
void txt_move_eol(struct Text *text, bool sel)
Definition text.cc:1031
void BKE_text_file_modified_ignore(struct Text *text)
Definition text.cc:563
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_FILEPATH
Definition RNA_types.hh:284
static bool text_region_scroll_poll(bContext *C)
Definition text_ops.cc:2948
static wmOperatorStatus text_selection_set_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:3403
static wmOperatorStatus text_copy_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1097
static wmOperatorStatus text_move_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:2366
static wmOperatorStatus text_jump_to_file_at_point_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:4117
static void text_select_update_primary_clipboard(const Text *text)
Definition text_ops.cc:228
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void txt_order_cursors(struct Text *text, bool reverse)
Definition text.cc:1187
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
void TEXT_OT_insert(wmOperatorType *ot)
Definition text_ops.cc:3746
static wmOperatorStatus text_convert_whitespace_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:1424
void TEXT_OT_reload(wmOperatorType *ot)
Definition text_ops.cc:585
static wmOperatorStatus text_save_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:762
static wmOperatorStatus text_duplicate_line_exec(bContext *C, wmOperator *)
Definition text_ops.cc:1042
void space_text_update_character_width(SpaceText *st)
static wmOperatorStatus text_save_as_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:806
ARegion * CTX_wm_region(const bContext *C)
void txt_backspace_word(struct Text *text)
Definition text.cc:1858
static wmOperatorStatus text_toggle_overwrite_exec(bContext *C, wmOperator *)
Definition text_ops.cc:2613
static wmOperatorStatus text_open_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition text_ops.cc:463
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, bool sel)
Definition text.cc:1104
static wmOperatorStatus text_paste_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:968
@ SCROLLHANDLE_INVALID_OUTSIDE
Definition text_ops.cc:2666
@ SCROLLHANDLE_BAR
Definition text_ops.cc:2667
@ SCROLLHANDLE_MIN_OUTSIDE
Definition text_ops.cc:2668
@ SCROLLHANDLE_MAX_OUTSIDE
Definition text_ops.cc:2669
static const EnumPropertyItem delete_type_items[]
Definition editfont.cc:1720
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
int BLI_str_utf8_offset_from_column_with_tabs(const char *str, size_t str_len, int column_target, int tab_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
Definition text_ops.cc:1941
void TEXT_OT_copy(wmOperatorType *ot)
Definition text_ops.cc:1106
bool txt_replace_char(struct Text *text, unsigned int add)
Definition text.cc:1940
static wmOperatorStatus text_run_script_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:934
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void TEXT_OT_run_script(wmOperatorType *ot)
Definition text_ops.cc:947
static wmOperatorStatus text_cursor_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition text_ops.cc:3463
static bool text_jump_to_file_at_point_external(bContext *C, ReportList *reports, const char *filepath, const int line_index, const int column_index)
Definition text_ops.cc:4021
bool bool bool bool BPY_run_string_as_string(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1
static wmOperatorStatus text_cursor_set_exec(bContext *C, wmOperator *op)
Definition text_ops.cc:3448
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
static void text_scroll_state_init(TextScroll *tsc, SpaceText *st, ARegion *region)
Definition text_ops.cc:2691
void TEXT_OT_save_as(wmOperatorType *ot)
Definition text_ops.cc:867
void BLI_str_cursor_step_bounds_utf8(const char *str, int str_maxlen, int pos, int *r_start, int *r_end)
void TEXT_OT_line_number(wmOperatorType *ot)
Definition text_ops.cc:3547
eRegion_Type regiontype
ListBaseT< Camera > cameras
Definition BKE_main.hh:397
ListBaseT< Text > texts
Definition BKE_main.hh:402
void(*) update_custom_camera(struct RenderEngine *engine, struct Camera *cam)
Definition RE_engine.h:126
void(*) update_script_node(struct RenderEngine *engine, struct bNodeTree *ntree, struct bNode *node)
Definition RE_engine.h:120
struct ReportList * reports
Definition RE_engine.h:154
eSpaceText_Flags flags
ed::text::SpaceText_Runtime * runtime
struct TextLine * prev
struct TextLine * next
struct blender::TextScroll::@246337252063272151263115240064276077065264016304 state
enum eScrollZone zone
Definition text_ops.cc:2679
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
wmEventType type
Definition WM_types.hh:817
wmEventModifierFlag modifier
Definition WM_types.hh:834
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
struct wmOperatorType * type
#define TXT_SCROLL_SPACE
#define TXT_LINE_HEIGHT(st)
#define TXT_NUMCOL_WIDTH(st)
#define TXT_BODY_LEFT(st)
#define TXT_BODY_LPAD