DIRECTORY
Carets USING [StartCaret, StopCaret],
EditSpan USING [CompareNodeOrder, NodeOrder],
Imager USING [Color, Context, MaskRectangleI, SetColor],
ImagerBackdoor USING [MakeStipple],
InputFocus USING [Focus, GetInputFocus, SetInputFocus],
Process USING [Detach],
Rope USING [ROPE],
TextEdit USING [FetchChar, Size],
TextLooks USING [Looks, noLooks],
TextNode USING [FirstChild, ForwardClipped, LastWithin, Level, Location, NarrowToTextNode, Offset, Parent, Ref, RefTextNode, Root, Span, StepBackward, StepForward],
TEditDocument USING [BeforeAfter, LineTable, maxClip, PunctuationPosition, SelectionGrain, SelectionId, SelectionPoint, Selection, TEditDocumentData],
TEditSelection USING [Alloc, Copy, Create, Free, IsDown, ForceDown, LockBothSelections, LockSel, fSel, nilSel, pSel, sSel, UnlockBothSelections, UnlockSel],
TEditSelectionPrivate USING [CharPositionInCachedLine],
TEditTouchup USING [LockAfterRefresh, UnlockAfterRefresh],
ViewerLocks USING [CallUnderWriteLock],
ViewerOps USING [AddProp, FetchProp, PaintViewer],
ViewerClasses USING [ModifyProc, Viewer];
Selection display and Control
MakePointSelection:
PUBLIC
PROC [selection: Selection, pos: TextNode.Location] = {
make a point selection at pos out the the current primary selection
tSel: Selection ← TEditSelection.Alloc[];
Copy[source: selection, dest: tSel];
tSel.start.pos ← tSel.end.pos ← pos;
tSel.granularity ← point;
tSel.pendingDelete ← FALSE;
tSel.insertion ← before;
MakeSelection[selection: primary, new: tSel];
Free[tSel];
};
ChangeSelections:
PROC [proc:
PROC [tSel: Selection], sel: Selection] = {
tSel: Selection ← TEditSelection.Alloc[];
LockBothSelections["ChangeBothSelections"];
{
ENABLE
UNWIND => UnlockBothSelections[];
Copy[source: sel, dest: tSel]; proc[tSel]
};
UnlockBothSelections[]; Free[tSel]
};
PushOrExchangeSelections:
PUBLIC
PROC = {
DoPush:
PROC [tSel: Selection] = {
MakeSelection[IF sSel.viewer=NIL THEN NIL ELSE sSel, primary];
MakeSelection[IF tSel.viewer=NIL THEN NIL ELSE tSel, secondary]
};
ChangeSelections[DoPush, pSel]
};
MakePrimary:
PUBLIC
PROC = {
make secondary selection be the primary
DoMakePrimary:
PROC [tSel: Selection] = {
Deselect[secondary]; MakeSelection[tSel, primary]
};
ChangeSelections[DoMakePrimary, sSel]
};
MakeSecondary:
PUBLIC
PROC = {
make secondary selection be the primary
DoMakeSecondary:
PROC [tSel: Selection] = {
Deselect[primary];
MakeSelection[tSel, secondary] ;
};
ChangeSelections[DoMakeSecondary, pSel]
};
CancelPrimary:
PUBLIC
PROC = {
MakeSelection[NIL, primary];
};
CancelSecondary:
PUBLIC
PROC = {
MakeSelection[NIL, secondary];
};
CancelFeedback:
PUBLIC
PROC = {
MakeSelection[NIL, feedback];
};
FakeSecondary:
PUBLIC
PROC [sel: Selection] = {
inner:
PROC = {
IF sSel.viewer # NIL THEN Deselect[secondary];
Copy[source: sel, dest: sSel];
};
WithLockedSelection[secondary, inner, "FakeSecondary"];
};
Deselect:
PUBLIC
PROC [selection: TEditDocument.SelectionId ← primary] = {
Take down the selection without changing the input focus.
inner:
PROC = {
sel: Selection =
SELECT selection
FROM
primary => pSel, secondary => sSel, feedback => fSel, ENDCASE => ERROR;
viewer: Viewer = sel.viewer;
op:
ATOM =
SELECT selection
FROM
primary => $TakeDownPSel,
secondary => $TakeDownSSel,
feedback => $TakeDownFSel,
ENDCASE => ERROR;
down: BOOL = IsDown[selection];
Copy[source: nilSel, dest: sel];
IF viewer#
NIL
AND
NOT down
THEN {
take the selection down from the screen
ViewerOps.PaintViewer[viewer, client, FALSE, op];
IF NOT IsDown[selection] THEN ForceDown[selection];
If the selection was not in a visible viewer, PaintViewer didn't call our paint proc, so the state didn't change. Force change directly.
}
};
WithLockedSelection[selection, inner, "Deselect"];
};
MakeSelection:
PUBLIC
PROC [new: Selection ←
NIL, selection: TEditDocument.SelectionId ← primary, startValid, endValid:
BOOL ←
FALSE, forkPaint:
BOOL ←
TRUE] = {
Changes input focus as well as the selection.
inner:
PROC = {
sel: Selection;
op: ATOM;
SELECT selection
FROM
primary => {
if: Viewer = InputFocus.GetInputFocus[].owner;
sel ← pSel;
op ← $ShowPSel;
IF new=NIL THEN {IF if#NIL THEN InputFocus.SetInputFocus[NIL]}
ELSE IF if#new.viewer THEN InputFocus.SetInputFocus[new.viewer];
};
feedback => {
sel ← fSel;
op ← $ShowFSel;
};
secondary => {
sel ← sSel;
op ← $ShowSSel;
};
ENDCASE => ERROR;
IF new=NIL OR new.viewer # sel.viewer THEN Deselect[selection];
IF new#
NIL
THEN {
IF selection#feedback AND fSel.viewer=new.viewer THEN Deselect[feedback];
When called to make a non-feedback selection is the viewer containing the feedback selection, automatically cancel the feedback selection.
Copy[source: new, dest: sel];
sel.start.metricsValid ← startValid;
sel.end.metricsValid ← endValid;
IF sel.granularity=point THEN sel.pendingDelete ← FALSE;
IF forkPaint
THEN {
showSel:
REF ShowSelRec =
SELECT selection
FROM
primary => showPSel, secondary => showSSel, ENDCASE => showFSel;
IF showSel.process = NIL THEN
TRUSTED {Process.Detach[showSel.process ←
FORK ShowSel[showSel, op ! ABORTED => CONTINUE]]
}
}
ELSE ViewerOps.PaintViewer[sel.viewer, client, FALSE, op]
}
};
WithLockedSelection[selection, inner, "MakeSelection"];
};
ShowSelRec: TYPE = RECORD [ process: PROCESS, selection: TEditDocument.SelectionId ];
showPSel: REF ShowSelRec ← NEW[ShowSelRec ← [NIL, primary]];
showSSel: REF ShowSelRec ← NEW[ShowSelRec ← [NIL, secondary]];
showFSel: REF ShowSelRec ← NEW[ShowSelRec ← [NIL, feedback]];
ShowSel:
PROC [my:
REF ShowSelRec, op:
ATOM] = {
selection: TEditDocument.SelectionId ← my.selection;
sel: Selection ←
SELECT selection
FROM
primary => pSel, secondary => sSel, feedback => fSel, ENDCASE => ERROR;
inner:
PROC = {
viewer: Viewer ← sel.viewer;
inner:
PROC = {
WITH viewer.data
SELECT
FROM
tdd: TEditDocument.TEditDocumentData => {
IF NOT TEditTouchup.LockAfterRefresh[tdd, "ShowSel"] THEN RETURN;
ViewerOps.PaintViewer[viewer, client,
FALSE, op
! UNWIND => TEditTouchup.UnlockAfterRefresh[tdd]];
TEditTouchup.UnlockAfterRefresh[tdd];
};
ENDCASE;
};
IF viewer#NIL THEN ViewerLocks.CallUnderWriteLock[inner, viewer];
WithLockedSelection[selection, inner, "ShowSel"];
};
lightGrey: Imager.Color ← ImagerBackdoor.MakeStipple[stipple: 0208H, xor: TRUE];
darkGrey: Imager.Color ← ImagerBackdoor.MakeStipple[stipple: 0A5A5H, xor: TRUE];
veryDarkGrey: Imager.Color ← ImagerBackdoor.MakeStipple[stipple: 0EBEBH, xor: TRUE];
black: Imager.Color ← ImagerBackdoor.MakeStipple[stipple: 0FFFFH, xor: TRUE];
SelColor: TYPE = {black, lightGrey, darkGrey, veryDarkGrey} ← black;
SelBound: TYPE = {solid, line} ← solid;
selectionLineWidth: NAT ← 2;
feedbackLineWidth: NAT ← 4;
feedbackLineRaise:
INTEGER ← 1;
selectionDescentLimit:
NAT ← 7;
N.B. Also in TEditMouseImpl
MarkSelection:
PUBLIC
PROC [dc: Imager.Context, viewer: Viewer, selection: Selection, id: TEditDocument.SelectionId] = {
WITH viewer.data
SELECT
FROM
tdd: TEditDocument.TEditDocumentData => {
lines: TEditDocument.LineTable = tdd.lineTable;
vHeight: INTEGER = selection.viewer.ch;
selBound: SelBound = IF selection.pendingDelete AND id#feedback THEN solid ELSE line;
selColor: SelColor = IF id=primary THEN black ELSE IF id=feedback THEN veryDarkGrey ELSE IF selection.pendingDelete THEN lightGrey ELSE darkGrey;
EffectSelect:
PROC [x, y, w, h:
INTEGER] = {
lineHeight: NAT ← selectionLineWidth;
bottom: INTEGER ← vHeight-y-h;
IF id=feedback THEN { lineHeight ← feedbackLineWidth; bottom ← bottom - feedbackLineRaise };
SELECT selColor
FROM
black => Imager.SetColor[dc, black];
lightGrey => Imager.SetColor[dc, lightGrey];
darkGrey => Imager.SetColor[dc, darkGrey];
veryDarkGrey=> Imager.SetColor[dc, veryDarkGrey];
ENDCASE => ERROR;
SELECT selBound
FROM
line => Imager.MaskRectangleI[dc, x, bottom, w, lineHeight];
solid => Imager.MaskRectangleI[dc, x, bottom, w, vHeight-y-bottom];
ENDCASE => ERROR;
};
IF selection.end.line<0 OR selection.start.line=LAST[INTEGER] OR
(selection.start.line=selection.end.line AND selection.end.clipped) THEN RETURN; -- not visible
SELECT
TRUE
FROM
selection.start.line = selection.end.line
OR (selection.start.line < 0
AND selection.end.line = 0) => {
one liner
x, y: INTEGER;
IF selection.start.line < 0
OR selection.start.clipped
THEN {
select from beginning of line
line: INTEGER ← MAX[0, selection.start.line];
x ← lines[line].xOffset;
y ← lines[line].yOffset-lines[line].ascent;
}
ELSE { x ← selection.start.x; y ← selection.start.y };
IF selection.end.clipped THEN ERROR; -- previous tests imply NOT end.clipped
EffectSelect[x, y, selection.end.x-x+selection.end.w, selection.end.h]
};
selection.start.line=lines.lastLine
AND selection.end.line>lines.lastLine => {
EffectSelect[selection.start.x, selection.start.y, lines[selection.start.line].width + lines[selection.start.line].xOffset - selection.start.x, selection.start.h]
};
ENDCASE => {
sl: INTEGER = MAX[0, MIN[lines.lastLine, selection.start.line]];
el: INTEGER = MAX[0, MIN[lines.lastLine, selection.end.line]];
EffectSelAll:
PROC [n:
INTEGER] = {
EffectSelect[lines[n].xOffset, lines[n].yOffset-lines[n].ascent, lines[n].width,
lines[n].ascent+lines[n].descent]
};
IF sl=selection.start.line
AND
NOT selection.start.clipped
THEN {
select end portion of sl
EffectSelect[selection.start.x, selection.start.y, (lines[sl].width + lines[sl].xOffset - selection.start.x), selection.start.h]
}
ELSE {
select all of sl
EffectSelAll[sl];
};
FOR n:
INTEGER
IN (sl..el)
DO
select all of the intermediate lines
EffectSelAll[n];
ENDLOOP;
SELECT
TRUE
FROM
selection.end.clipped => {}; -- end.line is not actually part of the selection
el=selection.end.line => {
EffectSelect[lines[el].xOffset, selection.end.y, selection.end.x - lines[el].xOffset + selection.end.w, selection.end.h];
};
ENDCASE => {
EffectSelAll[el];-- end.line is off screen, so select all of el
};
};
};
ENDCASE;
};
ExtendSelection:
PUBLIC
PROC [dc: Imager.Context, viewer: Viewer, old, new: Selection, id: TEditDocument.SelectionId, updateEnd:
BOOL] = {
when done, old is valid (it's = pSel, e.g.) and new^ = old^
TooHard:
PROC = {
MarkSelection[dc, viewer, old, id]; -- take it down
FixupSelection[new, viewer]; -- get position info about the new selection
MarkSelection[dc, viewer, new, id]; -- put it up
Copy[source: new, dest: old];
};
IF updateEnd
THEN {
update right end
BumpLoc:
PROC [loc: TextNode.Location]
RETURNS [TextNode.Location] = {
n: TextNode.RefTextNode = TextNode.NarrowToTextNode[loc.node];
where: TextNode.Offset ← loc.where+1;
IF where >= TextEdit.Size[n] THEN RETURN [[TextNode.StepForward[n],0]];
RETURN [[n,where]];
};
tooHard: BOOL = old.end.line NOT IN [0..LAST[INTEGER]);
sameNode: BOOL = (new.end.pos.node = old.end.pos.node);
IF tooHard THEN {TooHard; RETURN};
SELECT
TRUE
FROM
new.end.pos=old.end.pos => {};
(sameNode
AND new.end.pos.where>old.end.pos.where)
OR (
NOT sameNode
AND EditSpan.CompareNodeOrder[new.end.pos.node, old.end.pos.node]=after) => {
new end after old end
new.start ← old.end;
new.start.pos ← BumpLoc[new.start.pos];
IF sameNode AND new.start.pos.node # new.end.pos.node THEN
new.start.pos ← new.end.pos;
This weird case can happen if old ended with final CR of node and new is in the null line displayed after the CR.
FixupSelection[new, viewer];
MarkSelection[dc, viewer, new, id];
old.end ← new.end;
}
ENDCASE => {
new end before old end
save: TextNode.Location = new.end.pos;
new.start ← new.end;
new.start.pos ← BumpLoc[save];
IF sameNode AND new.start.pos.node # new.end.pos.node THEN
new.start.pos ← old.end.pos;
old ended in null line after final CR, new ends with the final CR
new.end ← old.end;
FixupSelection[new, viewer, TRUE, FALSE]; -- fix start
MarkSelection[dc, viewer, new, id];
old.end ← new.start;
old.end.pos ← save;
FixupSelection[old, viewer, FALSE, TRUE];
};
}
ELSE {
update start
DecLoc:
PROC [loc: TextNode.Location]
RETURNS [TextNode.Location] = {
n: TextNode.RefTextNode;
IF loc.where > 0 THEN RETURN [[loc.node, loc.where-1]];
n ← TextNode.NarrowToTextNode[TextNode.StepBackward[loc.node]];
RETURN [[n,MAX[TextEdit.Size[n],1]-1]]
};
tooHard: BOOL = old.start.line NOT IN [0..LAST[INTEGER]);
sameNode: BOOL = (new.start.pos.node = old.start.pos.node);
IF tooHard THEN {TooHard; RETURN};
SELECT
TRUE
FROM
new.start.pos=old.start.pos => {};
(sameNode
AND new.start.pos.where<old.start.pos.where)
OR (
NOT sameNode
AND EditSpan.CompareNodeOrder[new.start.pos.node, old.start.pos.node]=before) => {
new start comes before old start
new.end.pos ← DecLoc[old.start.pos];
FixupSelection[new, viewer];
MarkSelection[dc, viewer, new, id];
old.start ← new.start;
}
ENDCASE => {
new start comes after old start
save: TextNode.Location = new.start.pos;
new.end.pos ← DecLoc[save];
new.start ← old.start;
FixupSelection[new, viewer, FALSE, TRUE];
MarkSelection[dc, viewer, new, id];
old.start.pos ← save;
FixupSelection[old, viewer, TRUE, FALSE];
};
};
Copy[source: old, dest: new];
};
CannotFindIt: PUBLIC ERROR = CODE;
ComputeSpanLines:
PUBLIC
PROC [viewer: Viewer, span: TextNode.Span]
RETURNS [start, end:
INTEGER, startClipped, endClipped:
BOOL] = {
[start,startClipped] ← ComputePosLine[viewer, span.start];
SELECT
TRUE
FROM
span.start=span.end => { end ← start; endClipped ← startClipped };
start=
LAST[
INTEGER] => end ←
LAST[
INTEGER]
-- scrolled off bottom
ENDCASE => {
firstLine: INTEGER = IF start<=0 THEN 0 ELSE
IF startClipped THEN start-1 ELSE start;
[end,endClipped] ← ComputePosLine[viewer, span.end, firstLine];
};
};
ComputePosLine:
PUBLIC
PROC [viewer: Viewer, pos: TextNode.Location, firstLine:
INTEGER ← 0]
RETURNS [line:
INTEGER, clipped:
BOOL] = {
sp: TEditDocument.SelectionPoint ← ComputePosPoint[viewer, pos, firstLine, TRUE];
RETURN [sp.line, sp.clipped];
};
ComputePosPoint:
PUBLIC
PROC [viewer: Viewer, pos: TextNode.Location, firstLine:
INTEGER ← 0, lineOnly:
BOOL ←
FALSE]
RETURNS [sp: TEditDocument.SelectionPoint] = {
this must work correctly even if the node was filtered out for some reason
if pos was filtered, return line where it would have been and set clipped=TRUE
WITH viewer.data
SELECT
FROM
tdd: TEditDocument.TEditDocumentData => {
foundPos: BOOL ← FALSE;
IsPosPastLine:
PROC [pos: TextNode.Location, line:
INTEGER]
RETURNS [
BOOL] = {
next: TextNode.Offset;
next ← lines[line].pos.where+lines[line].nChars;
IF pos.where >= next AND lines[line].end # eon THEN RETURN [TRUE]; -- it is past this line
RETURN [FALSE]
};
FindPos:
PROC [pos: TextNode.Location]
RETURNS [found:
BOOL, line:
INTEGER] = {
found ← FALSE;
FOR n:
INTEGER
IN [firstLine..lines.lastLine]
DO
SELECT
TRUE
FROM
lines[n].pos.node=pos.node => {
IF pos.where < lines[n].pos.where THEN EXIT; -- have gone past it
found ← TRUE;
found => EXIT;
ENDCASE;
ENDLOOP
};
lines: TEditDocument.LineTable ← tdd.lineTable;
sp.pos ← pos;
IF lines[0].pos.node = pos.node
THEN {
IF lines[0].pos.where > pos.where
THEN {
before beginning of text
sp.y ← sp.line ← -LAST[INTEGER];
RETURN;
};
};
IF lines[lines.lastLine].pos.node=pos.node
AND IsPosPastLine[pos,lines.lastLine]
THEN {
sp.y ← sp.line ← LAST[INTEGER]; -- after end of text
RETURN;
};
firstLine ← MIN[lines.lastLine,MAX[firstLine,0]];
[foundPos, sp.line] ← FindPos[pos]; sp.clipped ← FALSE;
IF NOT foundPos THEN
SELECT EditSpan.CompareNodeOrder[pos.node, lines[0].pos.node]
FROM
same, before => { sp.line ← sp.y ← -LAST[INTEGER]; RETURN }; -- before beginning
disjoint => ERROR CannotFindIt;
ENDCASE => -- pos.node comes after first line node
IF tdd.clipLevel = TEditDocument.maxClip AND tdd.commentFilter=includeComments
THEN {
nothing special going on, so would have found it if not after end
sp.line ← sp.y ← LAST[INTEGER];
RETURN
} -- after end
ELSE {
must think about this harder
SELECT EditSpan.CompareNodeOrder[pos.node, lines[lines.lastLine].pos.node]
FROM
same, after => {
it really is after the end
sp.line ← sp.y ← LAST[INTEGER];
RETURN
};
disjoint => ERROR CannotFindIt; -- may have been deleted or moved
ENDCASE => { -- it got clipped
n: TextNode.Ref ← pos.node;
delta: INTEGER ← TextNode.Level[n]-tdd.clipLevel;
firstLine ← 0; -- need to let FindPos look at all the previous lines
FOR i:INTEGER IN [0..delta) DO n ← TextNode.Parent[n]; ENDLOOP;
n ← TextNode.ForwardClipped[n,tdd.clipLevel].nx;
[foundPos, sp.line] ← FindPos[[n,0]];
IF NOT foundPos THEN ERROR CannotFindIt;
may have been restored by Undo
sp.clipped ← TRUE;
};
};
IF lineOnly OR sp.clipped THEN RETURN; -- otherwise, compute metrics
sp.y ← lines[sp.line].yOffset-lines[sp.line].ascent;
sp.h ← lines[sp.line].ascent+MIN[lines[sp.line].descent, selectionDescentLimit];
[sp.x, sp.w] ← TEditSelectionPrivate.CharPositionInCachedLine[viewer, sp.line, pos];
IF sp.x =
LAST[
INTEGER]
THEN {
past this line
IF sp.line=lines.lastLine THEN {sp.line ← sp.y ← LAST[INTEGER]}
ELSE {sp.x ← lines[sp.line].width; sp.w ← 0};
};
sp.metricsValid ← TRUE;
};
ENDCASE;
};
FixupSelection:
PUBLIC
PROC [selection: Selection, viewer: Viewer, start, end:
BOOL ←
TRUE] = {
recompute the xywh fields in the selection
fixes selection screen info assuming start.pos and end.pos are correct
IF start THEN selection.start ← ComputePosPoint[viewer, selection.start.pos];
IF end THEN
SELECT
TRUE
FROM
selection.start.pos=selection.end.pos =>
no need to re-compute
selection.end ← selection.start;
selection.start.line=
LAST[
INTEGER] => {
scrolled off bottom
selection.end.line ← LAST[INTEGER];
selection.end.metricsValid ← TRUE;
};
ENDCASE => {
firstLine:
INTEGER = (
IF selection.start.line<=0 THEN 0
ELSE IF selection.start.clipped THEN selection.start.line-1
ELSE selection.start.line
);
selection.end ← ComputePosPoint[viewer, selection.end.pos, firstLine];
};
};
FixupCaret:
PUBLIC
PROC [selection: Selection] = {
recompute the xy fields in the caret
lines: TEditDocument.LineTable = selection.data.lineTable;
node: TextNode.RefTextNode ← TextNode.NarrowToTextNode[selection.end.pos.node];
size: TextNode.Offset ← TextEdit.Size[node];
PutCaretOnNextLine:
PROC = {
SELECT selection.end.line
FROM
IN [0..lines.lastLine) => {
nextLine: INTEGER ← selection.end.line+1;
selection.caretX ← lines[nextLine].xOffset;
selection.caretY ← selection.viewer.ch - lines[nextLine].yOffset - lines[nextLine].descent;
};
= lines.lastLine => {
selection.caretX ← lines[selection.end.line].xOffset;
selection.caretY ← selection.viewer.ch - selection.end.y - selection.end.h - selection.end.h;
};
ENDCASE => ERROR;
};
IF selection.insertion=before
THEN {
IF selection.start.clipped
THEN selection.caretY ←
LAST[
INTEGER]
-- caret not visible
ELSE IF start.line=lines.lastLine AND granularity=point AND
start.pos.where=size AND size>0 AND TextEdit.FetchChar[node, size-1]=15C
THEN PutCaretOnNextLine
ELSE {
selection.caretX ← selection.start.x;
selection.caretY ←
IF selection.start.line
NOT
IN [0..lines.lastLine]
THEN
LAST[
INTEGER]
ELSE selection.viewer.ch - selection.start.y - selection.start.h;
};
}
ELSE
SELECT
TRUE
FROM
selection.end.clipped =>
caret not visible
selection.caretY ← LAST[INTEGER];
selection.end.pos.where IN [0..size) AND selection.end.line IN [0..lines.lastLine] AND TextEdit.FetchChar[node,selection.end.pos.where]=[0,15C] =>
PutCaretOnNextLine[];
ENDCASE => {
selection.caretX ← selection.end.x+selection.end.w;
selection.caretY ← (
IF selection.end.line NOT IN [0..lines.lastLine] THEN LAST[INTEGER]
ELSE selection.viewer.ch - selection.end.y - selection.end.h
);
};
};
KillSelection:
PUBLIC
PROC = {
selection actually get taken down in our InputModify Proc
IF InputFocus.GetInputFocus[]#NIL THEN InputFocus.SetInputFocus[];
};
ModifyPSel:
PROC [proc:
PROC [root: TextNode.Ref, tSel: Selection]] = {
inner:
PROC = {
root: TextNode.Ref ← SelectionRoot[pSel];
IF root#
NIL
THEN {
tSel: Selection ← TEditSelection.Alloc[];
TEditSelection.Copy[source: pSel, dest: tSel];
proc[root, tSel ! UNWIND => Free[tSel]];
MakeSelection[new: tSel];
Free[tSel];
};
};
WithLockedSelection[primary, inner, "CallWithSelLock"];
};
SelectEverything:
PUBLIC
PROC = {
expand to include everything
DoSelEverything:
PROC [root: TextNode.Ref, tSel: Selection] = {
root ← TextNode.Root[tSel.start.pos.node];
tSel.start.pos ← [TextNode.FirstChild[root], 0];
tSel.end.pos.node ← TextNode.LastWithin[root];
tSel.end.pos.where ← TextEdit.Size[TextNode.NarrowToTextNode[tSel.end.pos.node]]-1;
tSel.granularity ← branch
};
ModifyPSel[DoSelEverything]
};
PendingDeleteSelection:
PUBLIC
PROC = {
DoPDel:
PROC [root: TextNode.Ref, tSel: Selection] = {
tSel.pendingDelete ←
TRUE
};
ModifyPSel[DoPDel]
};
NotPendingDeleteSelection:
PUBLIC
PROC = {
DoNotPDel:
PROC [root: TextNode.Ref, tSel: Selection] = {
tSel.pendingDelete ←
FALSE
};
ModifyPSel[DoNotPDel]
};
CaretBeforeSelection:
PUBLIC
PROC = {
DoCaretBeforeSelection:
PROC [root: TextNode.Ref, tSel: Selection] = {
tSel.insertion ← before
};
ModifyPSel[DoCaretBeforeSelection]
};
CaretAfterSelection:
PUBLIC
PROC = {
DoCaretAfterSelection:
PROC [root: TextNode.Ref, tSel: Selection] = {
IF tSel.granularity # point
THEN tSel.insertion ← after
};
ModifyPSel[DoCaretAfterSelection]
};