Small textbox fixes

Lose focus on mouse click outside
Update selection while dragging outside the box
Stop trying to flip the selection on drag, keep shift+click
This commit is contained in:
Ilia Demianenko 2023-08-15 18:37:08 -07:00 committed by Martin Fouilleul
parent e0db03b51c
commit 40887a9a2d
1 changed files with 53 additions and 51 deletions

View File

@ -2663,10 +2663,6 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8
oc_ui_sig sig = oc_ui_box_sig(frame);
if(sig.hovering)
{
oc_ui_box_set_hot(frame, true);
if(sig.pressed)
{
if(!oc_ui_box_active(frame))
@ -2703,7 +2699,7 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8
}
//NOTE: put cursor the closest to new cursor (this maximizes the resulting selection,
// and seems to be the standard behaviour across a number of text editor)
if(abs(newCursor - ui->editCursor) > abs(newCursor - ui->editMark))
if(sig.pressed && abs(newCursor - ui->editCursor) > abs(newCursor - ui->editMark))
{
i32 tmp = ui->editCursor;
ui->editCursor = ui->editMark;
@ -2716,12 +2712,18 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8
ui->editMark = ui->editCursor;
}
}
if(sig.hovering)
{
oc_ui_box_set_hot(frame, true);
}
else
{
oc_ui_box_set_hot(frame, false);
if(sig.pressed)
if(oc_mouse_pressed(&ui->input, OC_MOUSE_LEFT) ||
oc_mouse_pressed(&ui->input, OC_MOUSE_RIGHT) ||
oc_mouse_pressed(&ui->input, OC_MOUSE_MIDDLE))
{
if(oc_ui_box_active(frame))
{