1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-05-31 22:41:37 +00:00

Improve handling of vanishing selection

If you select a note or long comment and delete it, the selection is
lost, because the selected item no longer exists.  This is inconvenient
if you're working with the keyboard, because it moves the keyboard
position to the top of the file.

If the previous selection was non-empty, and the new selection is
empty, we want to select the line that would have appeared below the
item that was deleted.  Making this work exactly right is a bunch of
work, but we can make it work mostly right by selecting the first line
associated with the offset of the previous selection.
This commit is contained in:
Andy McFadden 2021-08-15 14:20:58 -07:00
parent 992e008e7d
commit b23eefaa1a

View File

@ -404,6 +404,26 @@ namespace SourceGen {
// to the top of the list.
topIndex = 0;
}
// If the selected item was deleted, we can't restore the selection. This is
// annoying when you're using the keyboard, because if you hit Del to delete a
// note and then hit down-arrow you jump to the top of the file. If we detect
// this situation, we want to select the thing that appeared below it. We can
// approximate this by just selecting the first thing at the offset (which is
// not quite right if you have both a long comment and a note, but it'll do).
//
// This doesn't help for some of the header stuff, e.g. if you select the last
// platform/project equate and then remove one symbol, the selection gets lost.
if (sel.Count == 0 && mSelectionTags.Count != 0) {
Debug.WriteLine("Lost selection");
int tryOffset = mSelectionTags[0].mOffset;
int tryIndex = LineListGen.FindLineByOffset(lineList, tryOffset);
if (tryIndex >= 0) {
Debug.WriteLine(" Setting to offset +" + tryOffset.ToString("x6") +
" (line " + tryIndex + ")");
sel[tryIndex] = true;
}
}
return sel;
}
@ -569,6 +589,7 @@ namespace SourceGen {
return -1;
}
// Start with a binary search.
int low = 0;
int high = lineList.Count - 1;
int mid = -1;