PositionRange.Mesa
Last Edited by: Spreitzer, September 27, 1984 2:15:59 pm PDT
DIRECTORY Convert, MessageWindow, NodeProps, Rope, TEditDocument, TEditInput, TEditOps, TEditProfile, TEditRefresh, TEditSelection, TextNode, ViewerClasses;
PositionRange: CEDAR PROGRAM
IMPORTS Convert, MessageWindow, NodeProps, Rope, TEditInput, TEditOps, TEditProfile, TEditRefresh, TEditSelection, TextNode =
BEGIN
Selection: TYPE = TEditDocument.Selection;
Position: TEditInput.CommandProc = {
TEditInput.CloseEvent[];
ShowPosition[viewer: viewer, skipCommentNodes: TRUE];
RETURN[FALSE, TRUE]
};
PositionIncludingComments: TEditInput.CommandProc = {
TEditInput.CloseEvent[];
ShowPosition[viewer: viewer, skipCommentNodes: FALSE];
RETURN[FALSE, TRUE]
};
Alternate version of TEditSelectionOpsImpl.ShowPosition:
ShowPosition: PROC[viewer: ViewerClasses.Viewer, skipCommentNodes: BOOLTRUE] = BEGIN
countI, countF: INT ← -1;
sel: Rope.ROPE ← TEditOps.GetSelContents[];
selLen: INT ← sel.Length[];
sep: INT ← sel.Index[s2: ".."];
countI ← Convert.IntFromRope[sel.Substr[0, sep] ! Convert.Error => CONTINUE];
IF countI>=0 THEN BEGIN
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 sep < selLen
THEN countF ← Convert.IntFromRope[sel.Substr[sep+2] ! Convert.Error => CONTINUE]
ELSE countF ← countI + 3;
IF countF > 0
THEN TEditSelection.CallWithSelAndDocAndTddLocks[viewer, feedback, DoPosition]
ELSE {OPEN MessageWindow;
Append["Select character count or count..count for position.", TRUE];
Blink[] };
END
ELSE { OPEN MessageWindow;
Append["Select character count or count..count for position.", TRUE];
Blink[] };
END;
Setup: PROC = {
TEditInput.Register[$Position, Position];
TEditInput.Register[$PositionIncludingComments, PositionIncludingComments];
};
Setup[];
END.