X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fundo%2FUndoDeleteOperation.java;h=73d9c4f3c50e984662822401b095fcefc94f3438;hp=d99a9f68056637ae838788c709d40e9d061c68cc;hb=a6197ddcaac11c0b943183da7d46169742d024af;hpb=88f2c3647ed9e055090484f01a959d4581f85e7d diff --git a/tim/prune/undo/UndoDeleteOperation.java b/tim/prune/undo/UndoDeleteOperation.java index d99a9f6..73d9c4f 100644 --- a/tim/prune/undo/UndoDeleteOperation.java +++ b/tim/prune/undo/UndoDeleteOperation.java @@ -8,13 +8,24 @@ import tim.prune.data.TrackInfo; */ public abstract class UndoDeleteOperation implements UndoOperation { + /** Flag to remember whether the deleted point was at the beginning or end of the selected range */ + private boolean _isAtBoundaryOfSelectedRange = false; + + /** + * @param inAtBoundary true if deleted point was at the beginning or end of the selected range + */ + public void setAtBoundaryOfSelectedRange(boolean inAtBoundary) + { + _isAtBoundaryOfSelectedRange = inAtBoundary; + } + /** * Modify the current point/range selection after the delete operation is undone * @param inTrackInfo track info object * @param inStartIndex start index of reinserted range * @param inEndIndex end index of reinserted range */ - protected static void modifySelection(TrackInfo inTrackInfo, int inStartIndex, int inEndIndex) + protected void modifySelection(TrackInfo inTrackInfo, int inStartIndex, int inEndIndex) { final int numPointsInserted = inEndIndex - inStartIndex + 1; // See if there is a currently selected point, if so does it need to be modified @@ -26,12 +37,19 @@ public abstract class UndoDeleteOperation implements UndoOperation // Same for currently selected range int rangeStart = inTrackInfo.getSelection().getStart(); int rangeEnd = inTrackInfo.getSelection().getEnd(); - if (rangeEnd >= inStartIndex && rangeEnd > rangeStart) + // Was the deleted point at the start or end of the selected range? + final boolean wasAtStart = numPointsInserted == 1 && inStartIndex == rangeStart && _isAtBoundaryOfSelectedRange; + final boolean wasAtEnd = numPointsInserted == 1 && inStartIndex == (rangeEnd+1) && _isAtBoundaryOfSelectedRange; + if (rangeEnd >= inStartIndex && rangeEnd > rangeStart || wasAtStart || wasAtEnd) { rangeEnd += numPointsInserted; if (rangeStart >= inStartIndex) { rangeStart += numPointsInserted; } + // Extend selection if the deleted point was at the start or end + if (wasAtStart) { + rangeStart--; + } inTrackInfo.getSelection().selectRange(rangeStart, rangeEnd); } }