Переглянути джерело

InputText: Fixed minor inconsistency when pressing Down on the last line when it doesn't have a carriage return (it used to move to the end of the line)

+ fixed two of our typos in stb_textedit.h
Louis Schnellbach 4 роки тому
батько
коміт
fbf70070bb
2 змінених файлів з 11 додано та 3 видалено
  1. 3 1
      docs/CHANGELOG.txt
  2. 8 2
      imstb_textedit.h

+ 3 - 1
docs/CHANGELOG.txt

@@ -50,7 +50,9 @@ Other Changes:
   It is a rather unusual or useless combination of features but no reason it shouldn't work!
 - InputText: Fixed minor scrolling glitch when erasing trailing lines in InputTextMultiline().
 - InputText: Fixed cursor being partially covered after using Ctrl+End key.
-- InputText: Fixed callback's helper DeleteChars() function when cursor is inside the deleted block. (#3454).
+- InputText: Fixed callback's helper DeleteChars() function when cursor is inside the deleted block. (#3454)
+- InputText: Fixed minor inconsistency when pressing Down on the last line when it doesn't have a carriage 
+  return (it used to move to the end of the line). [@Xipiryon]
 - DragFloat, DragScalar: Fixed ImGuiSliderFlags_ClampOnInput not being honored in the special case
   where v_min == v_max. (#3361)
 - SliderInt, SliderScalar: Fixed reaching of maximum value with inverted integer min/max ranges, both

+ 8 - 2
imstb_textedit.h

@@ -177,7 +177,7 @@
 // Keyboard input must be encoded as a single integer value; e.g. a character code
 // and some bitflags that represent shift states. to simplify the interface, SHIFT must
 // be a bitflag, so we can test the shifted state of cursor movements to allow selection,
-// i.e. (STB_TEXTED_K_RIGHT|STB_TEXTEDIT_K_SHIFT) should be shifted right-arrow.
+// i.e. (STB_TEXTEDIT_K_RIGHT|STB_TEXTEDIT_K_SHIFT) should be shifted right-arrow.
 //
 // You can encode other things, such as CONTROL or ALT, in additional bits, and
 // then test for their presence in e.g. STB_TEXTEDIT_K_WORDLEFT. For example,
@@ -877,6 +877,12 @@ retry:
 
          // now find character position down a row
          if (find.length) {
+
+            // [DEAR IMGUI]
+            // going down while being on the last line shouldn't bring us to that line end
+            if (STB_TEXTEDIT_GETCHAR(str, find.first_char + find.length - 1) != STB_TEXTEDIT_NEWLINE)
+               break;
+
             float goal_x = state->has_preferred_x ? state->preferred_x : find.x;
             float x;
             int start = find.first_char + find.length;
@@ -1134,7 +1140,7 @@ static void stb_textedit_discard_redo(StbUndoState *state)
                state->undo_rec[i].char_storage += n;
       }
       // now move all the redo records towards the end of the buffer; the first one is at 'redo_point'
-      // {DEAR IMGUI]
+      // [DEAR IMGUI]
       size_t move_size = (size_t)((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point - 1) * sizeof(state->undo_rec[0]));
       const char* buf_begin = (char*)state->undo_rec; (void)buf_begin;
       const char* buf_end   = (char*)state->undo_rec + sizeof(state->undo_rec); (void)buf_end;