Menu

#600 fixes #4011 The Cut Lines macro gives exception if the cursor is beyond text area

None
closed-accepted
#4011 (1)
5
2017-10-15
2017-10-09
No

Hello everybody,

This is my first contribution, a small patch which eliminates the exception.

The bug reporter was not fully accurate saying "If the cursor is on a line beyond the last line of text" because error is triggered when the cursor is on the last line at any position (or, if multiline, selected block ends on the last line). What happens is that the block or line is first selected and then cut. This process fails in JEditBuffer.java at getLineOfOffset(int offset).

public int getLineOfOffset(int offset)
{
    try
    {
        readLock();

        if(offset < 0 || offset > getLength())
            throw new ArrayIndexOutOfBoundsException(offset);

        return lineMgr.getLineOfOffset(offset);
    }
    finally
    {
        readUnlock();
    }
} //}}}

Offset can not be greater than textArea buffer length, while it is greater by one for the last line which results in an exception.

So we just adjust "stop" value (selection ending) when it is beyond buffer length.

1 Attachments

Discussion

  • Alan Ezust

    Alan Ezust - 2017-10-15
    • status: open --> closed-accepted
    • assigned_to: Alan Ezust
    • Group: -->
     
  • Alan Ezust

    Alan Ezust - 2017-10-15

    Committed 24764.

     

Log in to post a comment.