Merge branch 'textedit-line_start_end_handlers' of https://github.com/ocornut/stb into working
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents bd2cb59, 847d288 · Browse files · 1 file·+22 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+22 added−22 removed
- other:+22 added−22 removed
Provenance
- Commit
bee6e9f- Tree
68ffe38- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
bd2cb59- Parent 2
847d288
1 file changed+22 added−22 removed
modified:stb_textedit.h+22 added-22 removed
1004 unmodified lines1005 1006 #ifdef STB_TEXTEDIT_K_LINESTART21007 case STB_TEXTEDIT_K_LINESTART2:1008 #endif1009- case STB_TEXTEDIT_K_LINESTART: {1010- StbFindState find;1009+ case STB_TEXTEDIT_K_LINESTART:1010 stb_textedit_clamp(str, state);1011 stb_textedit_move_to_first(state);1013- stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);1014- state->cursor = find.first_char;1012+ if (state->single_line)1013+ state->cursor = 0;1014+ else while (state->cursor > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) != STB_TEXTEDIT_NEWLINE)1015+ --state->cursor;1016 state->has_preferred_x = 0;1017 break;1017- }1018 1019 #ifdef STB_TEXTEDIT_K_LINEEND21020 case STB_TEXTEDIT_K_LINEEND2:1021 #endif1022 case STB_TEXTEDIT_K_LINEEND: {1023- StbFindState find;1023+ int n = STB_TEXTEDIT_STRINGLEN(str);1024 stb_textedit_clamp(str, state);1025 stb_textedit_move_to_first(state);1026- stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);1027-1026+ if (state->single_line)1027+ state->cursor = n;1028+ else while (state->cursor < n && STB_TEXTEDIT_GETCHAR(str, state->cursor) != STB_TEXTEDIT_NEWLINE)1029+ ++state->cursor;1030 state->has_preferred_x = 0;1029- state->cursor = find.first_char + find.length;1030- if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)1031- --state->cursor;1031 break;1032 }1033 1034 #ifdef STB_TEXTEDIT_K_LINESTART21035 case STB_TEXTEDIT_K_LINESTART2 | STB_TEXTEDIT_K_SHIFT:1036 #endif1038- case STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_SHIFT: {1039- StbFindState find;1037+ case STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_SHIFT:1038 stb_textedit_clamp(str, state);1039 stb_textedit_prep_selection_at_cursor(state);1042- stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);1043- state->cursor = state->select_end = find.first_char;1040+ if (state->single_line)1041+ state->cursor = 0;1042+ else while (state->cursor > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) != STB_TEXTEDIT_NEWLINE)1043+ --state->cursor;1044+ state->select_end = state->cursor;1045 state->has_preferred_x = 0;1046 break;1046- }1047 1048 #ifdef STB_TEXTEDIT_K_LINEEND21049 case STB_TEXTEDIT_K_LINEEND2 | STB_TEXTEDIT_K_SHIFT:1050 #endif1051 case STB_TEXTEDIT_K_LINEEND | STB_TEXTEDIT_K_SHIFT: {1052- StbFindState find;1052+ int n = STB_TEXTEDIT_STRINGLEN(str);1053 stb_textedit_clamp(str, state);1054 stb_textedit_prep_selection_at_cursor(state);1055- stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);1056- state->has_preferred_x = 0;1057- state->cursor = find.first_char + find.length;1058- if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)1059- --state->cursor;1055+ if (state->single_line)1056+ state->cursor = n;1057+ else while (state->cursor < n && STB_TEXTEDIT_GETCHAR(str, state->cursor) != STB_TEXTEDIT_NEWLINE)1058+ ++state->cursor;1059 state->select_end = state->cursor;1060+ state->has_preferred_x = 0;1061 break;1062 }1063 1064 // @TODO:327 unmodified lines