40static bool text_insert(TextVars *
data,
const char *buf,
size_t buf_len);
99 !
data->runtime->lines.is_empty())
103 float2 co = runtime->
lines[cursor_pos.y].characters[cursor_pos.x].position;
123 cursor_offset = std::clamp(cursor_offset, 0, runtime->
character_count);
125 int2 cursor_position{0, 0};
128 cursor_position.x = cursor_offset;
132 cursor_position.y += 1;
135 cursor_position.y = std::clamp(cursor_position.y, 0,
int(runtime->
lines.size() - 1));
136 cursor_position.x = std::clamp(
137 cursor_position.x, 0,
int(runtime->
lines[cursor_position.y].characters.size() - 1));
139 return cursor_position;
143 const int2 cursor_pos)
145 return runtime->
lines[cursor_pos.y].characters[cursor_pos.x];
149 const int cursor_offset)
162 data->selection_start_offset = 0;
163 data->selection_end_offset = 0;
169 int sel_start_offset =
data->selection_start_offset;
170 int sel_end_offset =
data->selection_end_offset;
171 if (sel_start_offset > sel_end_offset) {
172 std::swap(sel_start_offset, sel_end_offset);
175 return IndexRange(sel_start_offset, sel_end_offset - sel_start_offset);
202 const int offset_start = char_start.
offset;
204 BLI_assert(offset_start >= 0 && offset_end <= data->text_len_bytes);
205 BLI_assert(offset_end >= 0 && offset_end <= data->text_len_bytes);
207 const int remaining =
data->text_len_bytes - offset_end;
209 std::memmove(
data->text_ptr + offset_start,
data->text_ptr + offset_end, remaining + 1);
210 data->text_len_bytes = offset_start + remaining;
236 data->selection_start_offset = 0;
237 data->selection_end_offset =
data->runtime->character_count;
245 ot->
name =
"Select All";
247 ot->
idname =
"SEQUENCER_OT_text_select_all";
277 ot->
name =
"Deselect All";
279 ot->
idname =
"SEQUENCER_OT_text_deselect_all";
302 const int offset_start = start.
offset;
304 BLI_assert(offset_start >= 0 && offset_start <= data->text_len_bytes);
305 BLI_assert(offset_end >= 0 && offset_end <= data->text_len_bytes);
308 const size_t len = offset_end - offset_start;
310 memcpy(buf,
data->text_ptr + offset_start,
len);
335 ot->
name =
"Copy Text";
337 ot->
idname =
"SEQUENCER_OT_text_edit_copy";
372 ot->
name =
"Cut Text";
374 ot->
idname =
"SEQUENCER_OT_text_edit_cut";
413 ot->
name =
"Paste Text";
415 ot->
idname =
"SEQUENCER_OT_text_edit_paste";
445 {
LINE_BEGIN,
"LINE_BEGIN", 0,
"Line Begin",
""},
446 {
LINE_END,
"LINE_END", 0,
"Line End",
""},
447 {
TEXT_BEGIN,
"TEXT_BEGIN", 0,
"Text Begin",
""},
448 {
TEXT_END,
"TEXT_END", 0,
"Text End",
""},
449 {
PREV_CHAR,
"PREVIOUS_CHARACTER", 0,
"Previous Character",
""},
450 {
NEXT_CHAR,
"NEXT_CHARACTER", 0,
"Next Character",
""},
451 {
PREV_WORD,
"PREVIOUS_WORD", 0,
"Previous Word",
""},
452 {
NEXT_WORD,
"NEXT_WORD", 0,
"Next Word",
""},
453 {
PREV_LINE,
"PREVIOUS_LINE", 0,
"Previous Line",
""},
454 {
NEXT_LINE,
"NEXT_LINE", 0,
"Next Line",
""},
455 {0,
nullptr, 0,
nullptr,
nullptr},
464 if (cursor_position.x + offset > cur_line.
characters.size() - 1 &&
465 cursor_position.y < runtime->
lines.size() - 1)
467 cursor_position.x = 0;
471 else if (cursor_position.x + offset < 0 && cursor_position.y > 0) {
473 cursor_position.x = runtime->
lines[cursor_position.y].characters.size() - 1;
476 cursor_position.x += offset;
477 const int position_max = runtime->
lines[cursor_position.y].characters.size() - 1;
478 cursor_position.x = std::clamp(cursor_position.x, 0, position_max);
480 return cursor_position;
488 const int cur_pos_x = cur_line.
characters[cursor_position.x].position.x;
490 const int line_max = runtime->
lines.size() - 1;
491 const int new_line_index = std::clamp(cursor_position.y + offset, 0, line_max);
494 if (cursor_position.y == new_line_index) {
495 return cursor_position;
499 int best_distance = std::numeric_limits<int>::max();
500 int best_character_index = 0;
502 for (
int i : new_line.
characters.index_range()) {
507 best_character_index = i;
511 cursor_position.x = best_character_index;
512 cursor_position.y = new_line_index;
513 return cursor_position;
519 cursor_position.x = cur_line.
characters.size() - 1;
520 return cursor_position;
525 return ELEM(chr1,
' ',
'\t',
'\n') && !
ELEM(chr2,
' ',
'\t',
'\n');
530 const char *text_ptr)
534 while (cursor_position.x > 0 || cursor_position.y > 0) {
542 cursor_position = prev_cursor_pos;
544 return cursor_position;
549 const char *text_ptr)
551 const int maxline = runtime->
lines.size() - 1;
552 const int maxchar = runtime->
lines.last().characters.size() - 1;
554 while ((cursor_position.x < maxchar) || (cursor_position.y < maxline)) {
563 return cursor_position;
573 data->selection_start_offset =
data->cursor_offset;
592 cursor_position.x = 0;
598 cursor_position = {0, 0};
601 cursor_position.y = runtime->
lines.size() - 1;
614 data->selection_end_offset =
data->cursor_offset;
618 data->cursor_offset ==
data->selection_start_offset)
630 ot->
name =
"Move Cursor";
632 ot->
idname =
"SEQUENCER_OT_text_cursor_move";
647 "Where to move cursor to, to make a selection");
650 ot->
srna,
"select_text",
false,
"Select Text",
"Select text while moving cursor");
662 {
DEL_NEXT_SEL,
"NEXT_OR_SELECTION", 0,
"Next or Selection",
""},
663 {
DEL_PREV_SEL,
"PREVIOUS_OR_SELECTION", 0,
"Previous or Selection",
""},
664 {0,
nullptr, 0,
nullptr,
nullptr},
669 const int offset_start = character.
offset;
671 BLI_assert(offset_start >= 0 && offset_start <= data->text_len_bytes);
672 BLI_assert(offset_end >= 0 && offset_end <= data->text_len_bytes);
673 const int remaining =
data->text_len_bytes - offset_end + 1;
674 std::memmove(
data->text_ptr + offset_start,
data->text_ptr + offset_end, remaining);
682 if (
const std::optional<wmOperatorStatus> status = WM_operator_IME_edit_maybe(
C)) {
706 if (
data->cursor_offset == 0) {
711 data->cursor_offset -= 1;
722 ot->
name =
"Delete Text";
723 ot->
description =
"Delete text at cursor position";
724 ot->
idname =
"SEQUENCER_OT_text_delete";
739 "Which part of the text to delete");
754 size_t needed_size =
data->text_len_bytes + buf_len + 1;
758 data->cursor_offset);
760 std::memcpy(new_text,
data->text_ptr, cur_char.
offset);
761 std::memcpy(new_text + cur_char.
offset, buf, buf_len);
762 std::memcpy(new_text + cur_char.
offset + buf_len,
765 data->text_len_bytes += buf_len;
766 MEM_delete(
data->text_ptr);
767 data->text_ptr = new_text;
784 if (in_buf_len == 0) {
801 if (
const std::optional<wmOperatorStatus> status = WM_operator_IME_insert_maybe(
802 C, op, event,
"string"))
817 ot->
name =
"Insert Text";
818 ot->
description =
"Insert text at cursor position";
819 ot->
idname =
"SEQUENCER_OT_text_insert";
831 ot->
srna,
"string",
nullptr, 512,
"String",
"String to be inserted at cursor position");
856 ot->
name =
"Insert Line Break";
857 ot->
description =
"Insert line break at cursor position";
858 ot->
idname =
"SEQUENCER_OT_text_line_break";
877 int best_cursor_offset = 0;
878 float best_distance = std::numeric_limits<float>::max();
885 best_cursor_offset = character.
index;
890 return best_cursor_offset;
910 mouse_loc -= view_offs;
921 bool make_selection =
false;
923 switch (event->
type) {
927 if (make_selection) {
928 data->selection_end_offset =
data->cursor_offset;
937 make_selection =
true;
939 data->selection_start_offset =
data->cursor_offset;
942 data->selection_end_offset =
data->cursor_offset;
983 ot->
name =
"Set Cursor";
985 ot->
idname =
"SEQUENCER_OT_text_cursor_set";
998 ot->
srna,
"select_text",
false,
"Select Text",
"Select text while moving cursor");
1025 ot->
name =
"Edit Text";
1027 ot->
idname =
"SEQUENCER_OT_text_edit_mode_toggle";
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr bool is_empty() const
constexpr IndexRange()=default
float distance(float, float) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
IndexRange strip_text_selection_range_get(const TextVars *data)
static void delete_character(const seq::CharInfo character, TextVars *data)
void SEQUENCER_OT_text_edit_copy(wmOperatorType *ot)
void SEQUENCER_OT_text_line_break(wmOperatorType *ot)
static void text_runtime_update(TextVars &text)
static void cursor_set_by_mouse_position(const bContext *C, const wmEvent *event)
static wmOperatorStatus sequencer_text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void SEQUENCER_OT_text_delete(wmOperatorType *ot)
void SEQUENCER_OT_text_edit_cut(wmOperatorType *ot)
static const EnumPropertyItem move_type_items[]
bool sequencer_text_editing_active_poll(bContext *C)
static wmOperatorStatus sequencer_text_edit_mode_toggle_exec(bContext *C, wmOperator *)
static int2 cursor_move_by_line(int2 cursor_position, const seq::TextVarsRuntime *runtime, int offset)
static const EnumPropertyItem delete_type_items[]
static wmOperatorStatus sequencer_text_edit_paste_exec(bContext *C, wmOperator *)
void SEQUENCER_OT_text_insert(wmOperatorType *ot)
static int cursor_position_to_offset(const seq::TextVarsRuntime *runtime, int2 cursor_position)
void SEQUENCER_OT_text_deselect_all(wmOperatorType *ot)
bool sequencer_editing_initialized_and_active(bContext *C)
static const seq::CharInfo & character_at_cursor_pos_get(const seq::TextVarsRuntime *runtime, const int2 cursor_pos)
static wmOperatorStatus sequencer_text_edit_copy_exec(bContext *C, wmOperator *)
int2 strip_text_cursor_offset_to_position(const seq::TextVarsRuntime *runtime, int cursor_offset)
static void text_editing_update(const bContext *C)
static const seq::CharInfo & character_at_cursor_offset_get(const seq::TextVarsRuntime *runtime, const int cursor_offset)
void SEQUENCER_OT_text_select_all(wmOperatorType *ot)
static wmOperatorStatus sequencer_text_deselect_all_exec(bContext *C, wmOperator *)
static bool text_insert(TextVars *data, const char *buf, size_t buf_len)
static bool sequencer_text_editing_poll(bContext *C)
static wmOperatorStatus sequencer_text_cursor_move_exec(bContext *C, wmOperator *op)
static wmOperatorStatus sequencer_text_cursor_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus sequencer_text_delete_exec(bContext *C, wmOperator *op)
static int2 cursor_move_by_character(int2 cursor_position, const seq::TextVarsRuntime *runtime, int offset)
static void text_selection_cancel(TextVars *data)
static bool is_whitespace_transition(char chr1, char chr2)
static wmOperatorStatus sequencer_text_insert_exec(bContext *C, wmOperator *op)
void SEQUENCER_OT_text_edit_paste(wmOperatorType *ot)
static void delete_selected_text(TextVars *data)
static int2 cursor_move_next_word(int2 cursor_position, const seq::TextVarsRuntime *runtime, const char *text_ptr)
static int2 cursor_move_line_end(int2 cursor_position, const seq::TextVarsRuntime *runtime)
bool strip_point_image_isect(const Scene *scene, const Strip *strip, float point_view[2])
static bool text_has_selection(const TextVars *data)
void SEQUENCER_OT_text_cursor_move(wmOperatorType *ot)
static int find_closest_cursor_offset(const TextVars *data, float2 mouse_loc)
static wmOperatorStatus sequencer_text_edit_cut_exec(bContext *C, wmOperator *)
static int2 cursor_move_prev_word(int2 cursor_position, const seq::TextVarsRuntime *runtime, const char *text_ptr)
static wmOperatorStatus sequencer_text_select_all_exec(bContext *C, wmOperator *)
const Strip * sequencer_text_editing_cursor_strip_get(const Scene *scene)
static wmOperatorStatus sequencer_text_line_break_exec(bContext *C, wmOperator *)
std::optional< int2 > sequencer_text_editing_cursor_region_xy_get(const Scene *scene, const ARegion *region, const Strip *strip)
void SEQUENCER_OT_text_cursor_set(wmOperatorType *ot)
static void text_edit_copy(TextVars *data)
void SEQUENCER_OT_text_edit_mode_toggle(wmOperatorType *ot)
static wmOperatorStatus sequencer_text_cursor_set_modal(bContext *C, wmOperator *, const wmEvent *event)
T distance(const T &a, const T &b)
CartesianBasis invert(const CartesianBasis &basis)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
std::recursive_mutex & text_runtime_mutex_get()
void relations_invalidate_cache_raw(Scene *scene, Strip *strip)
void text_effect_update_runtime(const RenderData *context, TextVars &text, const int2 image_size)
float3x3 image_transform_matrix_get(const Scene *scene, const Strip *strip)
Strip * select_active_get(const Scene *scene)
bool effects_can_render_text(const Strip *strip)
void view2d_view_to_region(const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
View2D * view2d_fromcontext(const bContext *C)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
Scene * CTX_data_sequencer_scene(const bContext *C)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
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 BLF_disable(int fontid, FontFlags flag)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
float BKE_scene_frame_get(const Scene *scene)
BMesh const char void * data
wmWindowManager * CTX_wm_manager(const bContext *C)
@ SEQ_FLAG_TEXT_EDITING_ACTIVE
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
MatBase< float, 3, 3 > float3x3
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
bScreen * ED_screen_animation_no_scrub(const wmWindowManager *wm)
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
void WM_clipboard_text_set(const char *buf, bool selection)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
ARegion * CTX_wm_region(const bContext *C)
Vector< CharInfo > characters
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT