DoPosition:
PROC [tdd: TEditDocument.TEditDocumentData, tSel: Selection] = {
tiogaFile: BOOL ← (NodeProps.GetProp[tdd.text, $FromTiogaFile] = $Yes);
IF countF < countI THEN {c: INT ← countI; countI ← countF; countF ← c};
IF ~tiogaFile
-- hack to compensate for leading CR
THEN {countI ← countI+1; countF ← countF+1};
tSel.start.pos ← TextNode.LocWithin[tdd.text, countI, 1, skipCommentNodes];
tSel.end.pos ← TextNode.LocWithin[tdd.text, countF, 1, skipCommentNodes];
tSel.end.pos.where ← MIN[tSel.end.pos.where, TextNode.EndPos[tSel.end.pos.node]];
tSel.start.pos.where ← MIN[tSel.end.pos.where, tSel.start.pos.where];
IF tSel.start.pos.where=tSel.end.pos.where
AND tSel.start.pos.node=tSel.end.pos.node
AND tSel.start.pos.where > 0
THEN
tSel.start.pos.where ← tSel.start.pos.where-1;
tSel.granularity ← char;
tSel.viewer ← viewer;
tSel.data ← tdd;
tSel.pendingDelete ← FALSE;
tSel.insertion ← IF TEditProfile.selectionCaret=before THEN before ELSE after;
TEditOps.RememberCurrentPosition[viewer];
TEditSelection.SetSelLooks[tSel];
TEditSelection.MakeSelection[new: tSel, selection: feedback];
TEditRefresh.ScrollToEndOfSel[viewer,
FALSE, feedback];
-- sets bit to cause scroll after refresh
};
IF countF > 0
THEN TEditSelection.CallWithSelAndDocAndTddLocks[viewer, feedback, DoPosition]
ELSE {
OPEN MessageWindow;
Append["Select character count or count..count for position.", TRUE];
Blink[] };