diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index 8c975327..3e06e8e7 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -160,11 +160,12 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla //- rjf: invalid single-line op or endpoint units => try multiline if(evt->delta_unit == UI_EventDeltaUnit_Whole || single_line_op.flags & UI_TxtOpFlag_Invalid) { + U64 start_cursor = *cursor; U64 line_count = text_patched.line_map.total_line_count; Vec2S32 delta = evt->delta_2s32; //- rjf: wrap lines right - if(evt->delta_unit != UI_EventDeltaUnit_Whole && delta.x > 0 && *cursor == line_range.max+1 && line_num+1 <= line_count) + if(evt->delta_unit != UI_EventDeltaUnit_Whole && delta.x > 0 && *cursor == line_range.max && line_num+1 <= line_count) { Rng1U64 next_line_range = txt_range_from_line_num(&text_patched.line_map, line_num+1); *cursor = next_line_range.min; @@ -280,7 +281,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla //- rjf: movement to endpoint (+) if(evt->delta_unit == UI_EventDeltaUnit_Whole && (delta.y > 0 || delta.x > 0)) { - *cursor = txt_range_from_line_num(&text_patched.line_map, text_patched.line_map.total_line_count).max; + *cursor = text_patched.size; change = 1; taken = 1; } @@ -298,6 +299,15 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla { *mark = *cursor; } + + //- rjf: push patch if we have one + if(evt->flags & UI_EventFlag_Delete) + { + Rng1U64 range = r1u64(start_cursor, *cursor); + txt_patch_list_push_new(cv->patch_arena, &cv->patches, range, single_line_op.replace); + text_patched = txt_patched_from_info_data_patches(scratch.arena, text_info, text_data, &cv->patches); + *cursor = *mark = range.min; + } } //- rjf: valid single-line op => do single-line op diff --git a/src/text/text.c b/src/text/text.c index 896fe3c5..708f4e78 100644 --- a/src/text/text.c +++ b/src/text/text.c @@ -2505,13 +2505,13 @@ txt_patched_from_info_data_patches(Arena *arena, TXT_TextInfo *info, String8 dat affected_line_range.min = og_line_range.min; } - // rjf: the last line in the range -> take max from original line map, shift - if(affected_line_idx == affected_line_count-1) + // rjf: the last line in the range -> take remaining suffix from original line map + if(affected_line_idx == affected_line_count-1 && affected_line_idx >= ClampBot(0, line_delta)) { - Rng1U64 og_line_range = txt_range_from_line_num(&last_line_map, replace_line_num_range.min + affected_line_idx); - if(dim_1u64(og_line_range) != 0) + Rng1U64 og_line_range = txt_range_from_line_num(&last_line_map, replace_line_num_range.max); + if(og_line_range.max > n->v.range.max) { - affected_line_range.max += dim_1u64(og_line_range); + affected_line_range.max += og_line_range.max - n->v.range.max; } } diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 77642562..684850fc 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -191,8 +191,19 @@ ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, } //- rjf: form next cursor + B32 cursor_out_of_bounds = 0; if(cursor == mark || !(event->flags & UI_EventFlag_ZeroDeltaOnSelect)) { + if(delta.x < -(S32)next_cursor) + { + delta.x = -(S32)next_cursor; + cursor_out_of_bounds = 1; + } + if(cursor + delta.x > string.size) + { + delta.x = (S32)((S64)string.size - (S64)cursor); + cursor_out_of_bounds = 1; + } next_cursor += delta.x; } @@ -255,7 +266,7 @@ ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, //- rjf: determine if this event should be taken, based on bounds of cursor { - if(next_cursor > string.size+replace.size || event->delta_2s32.y != 0) + if(next_cursor > string.size+replace.size || event->delta_2s32.y != 0 || cursor_out_of_bounds) { flags |= UI_TxtOpFlag_Invalid; }