From f710c23bf7f6b6482e555405f72403a3c3c03167 Mon Sep 17 00:00:00 2001 From: Hansi Raber Date: Fri, 29 Apr 2016 04:45:55 +0200 Subject: [PATCH] stb_textedit/stb_text_locate_coord: fix cursor position in the "shouldn't happen, but if it does, fall through to end-of-line case" case (`i=0` causes problems with the return values in this case) --- stb_textedit.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stb_textedit.h b/stb_textedit.h index 29af484..5a617ea 100644 --- a/stb_textedit.h +++ b/stb_textedit.h @@ -417,10 +417,9 @@ static int stb_text_locate_coord(STB_TEXTEDIT_STRING *str, float x, float y) // check if it's before the end of the line if (x < r.x1) { // search characters in row for one that straddles 'x' - k = i; prev_x = r.x0; - for (i=0; i < r.num_chars; ++i) { - float w = STB_TEXTEDIT_GETWIDTH(str, k, i); + for (k=0; k < r.num_chars; ++k) { + float w = STB_TEXTEDIT_GETWIDTH(str, i, k); if (x < prev_x+w) { if (x < prev_x+w/2) return k+i;