CGUIEditBox selecting behaviour fix

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

CGUIEditBox selecting behaviour fix

Post 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
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Another misbehaviour

Post 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;
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Thanks, this makes the editbox feel a lot more like the windows edit box. :)
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Yea, definitely, but not limited to. It's standard feel of other OS'es too. :)
Post Reply