EditSpan.mesa; written by Bill Paxton, June 1981
edited by McGregor, August 12, 1983 10:04 am
edited by Bill Paxton, June 14, 1983 4:11 pm
DIRECTORY
TiogaLooks,
TiogaNode,
TiogaTreeOps,
TextEdit,
EditNotify,
UndoEvent;
EditSpan: CEDAR DEFINITIONS
IMPORTS TiogaLooks = BEGIN
Ref: TYPE = TiogaNode.Ref;
RefBranchNode: TYPE = TiogaNode.RefBranchNode;
TreeLoc: TYPE = TiogaTreeOps.TreeLoc;
TreeSpan: TYPE = TiogaTreeOps.TreeSpan;
Event: TYPE = UndoEvent.Ref;
**** Miscellaneous ****
CannotDoEdit: ERROR;
afterMoved1, afterMoved2: TreeLoc;
hints for repaint set by Move, MoveOnto, and Transpose
gives pointers to locs after the moved spans
**** Operations to add or delete looks ****
Looks: TYPE = TiogaLooks.Looks;
noLooks: Looks = TiogaLooks.noLooks;
allLooks: Looks = TiogaLooks.allLooks;
ChangeLooks: PROC [root: RefBranchNode, span: TreeSpan, remove, add: Looks, event: Event ← NIL];
first remove then add in the given span
AddLooks: PROC [root: RefBranchNode, span: TreeSpan, add: Looks, event: Event ← NIL]
= INLINE { ChangeLooks[root, span, noLooks, add, event] };
RemoveLooks: PROC [root: RefBranchNode, span: TreeSpan, remove: Looks, event: Event ← NIL]
= INLINE { ChangeLooks[root, span, remove, noLooks, event] };
SetLooks: PROC [root: RefBranchNode, span: TreeSpan, new: Looks, event: Event ← NIL]
= INLINE { ChangeLooks[root, span, allLooks, new, event] };
ClearLooks: PROC [root: RefBranchNode, span: TreeSpan, event: Event ← NIL]
= INLINE { ChangeLooks[root, span, allLooks, noLooks, event] };
***** Editing operations on spans
Replace: PROC [
destRoot, sourceRoot: RefBranchNode, dest, source: TreeSpan,
saveForPaste: BOOLEANTRUE, event: Event ← NIL]
RETURNS [result: TreeSpan];
replace dest span by copy of source span
if words flag is true, does ReplaceWords instead of ReplaceText
result is the new copy of source
Delete: PROC [root: RefBranchNode, del: TreeSpan, event: Event ← NIL, saveForPaste: BOOLEANTRUE];
RecordGroupForPaste: PROC [start, end: Ref, event: Event]; -- for use by EditGroupImpl.Delete etc.
SaveForPaste: PROC [span: TreeSpan, event: Event ← NIL];
SavedForPaste: PROC RETURNS [span: TreeSpan];
result is last thing deleted or explicitly saved for Paste
Place: TYPE = EditNotify.Place; -- { before, after, sibling, child };
these are modifiers for the destination of a Move or Copy or Insert
only apply when destination is an entire node (i.e., dest.where = NodeItself)
place = before means insert as sibling before dest
place = after means insert as sibling after dest; inherit children of dest
place = sibling means insert as sibling after dest; don't inherit children of dest
place = child means insert as first child of dest
Copy: PROC [destRoot, sourceRoot: RefBranchNode, dest: TreeLoc, source: TreeSpan,
where: Place ← after, nesting: INTEGER ← 0, event: Event ← NIL]
RETURNS [result: TreeSpan];
result is the new copy of source
Move: PROC [destRoot, sourceRoot: RefBranchNode, dest: TreeLoc, source: TreeSpan,
where: Place ← after, nesting: INTEGER ← 0, event: Event ← NIL]
RETURNS [result: TreeSpan];
dest cannot be within source or get error BadMove
result is moved span
nesting is relative to dest
e.g., where=after and nesting=1 makes source be child of dest
MoveOnto: PROC [destRoot, sourceRoot: RefBranchNode, dest, source: TreeSpan,
saveForPaste: BOOLEANTRUE, event: Event ← NIL]
RETURNS [result: TreeSpan];
like Replace, but moves source instead of copying it
result is moved span
Transpose: PROC [
alphaRoot, betaRoot: RefBranchNode, alpha, beta: TreeSpan, event: Event ← NIL]
RETURNS [newAlpha, newBeta: TreeSpan];
alpha and beta must not overlap or get error BadTranspose
newAlpha is new location of alpha span; ditto for newBeta
***** Insert new nodes
Insert: PROC [root: RefBranchNode, old: Ref, where: Place ← after, event: Event ← NIL]
RETURNS [new: Ref];
empty copy of old node is inserted in tree in position determined by "where"
Inherit: PROC [old, new: Ref, allprops: BOOLFALSE];
InsertTextNode: PROC [
root: RefBranchNode, old: Ref, class: TiogaNode.ItemClassID ← TiogaNode.defaultTextClassID,
where: Place ← after, inherit: BOOLFALSE, event: Event ← NIL]
RETURNS [new: TiogaNode.RefTextNode];
empty text item node is inserted in tree
InsertBranchNode: PROC [
root: RefBranchNode, old: Ref, where: Place ← after, inherit: BOOLFALSE, event: Event ← NIL]
RETURNS [new: TiogaNode.RefBranchNode];
empty branch node is inserted in tree
InsertBoxNode: PROC [
root: RefBranchNode, old: Ref, class: TiogaNode.ItemClassID,
where: Place ← after, inherit: BOOLFALSE, event: Event ← NIL]
RETURNS [new: TiogaNode.RefBoxNode];
empty box item node is inserted in tree
InsertListNode: PROC [
root: RefBranchNode, old: Ref, class: TiogaNode.ItemClassID,
where: Place ← after, inherit: BOOLFALSE, event: Event ← NIL]
RETURNS [new: TiogaNode.RefListNode];
empty list item node is inserted in tree
InsertBasicNode: PROC [
root: RefBranchNode, old: Ref, class: TiogaNode.BasicClassID,
where: Place ← after, inherit: BOOLFALSE, event: Event ← NIL]
RETURNS [new: TiogaNode.RefBasicNode];
empty basic node is inserted in tree
***** Break & Join
BreakTextNode: PROC [root: RefBranchNode, loc: TreeLoc, event: Event ← NIL] RETURNS [new: Ref];
Inserts copy of loc.node as next sibling and returns this as "new". Moves text starting with loc.where to new. Error if loc.node is not a text node.
BreakParent: PROC [root: RefBranchNode, node: Ref, before: BOOLTRUE, event: Event ← NIL]
RETURNS [Ref];
Inserts copy of parent as next sibling of parent.
If before is true, moves children starting with node to be contents of new.
Otherwise, moves children starting with next sibling of node.
Returns the parent of node after the break.
BreakStatement: PROC [root: RefBranchNode, node: Ref, before: BOOLTRUE, event: Event ← NIL]
RETURNS [RefBranchNode];
loc points somewhere in the contents of a statement. This works its way up breaking nodes until contents from node on have been moved to a new statement. If before is true, node moves to the new statement; otherwise, it stays in the old one.
Returns the statement which contains node after the break.
JoinStatements: PROC [root, statement: RefBranchNode, event: Event ← NIL] RETURNS [loc: TreeLoc];
moves contents of statement to end of previous one and then deletes statement
***** Nesting
Nest: PROC [root: RefBranchNode, span: TreeSpan, event: Event ← NIL] RETURNS [new: TreeSpan] = INLINE {
moves span to a deeper nesting level in tree
moves all nodes of span, even if don't have entire node selected
new ← ChangeNesting[root,span,1,event] };
UnNest: PROC [root: RefBranchNode, span: TreeSpan, event: Event ← NIL] RETURNS [new: TreeSpan] = INLINE {
moves span to a shallower nesting level in tree
new ← ChangeNesting[root,span,-1,event] };
ChangeNesting: PROC [root: RefBranchNode, span: TreeSpan, change: INTEGER, event: Event ← NIL]
RETURNS [new: TreeSpan];
END.