+ void NormalizeSelection(Block * startBlock, int * startSel, Block * endBlock, int * endSel)
+ {
+ bool selAfter = false;
+ Block b;
+ for(b = selBlock; b; b = GetNextBlock(b))
+ {
+ if(b != selBlock && b == textBlock)
+ {
+ selAfter = true;
+ break;
+ }
+ }
+
+ if(textBlock == selBlock)
+ {
+ *startSel = Min(selPosition, curPosition);
+ *endSel = Max(selPosition, curPosition);
+ *startBlock = *endBlock = textBlock;
+ }
+ else if(!selAfter)
+ {
+ *startBlock = textBlock;
+ *startSel = curPosition;
+ *endSel = selPosition;
+ *endBlock = selBlock;
+ }
+ else
+ {
+ *startBlock = selBlock;
+ *startSel = selPosition;
+ *endSel = curPosition;
+ *endBlock = textBlock;
+ }
+ }
+