<> <> 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] }; <> ShowPosition: PROC[viewer: ViewerClasses.Viewer, skipCommentNodes: BOOL _ TRUE] = 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]; <> <> 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.