From a4a377ecad6f1732cc54e7ac329fdef9949f9bf7 Mon Sep 17 00:00:00 2001 From: you Date: Fri, 19 May 2017 07:57:21 +0200 Subject: Fix textarea bug: clicking right of the end of a line caused the cursor to be in one of the next lines (#3474) --- src/intlGUIEditBox.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/intlGUIEditBox.cpp') diff --git a/src/intlGUIEditBox.cpp b/src/intlGUIEditBox.cpp index 29f828076..4cc2d746f 100644 --- a/src/intlGUIEditBox.cpp +++ b/src/intlGUIEditBox.cpp @@ -1120,6 +1120,8 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) if (x < CurrentTextRect.UpperLeftCorner.X) x = CurrentTextRect.UpperLeftCorner.X; + else if (x > CurrentTextRect.LowerRightCorner.X) + x = CurrentTextRect.LowerRightCorner.X; s32 idx = font->getCharacterFromPos(Text.c_str(), x - CurrentTextRect.UpperLeftCorner.X); @@ -1127,7 +1129,7 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) if (idx != -1) return idx + startPos; - // click was off the right edge of the line, go to end. + // click was off the right edge of the last line, go to end. return txtLine->size() + startPos; } -- cgit v1.2.3 From 1469424075affce7c27bb44e5a5cbd51485e44b2 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 20 May 2017 10:12:54 +0200 Subject: Fix input regression introduced by a4a377ecad6f1732cc54e7ac329fdef9949f9bf7 Fix #5776 --- src/intlGUIEditBox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/intlGUIEditBox.cpp') diff --git a/src/intlGUIEditBox.cpp b/src/intlGUIEditBox.cpp index 4cc2d746f..9884af003 100644 --- a/src/intlGUIEditBox.cpp +++ b/src/intlGUIEditBox.cpp @@ -1120,8 +1120,8 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) if (x < CurrentTextRect.UpperLeftCorner.X) x = CurrentTextRect.UpperLeftCorner.X; - else if (x > CurrentTextRect.LowerRightCorner.X) - x = CurrentTextRect.LowerRightCorner.X; + else if (x > CurrentTextRect.LowerRightCorner.X + 1) + x = CurrentTextRect.LowerRightCorner.X + 1; s32 idx = font->getCharacterFromPos(Text.c_str(), x - CurrentTextRect.UpperLeftCorner.X); -- cgit v1.2.3 From 099624a513198334ba66c4770e8679d6b2a9138a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Wed, 24 May 2017 08:56:40 +0200 Subject: Revert 1469424 and fix wrong char position when doing mouse selection on intlGUIEditBox (#5806) * Revert 1469424075affce7c27bb44e5a5cbd51485e44b2 and fix wrong char position when doing mouse selection on intlGUIEditBox position should look at current line not the whole text and shift 1 character on the last line (due to \0 string delimiter) * Finish the fix and prevent values under zero for getCursorPos which crash the program if found * Forget to remove old comment * fix zero to NULL * Fix typo --- src/intlGUIEditBox.cpp | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'src/intlGUIEditBox.cpp') diff --git a/src/intlGUIEditBox.cpp b/src/intlGUIEditBox.cpp index 9884af003..37687e1e4 100644 --- a/src/intlGUIEditBox.cpp +++ b/src/intlGUIEditBox.cpp @@ -29,6 +29,7 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h +#include #include "intlGUIEditBox.h" #if defined(_IRR_COMPILE_WITH_GUI_) && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9 @@ -1096,41 +1097,39 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; - core::stringw *txtLine=0; - s32 startPos=0; - x+=3; + core::stringw *txtLine = NULL; + s32 startPos = 0; + u32 curr_line_idx = 0; + x += 3; - for (u32 i=0; i < lineCount; ++i) - { - setTextRect(i); - if (i == 0 && y < CurrentTextRect.UpperLeftCorner.Y) + for (; curr_line_idx < lineCount; ++curr_line_idx) { + setTextRect(curr_line_idx); + if (curr_line_idx == 0 && y < CurrentTextRect.UpperLeftCorner.Y) y = CurrentTextRect.UpperLeftCorner.Y; - if (i == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y ) + if (curr_line_idx == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y) y = CurrentTextRect.LowerRightCorner.Y; // is it inside this region? - if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y) - { + if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y) { // we've found the clicked line - txtLine = (WordWrap || MultiLine) ? &BrokenText[i] : &Text; - startPos = (WordWrap || MultiLine) ? BrokenTextPositions[i] : 0; + txtLine = (WordWrap || MultiLine) ? &BrokenText[curr_line_idx] : &Text; + startPos = (WordWrap || MultiLine) ? BrokenTextPositions[curr_line_idx] : 0; break; } } if (x < CurrentTextRect.UpperLeftCorner.X) x = CurrentTextRect.UpperLeftCorner.X; - else if (x > CurrentTextRect.LowerRightCorner.X + 1) - x = CurrentTextRect.LowerRightCorner.X + 1; - - s32 idx = font->getCharacterFromPos(Text.c_str(), x - CurrentTextRect.UpperLeftCorner.X); + else if (x > CurrentTextRect.LowerRightCorner.X) + x = CurrentTextRect.LowerRightCorner.X; - // click was on or left of the line - if (idx != -1) - return idx + startPos; + s32 idx = font->getCharacterFromPos(txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X); + // Special handling for last line, if we are on limits, add 1 extra shift because idx + // will be the last char, not null char of the wstring + if (curr_line_idx == lineCount - 1 && x == CurrentTextRect.LowerRightCorner.X) + idx++; - // click was off the right edge of the last line, go to end. - return txtLine->size() + startPos; + return rangelim(idx + startPos, 0, S32_MAX); } -- cgit v1.2.3