Skip to content
Myr

stb_textedit: fix LINESTART when cursor is at end of buffer and no trailing newline. Stopped using find_charpos(), simpler and faster.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ocornut · committed by ocornut · parent dca0a37 · 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

1 file+22 added−22 removed

modified:stb_textedit.h+22 added-22 removed
985 unmodified lines
986987#ifdef STB_TEXTEDIT_K_LINESTART2988 case STB_TEXTEDIT_K_LINESTART2:989#endif990 case STB_TEXTEDIT_K_LINESTART: {991 StbFindState find;990 case STB_TEXTEDIT_K_LINESTART:991 stb_textedit_clamp(str, state);992 stb_textedit_move_to_first(state);994 stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);995 state->cursor = find.first_char;993 if (state->single_line)994 state->cursor = 0;995 else while (state->cursor > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) != STB_TEXTEDIT_NEWLINE)996 --state->cursor;997 state->has_preferred_x = 0;998 break;998 }9991000#ifdef STB_TEXTEDIT_K_LINEEND21001 case STB_TEXTEDIT_K_LINEEND2:1002#endif1003 case STB_TEXTEDIT_K_LINEEND: {1004 StbFindState find;1004 int n = STB_TEXTEDIT_STRINGLEN(str);1005 stb_textedit_clamp(str, state);1006 stb_textedit_move_to_first(state);1007 stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);10081007 if (state->single_line)1008 state->cursor = n;1009 else while (state->cursor < n && STB_TEXTEDIT_GETCHAR(str, state->cursor) != STB_TEXTEDIT_NEWLINE)1010 ++state->cursor;1011 state->has_preferred_x = 0;1010 state->cursor = find.first_char + find.length;1011 if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)1012 --state->cursor;1012 break;1013 }10141015#ifdef STB_TEXTEDIT_K_LINESTART21016 case STB_TEXTEDIT_K_LINESTART2 | STB_TEXTEDIT_K_SHIFT:1017#endif1019 case STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_SHIFT: {1020 StbFindState find;1018 case STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_SHIFT:1019 stb_textedit_clamp(str, state);1020 stb_textedit_prep_selection_at_cursor(state);1023 stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);1024 state->cursor = state->select_end = find.first_char;1021 if (state->single_line)1022 state->cursor = 0;1023 else while (state->cursor > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) != STB_TEXTEDIT_NEWLINE)1024 --state->cursor;1025 state->select_end = state->cursor;1026 state->has_preferred_x = 0;1027 break;1027 }10281029#ifdef STB_TEXTEDIT_K_LINEEND21030 case STB_TEXTEDIT_K_LINEEND2 | STB_TEXTEDIT_K_SHIFT:1031#endif1032 case STB_TEXTEDIT_K_LINEEND | STB_TEXTEDIT_K_SHIFT: {1033 StbFindState find;1033 int n = STB_TEXTEDIT_STRINGLEN(str);1034 stb_textedit_clamp(str, state);1035 stb_textedit_prep_selection_at_cursor(state);1036 stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);1037 state->has_preferred_x = 0;1038 state->cursor = find.first_char + find.length;1039 if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)1040 --state->cursor;1036 if (state->single_line)1037 state->cursor = n;1038 else while (state->cursor < n && STB_TEXTEDIT_GETCHAR(str, state->cursor) != STB_TEXTEDIT_NEWLINE)1039 ++state->cursor;1040 state->select_end = state->cursor;1041 state->has_preferred_x = 0;1042 break;1043 }10441045// @TODO:
270 unmodified lines