// see if we need to move any breakpoints around in response to
// this change to the document's text
String action = changeEvent.getAction();
Range range = changeEvent.getRange();
Position start = range.getStart();
Position end = range.getEnd();
// if the edit was all on one line or the action didn't change text
// in a way that could change lines, we can't have moved anything
if (start.getRow() == end.getRow() ||
(!action.equals("insertText") &&
!action.equals("insertLines") &&
!action.equals("removeText") &&
!action.equals("removeLines")))
{
return;
}
int shiftedBy = 0;
int shiftStartRow = 0;
// compute how many rows to shift
if (action == "insertText" ||
action == "insertLines")
{
shiftedBy = end.getRow() - start.getRow();
}
else
{
shiftedBy = start.getRow() - end.getRow();
}
// compute where to start shifting
shiftStartRow = start.getRow() +
((action == "insertText" && start.getColumn() > 0) ?
1 : 0);
// make a pass through the breakpoints and move them as appropriate:
// remove all the breakpoints after the row where the change
// happened, and add them back at their new position if they were
// not part of a deleted range.
ArrayList<Breakpoint> movedBreakpoints = new ArrayList<Breakpoint>();
for (int idx = 0; idx < breakpoints_.size(); idx++)
{
Breakpoint breakpoint = breakpoints_.get(idx);
int breakpointRow = rowFromLine(breakpoint.getEditorLineNumber());
if (breakpointRow >= shiftStartRow)
{
// remove the breakpoint from its old position
movedBreakpoints.add(breakpoint);
removeBreakpointMarker(breakpoint);
}
}
for (Breakpoint breakpoint: movedBreakpoints)
{
// calculate the new position of the breakpoint
int oldBreakpointPosition =
rowFromLine(breakpoint.getEditorLineNumber());
int newBreakpointPosition =
oldBreakpointPosition + shiftedBy;
// add a breakpoint in this new position only if it wasn't
// in a deleted range, and if we don't already have a
// breakpoint there
if (oldBreakpointPosition >= end.getRow() &&
!(oldBreakpointPosition == end.getRow() && shiftedBy < 0) &&
getBreakpointIdxByLine(lineFromRow(newBreakpointPosition)) < 0)
{
breakpoint.moveToLineNumber(lineFromRow(newBreakpointPosition));
placeBreakpointMarker(breakpoint);
fireEvent(new BreakpointMoveEvent(breakpoint.getBreakpointId()));