Page 1 of 1

CGUIEditBox selecting behaviour fix

Posted: Thu May 20, 2004 1:07 pm
by jox
Irrlicht 0.6:

I think the GUI elements can (and probably will) be improved in many ways. I just quickly fixed the selection behaviour of the EditBox. It had 2 problems.

1. Selecting backwards with SHIFT-LEFT would not work as expected. It is selecting characters to the right of the cursor instead of to the left (and thus is not the opposite of SHIFT-RIGHT).

2. It is not checking the bounds of the text. You are able to select an invisible non-existing character at the end (making MarkEnd>MarkBegin without actual selected text). It has no effect so far but might produce bugs in future.

CGUIEditBox.cpp line 239:

Change:

Code: Select all

case KEY_LEFT:

	if (event.KeyInput.Shift)
	{
		if (MarkBegin == MarkEnd)
			MarkBegin = CursorPos+1;

		MarkEnd = CursorPos;
	}
to

Code: Select all

case KEY_LEFT:

	if (event.KeyInput.Shift)
	{
		if (CursorPos > 0) {
			if (MarkBegin == MarkEnd)
				MarkBegin = CursorPos;

			MarkEnd = CursorPos-1;
		}
	}
and

Code: Select all

case KEY_RIGHT:

	if (event.KeyInput.Shift)
	{
		if (MarkBegin == MarkEnd)
			MarkBegin = CursorPos;

		MarkEnd = CursorPos+1;
	}
to

Code: Select all

case KEY_RIGHT:

	if (event.KeyInput.Shift)
	{
		if (Text.size() > CursorPos) {
			if (MarkBegin == MarkEnd)
				MarkBegin = CursorPos;

			MarkEnd = CursorPos+1;
		}
	}

greets,
jox

Another misbehaviour

Posted: Fri May 21, 2004 7:00 pm
by jox
If you select a text range and start typing, then the selected text gets replaced by the text you type in. Problem here: the first letter you type deletes the text and puts the cursor to the left of the letter instead of to the right, so that all following letters are placed before the first letter.

Example: if you select the text "Old" and type "New" you end up with "ewN".

To fix this search for "// replace marked text" in CGUIEditBox.cpp and change the following code a couple lines below

Code: Select all

CursorPos = realmbgn;
to

Code: Select all

CursorPos = realmbgn+1;

Posted: Sun May 23, 2004 6:47 am
by niko
Thanks, this makes the editbox feel a lot more like the windows edit box. :)

Posted: Sun May 23, 2004 1:01 pm
by jox
Yea, definitely, but not limited to. It's standard feel of other OS'es too. :)