deleting with backspace and moving with ctrl + left/right

This commit is contained in:
Vicente Ferrari Smith 2025-08-06 21:37:44 +02:00
parent 4744f67e2e
commit 0f5d7d6125
13 changed files with 74 additions and 16 deletions

View File

@ -6,7 +6,7 @@
NAME :: "mexplore";
VERSION :: "0.1";
JAI_VERSION :: "beta 0.2.016, built on 19 July 2025";
RELEASE_DATE :: "3 August 2025, 09:51:04";
RELEASE_DATE :: "6 August 2025, 21:33:37";
GIT_BRANCH :: "main";
GIT_REVISION :: "e4df2e155175ce56f09148738c333da44455ce7a";
GIT_REVISION :: "4744f67e2e182828d1a3de921c4a5b6194a2a24d";
DEBUG :: true;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -86,10 +86,44 @@ main :: () {
running = false;
case SDL_EVENT_KEY_DOWN;
log("%", event.key);
if event.key.key == {
case SDLK_ESCAPE;
running = false;
case SDLK_LEFT;
transition.left_arrow_down = true;
if event.key.mod == SDL_KMOD_LCTRL {
log("Moving word to the left!");
transition.char = STB_TEXTEDIT_K_WORDLEFT;
} else {
log("Moving to the left");
transition.char = STB_TEXTEDIT_K_LEFT;
}
case SDLK_RIGHT;
transition.right_arrow_down = true;
if event.key.mod == SDL_KMOD_LCTRL {
log("Moving word to the right!");
transition.char = STB_TEXTEDIT_K_WORDRIGHT;
} else {
log("Moving to the right");
transition.char = STB_TEXTEDIT_K_RIGHT;
}
case SDLK_BACKSPACE;
transition.backspace = true;
if event.key.mod == SDL_KMOD_LCTRL {
// log("Moving word to the right!");
// transition.char = STB_TEXTEDIT_K_WORDRIGHT;
} else {
transition.char = STB_TEXTEDIT_K_BACKSPACE;
}
case SDLK_LSHIFT;
transition.shift_down = true;
case SDLK_LCTRL;
transition.control_down = true;
case SDLK_RETURN;
transition.char = STB_TEXTEDIT_NEWLINE;

View File

@ -14,6 +14,12 @@ InputTransition :: struct {
shift_down : bool;
shift_up : bool;
left_arrow_down : bool;
right_arrow_down : bool;
backspace : bool;
char : s32;
}

View File

@ -290,6 +290,7 @@ STB_TEXTEDIT_DELETECHARS :: (obj: *STB_TEXTEDIT_STRING, i: s32, n: s32) {
if (i >= obj.text.count) return; // Nothing to remove
if (i + n > obj.text.count) n = xx obj.text.count - i; // Trim n if it goes past end
memcpy(*obj.text.data[i], *obj.text.data[i + n], obj.text.count - i - n);
array_resize(*obj.text, obj.text.count - n, false);
}
STB_TEXTEDIT_GETCHAR :: (obj: *STB_TEXTEDIT_STRING, i: s32) -> STB_TEXTEDIT_CHARTYPE {
@ -305,14 +306,15 @@ STB_TEXTEDIT_INSERTCHARS :: (obj: *STB_TEXTEDIT_STRING, i: s32, c: *STB_TEXTEDIT
len := obj.text.count;
if n + len > obj.text.allocated {
if n + len > obj.text.count {
array_resize(*obj.text, n + len);
}
// Shift the tail of the string right by n characters
if i != len
memcpy(obj.text.data + ((i + n) * size_of(STB_TEXTEDIT_CHARTYPE)), obj.text.data + (i * size_of(STB_TEXTEDIT_CHARTYPE)), (len - i) * size_of(STB_TEXTEDIT_CHARTYPE));
//memcpy(obj.text.data + ((i + n) * size_of(STB_TEXTEDIT_CHARTYPE)), obj.text.data + (i * size_of(STB_TEXTEDIT_CHARTYPE)), (len - i) * size_of(STB_TEXTEDIT_CHARTYPE));
memcpy(obj.text.data + ((i + n)), obj.text.data + (i), (len - i) * size_of(STB_TEXTEDIT_CHARTYPE));
//memcpy(obj.text.data + (i * size_of(STB_TEXTEDIT_CHARTYPE)), c, n * size_of(STB_TEXTEDIT_CHARTYPE));
memcpy(obj.text.data + (i), c, n * size_of(STB_TEXTEDIT_CHARTYPE));
@ -899,7 +901,6 @@ while retry := true {
}
}
}
break retry;
// #if #exists(STB_TEXTEDIT_K_INSERT) {
// case STB_TEXTEDIT_K_INSERT;
@ -1244,6 +1245,7 @@ while retry := true {
state.select_end = state.cursor;
state.has_preferred_x = 0;
}
break retry;
}
}

View File

@ -1332,10 +1332,14 @@ ui_action :: (rect : *Rect) -> UIAction {
for transition : input_transitions {
if rect.type == {
case .TEXTINPUT;
text_input := cast(*TextInput, rect);
if text_input.active && transition.char > 0 {
stb_textedit_key(text_input, *text_input.textedit_state, transition.char);
}
text_input := cast(*TextInput, rect);
if text_input.active {
if transition.char > 0 {
stb_textedit_key(text_input, *text_input.textedit_state, transition.char);
text_input.cursor_time = 0.0;
}
}
}
}

24
ui.rad
View File

@ -1,21 +1,33 @@
// raddbg 0.9.20 project file
recent_file: path: "src/main.jai"
recent_file: path: "src/ui.jai"
recent_file: path: "../../../../jai/modules/math/module.jai"
recent_file: path: "../../../../jai/modules/basic/array.jai"
recent_file: path: "src/text.jai"
recent_file: path: "src/stb_textedit.jai"
recent_file: path: "../../../../jai/modules/basic/array.jai"
recent_file: path: "../../../../jai/modules/default_allocator/module.jai"
recent_file: path: "src/ui.jai"
recent_file: path: "src/main.jai"
recent_file: path: "../../../../jai/modules/math/module.jai"
recent_file: path: "src/text.jai"
recent_file: path: "modules/kb_text_shape/kb_text_shape.h"
recent_file: path: "modules/SDL3/src/SDL-release-3.2.16/src/events/sdl_keyboard.c"
recent_file: path: "modules/SDL3/src/SDL-release-3.2.16/src/video/windows/SDL_windowsevents.c"
recent_file: path: "src/math/math.jai"
recent_file: path: "../../../../jai/modules/runtime_support.jai"
recent_file: path: "../../../../jai/modules/basic/module.jai"
recent_file: path: "../../../../jai/modules/default_allocator/module.jai"
target:
{
executable: "bin/mexplore-debug.exe"
working_directory: bin
enabled: 1
}
breakpoint:
{
source_location: "src/stb_textedit.jai:1140:1"
hit_count: 0
enabled: 0
}
breakpoint:
{
source_location: "src/stb_textedit.jai:305:1"
hit_count: 0
enabled: 0
}