Empyreus / lanterna

Automatically exported from code.google.com/p/lanterna
GNU Lesser General Public License v3.0
0 stars 0 forks source link

TextArea Fails on End key press #83

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If the text area does not have enough lines to fill itself and the user presses 
the End key, repaint() will fail with ArrayIndexOutOfBoundsException:

java.lang.ArrayIndexOutOfBoundsException: -24
    at java.util.ArrayList.elementData(ArrayList.java:371)
    at java.util.ArrayList.get(ArrayList.java:384)
    at com.googlecode.lanterna.gui.component.TextArea.repaint(TextArea.java:119)
    at com.googlecode.lanterna.gui.component.Panel.repaint(Panel.java:147)
    at com.googlecode.lanterna.gui.Window.repaint(Window.java:133)
    at com.googlecode.lanterna.gui.GUIScreen.repaint(GUIScreen.java:187)
    at com.googlecode.lanterna.gui.GUIScreen.update(GUIScreen.java:199)
    at com.googlecode.lanterna.gui.GUIScreen.doEventLoop(GUIScreen.java:237)
    at com.googlecode.lanterna.gui.GUIScreen.showWindow(GUIScreen.java:309)

This is because keyboardInteraction() does not prevent scrollTopIndex from 
being set below zero:

                case End:
                    scrollTopIndex = lines.size() - lastSize.getRows();
                    break;

Here is a simple fix:

                case End:
                    scrollTopIndex = Math.max(0, lines.size() - lastSize.getRows());
                    break;

Thanks for the great library! It's a life saver.

Original issue reported on code.google.com by dboit...@gmail.com on 26 Aug 2013 at 9:17

GoogleCodeExporter commented 9 years ago
I've applied the fix to 2.1.x and trunk, pushed new snapshots to Nexus

Original comment by mab...@gmail.com on 30 Sep 2013 at 1:39