Skip to content
Myr

Merge branch '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 50ec402, bde8f7c · Browse files · 1 file+41 added−30 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+41 added−30 removed

  • other:+41 added−30 removed

1 file+41 added−30 removed

modified:stb_textedit.h+41 added-30 removed
146 unmodified lines
147// STB_TEXTEDIT_K_UNDO keyboard input to perform undo148// STB_TEXTEDIT_K_REDO keyboard input to perform redo149//150// Optional:151// STB_TEXTEDIT_K_INSERT keyboard input to toggle insert mode152// STB_TEXTEDIT_IS_SPACE(ch) true if character is whitespace (e.g. 'isspace'),153// required for WORDLEFT/WORDRIGHT154// STB_TEXTEDIT_K_WORDLEFT keyboard input to move cursor left one word // e.g. ctrl-LEFT155// STB_TEXTEDIT_K_WORDRIGHT keyboard input to move cursor right one word // e.g. ctrl-RIGHT156// STB_TEXTEDIT_K_LINESTART2 secondary keyboard input to move cursor to start of line157// STB_TEXTEDIT_K_LINEEND2 secondary keyboard input to move cursor to end of line158// STB_TEXTEDIT_K_TEXTSTART2 secondary keyboard input to move cursor to start of text159// STB_TEXTEDIT_K_TEXTEND2 secondary keyboard input to move cursor to end of text151// STB_TEXTEDIT_K_INSERT keyboard input to toggle insert mode152// STB_TEXTEDIT_IS_SPACE(ch) true if character is whitespace (e.g. 'isspace'),153// required for default WORDLEFT/WORDRIGHT handlers154// STB_TEXTEDIT_MOVEWORDLEFT(obj,i) custom handler for WORDLEFT, returns index to move cursor to155// STB_TEXTEDIT_MOVEWORDRIGHT(obj,i) custom handler for WORDRIGHT, returns index to move cursor to156// STB_TEXTEDIT_K_WORDLEFT keyboard input to move cursor left one word // e.g. ctrl-LEFT157// STB_TEXTEDIT_K_WORDRIGHT keyboard input to move cursor right one word // e.g. ctrl-RIGHT158// STB_TEXTEDIT_K_LINESTART2 secondary keyboard input to move cursor to start of line159// STB_TEXTEDIT_K_LINEEND2 secondary keyboard input to move cursor to end of line160// STB_TEXTEDIT_K_TEXTSTART2 secondary keyboard input to move cursor to start of text161// STB_TEXTEDIT_K_TEXTEND2 secondary keyboard input to move cursor to end of text162//163// Todo:164// STB_TEXTEDIT_K_PGUP keyboard input to move cursor up a page165// STB_TEXTEDIT_K_PGDOWN keyboard input to move cursor down a page
444 unmodified lines
610 }611}612613#ifdef STB_TEXTEDIT_IS_SPACE612static int is_word_boundary( STB_TEXTEDIT_STRING *_str, int _idx )614static int is_word_boundary( STB_TEXTEDIT_STRING *str, int idx )615{614 return _idx > 0 ? (STB_TEXTEDIT_IS_SPACE( STB_TEXTEDIT_GETCHAR(_str,_idx-1) ) && !STB_TEXTEDIT_IS_SPACE( STB_TEXTEDIT_GETCHAR(_str, _idx) ) ) : 1;616 return idx > 0 ? (STB_TEXTEDIT_IS_SPACE( STB_TEXTEDIT_GETCHAR(str,idx-1) ) && !STB_TEXTEDIT_IS_SPACE( STB_TEXTEDIT_GETCHAR(str, idx) ) ) : 1;617}618619#ifndef STB_TEXTEDIT_MOVEWORDLEFT617static int stb_textedit_move_to_word_previous( STB_TEXTEDIT_STRING *_str, STB_TexteditState *_state )620static int stb_textedit_move_to_word_previous( STB_TEXTEDIT_STRING *str, int c )621{619 int c = _state->cursor - 1;620 while( c >= 0 && !is_word_boundary( _str, c ) )622 --c; // always move at least one character623 while( c >= 0 && !is_word_boundary( str, c ) )624 --c;625626 if( c < 0 )627 c = 0;628629 return c;630}631#define STB_TEXTEDIT_MOVEWORDLEFT stb_textedit_move_to_word_previous632#endif633634#ifndef STB_TEXTEDIT_MOVEWORDRIGHT629static int stb_textedit_move_to_word_next( STB_TEXTEDIT_STRING *_str, STB_TexteditState *_state )635static int stb_textedit_move_to_word_next( STB_TEXTEDIT_STRING *str, int c )636{637 const int len = STB_TEXTEDIT_STRINGLEN(_str);632 int c = _state->cursor+1;633 while( c < len && !is_word_boundary( _str, c ) )638 ++c; // always move at least one character639 while( c < len && !is_word_boundary( str, c ) )640 ++c;641642 if( c > len )643 c = len;644645 return c;646}647#define STB_TEXTEDIT_MOVEWORDRIGHT stb_textedit_move_to_word_next648#endif649650#endif651652// update selection and cursor to match each other653static void stb_textedit_prep_selection_at_cursor(STB_TexteditState *state)654{655 if (!STB_TEXT_HAS_SELECTION(state))
111 unmodified lines
767 state->cursor = state->select_end;768 state->has_preferred_x = 0;769 break;770762#ifdef STB_TEXTEDIT_IS_SPACE771#ifdef STB_TEXTEDIT_MOVEWORDLEFT772 case STB_TEXTEDIT_K_WORDLEFT:773 if (STB_TEXT_HAS_SELECTION(state))774 stb_textedit_move_to_first(state);775 else {767 state->cursor = stb_textedit_move_to_word_previous(str, state);776 state->cursor = STB_TEXTEDIT_MOVEWORDLEFT(str, state->cursor);777 stb_textedit_clamp( str, state );778 }779 break;780772 case STB_TEXTEDIT_K_WORDRIGHT:773 if (STB_TEXT_HAS_SELECTION(state)) 774 stb_textedit_move_to_last(str, state);775 else {776 state->cursor = stb_textedit_move_to_word_next(str, state);777 stb_textedit_clamp( str, state );778 }779 break;780781 case STB_TEXTEDIT_K_WORDLEFT | STB_TEXTEDIT_K_SHIFT:782 if( !STB_TEXT_HAS_SELECTION( state ) )783 stb_textedit_prep_selection_at_cursor(state);784785 state->cursor = stb_textedit_move_to_word_previous(str, state);785 state->cursor = STB_TEXTEDIT_MOVEWORDLEFT(str, state->cursor);786 state->select_end = state->cursor;787788 stb_textedit_clamp( str, state );789 break;790#endif791792#ifdef STB_TEXTEDIT_MOVEWORDRIGHT793 case STB_TEXTEDIT_K_WORDRIGHT:794 if (STB_TEXT_HAS_SELECTION(state)) 795 stb_textedit_move_to_last(str, state);796 else {797 state->cursor = STB_TEXTEDIT_MOVEWORDRIGHT(str, state->cursor);798 stb_textedit_clamp( str, state );799 }800 break;801802 case STB_TEXTEDIT_K_WORDRIGHT | STB_TEXTEDIT_K_SHIFT:803 if( !STB_TEXT_HAS_SELECTION( state ) )804 stb_textedit_prep_selection_at_cursor(state);805795 state->cursor = stb_textedit_move_to_word_next(str, state);806 state->cursor = STB_TEXTEDIT_MOVEWORDRIGHT(str, state->cursor);807 state->select_end = state->cursor;808809 stb_textedit_clamp( str, state );810 break;
504 unmodified lines