Browse Source

InputText: fixed cursor positioning issue using up/down keys on non-ASCII text. (#8635, #7925)

Bug introduced in abd07f6d30736c00fba899d41043a78a5de0f765.
Ref https://github.com/nothings/stb/issues/188
ocornut 4 tháng trước cách đây
mục cha
commit
61242e2e6a
3 tập tin đã thay đổi với 11 bổ sung5 xóa
  1. 2 0
      docs/CHANGELOG.txt
  2. 1 1
      imgui.h
  3. 8 4
      imstb_textedit.h

+ 2 - 0
docs/CHANGELOG.txt

@@ -76,6 +76,8 @@ Other changes:
     - The feature is unlikely to ever work properly when using a coarse clipper
       such as ImGuiListClipper.
 - TreeNode: fixed incorrect clipping of arrow/bullet when using ImGuiTreeNodeFlags_SpanAllColumns.
+- InputText: fixed cursor positioning issue using up/down keys near end of lines while
+  editing non-ASCII text. (Regression from 1.91.2) (#8635, #7925)
 - Tables: fixed TableHeader() eager vertical clipping of text which may be noticeable
   with FramePadding.y was too small. (#6236)
 - Tables: fixed an assert when combining Tables, Frozen Rows, Clipper and BeginMultiSelect()

+ 1 - 1
imgui.h

@@ -29,7 +29,7 @@
 // Library Version
 // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
 #define IMGUI_VERSION       "1.92.0 WIP"
-#define IMGUI_VERSION_NUM   19194
+#define IMGUI_VERSION_NUM   19195
 #define IMGUI_HAS_TABLE
 
 /*

+ 8 - 4
imstb_textedit.h

@@ -918,7 +918,7 @@ retry:
             state->cursor = start;
             STB_TEXTEDIT_LAYOUTROW(&row, str, state->cursor);
             x = row.x0;
-            for (i=0; i < row.num_chars; ++i) {
+            for (i=0; i < row.num_chars; ) {
                float dx = STB_TEXTEDIT_GETWIDTH(str, start, i);
                #ifdef IMSTB_TEXTEDIT_GETWIDTH_NEWLINE
                if (dx == IMSTB_TEXTEDIT_GETWIDTH_NEWLINE)
@@ -927,7 +927,9 @@ retry:
                x += dx;
                if (x > goal_x)
                   break;
-               state->cursor = IMSTB_TEXTEDIT_GETNEXTCHARINDEX(str, state->cursor);
+               int next_cursor = IMSTB_TEXTEDIT_GETNEXTCHARINDEX(str, state->cursor);
+               i += next_cursor - state->cursor;
+               state->cursor = next_cursor;
             }
             stb_textedit_clamp(str, state);
 
@@ -980,7 +982,7 @@ retry:
             state->cursor = find.prev_first;
             STB_TEXTEDIT_LAYOUTROW(&row, str, state->cursor);
             x = row.x0;
-            for (i=0; i < row.num_chars; ++i) {
+            for (i=0; i < row.num_chars; ) {
                float dx = STB_TEXTEDIT_GETWIDTH(str, find.prev_first, i);
                #ifdef IMSTB_TEXTEDIT_GETWIDTH_NEWLINE
                if (dx == IMSTB_TEXTEDIT_GETWIDTH_NEWLINE)
@@ -989,7 +991,9 @@ retry:
                x += dx;
                if (x > goal_x)
                   break;
-               state->cursor = IMSTB_TEXTEDIT_GETNEXTCHARINDEX(str, state->cursor);
+               int next_cursor = IMSTB_TEXTEDIT_GETNEXTCHARINDEX(str, state->cursor);
+               i += next_cursor - state->cursor;
+               state->cursor = next_cursor;
             }
             stb_textedit_clamp(str, state);