Răsfoiți Sursa

InputText: stb_textedit.h tentative fix for End key on multi-line fields (#275)

ocornut 10 ani în urmă
părinte
comite
f7f71043ca
1 a modificat fișierele cu 7 adăugiri și 0 ștergeri
  1. 7 0
      stb_textedit.h

+ 7 - 0
stb_textedit.h

@@ -1,3 +1,6 @@
+// [ImGui] this is a slightly modified version of stb_truetype.h 1.4
+// [ImGui] we made a fix for using the END key on multi-line text edit, see https://github.com/ocornut/imgui/issues/275
+
 // stb_textedit.h - v1.4  - public domain - Sean Barrett
 // Development of this library was sponsored by RAD Game Tools
 //
@@ -957,6 +960,8 @@ retry:
          stb_textedit_move_to_first(state);
          stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);
          state->cursor = find.first_char + find.length;
+         if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)
+            state->cursor--;
          state->has_preferred_x = 0;
          break;
       }
@@ -977,6 +982,8 @@ retry:
          stb_textedit_prep_selection_at_cursor(state);
          stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);
          state->cursor = state->select_end = find.first_char + find.length;
+         if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)
+            state->cursor = state->select_end = state->cursor - 1;
          state->has_preferred_x = 0;
          break;
       }