PipalTextEditor.mesa 
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Barth, February 5, 1988 3:32:46 pm PST
DIRECTORY Pipal, PipalEdit, PipalInt, PipalInteractiveEdit, PipalReal;
PipalTextEditor: CEDAR DEFINITIONS = BEGIN
Theory
The Pipal text editor. The look and feel is stolen from Tioga.
Text Class
pipalTextClass: Pipal.Class;
PipalText: TYPE = REF PipalTextRec;
PipalTextRec: TYPE = RECORD [
rope: Pipal.ROPENIL,
size: PipalReal.Size ← PipalReal.emptySize];
Location: TYPE = INT;
CreatePipalText: PROC [rope: Pipal.ROPE, size: PipalReal.Size ← PipalReal.emptySize] RETURNS [text: PipalText];
GetSelectionInterval: PROC [text: PipalText, position: PipalReal.Position, grain: SelectionGrain] RETURNS [interval: PipalInt.Interval, closerRight: BOOL];
Convert a 2D position and grain specification into a selection interval and a boolean which indicates if the position was closer the right edge of the selection bounding box than the left edge.
Text Editor Class
textEditorClass: Pipal.Class;
TextEditor: TYPE = REF TextEditorRec;
TextEditorRec: TYPE = RECORD [
selections: ARRAY Selections OF Selection,
paste: Pipal.ROPENIL];
Selections: TYPE = {primary, secondary};
Selection: TYPE = RECORD [
valid: BOOLFALSE,
interval: PipalInt.Interval,
pendingDelete: BOOLFALSE,
caretAfter: BOOLFALSE,
granularity: SelectionGrain];
SelectionGrain: TYPE = {char, word};
Creation
Create: PROC [text: PipalText] RETURNS [editor: PipalEdit.Editor];
Make an editor object.
Manipulation
InsertRope: PROC [editor: PipalEdit.Editor, characters: Pipal.ROPE];
Insert the characters at the primary selection caret location. If pending delete then delete the primary selection, put it into the paste buffer, and reduce the primary selection size to 0.
Errors: noPrimarySelection
InsertChar: PROC [editor: PipalEdit.Editor, character: CHAR];
Insert the character at the primary selection caret location. If pending delete then delete the primary selection, put it into the paste buffer, and reduce the primary selection size to 0.
Errors: noPrimarySelection
Move: PROC [editor: PipalEdit.Editor];
Move the secondary selection to the primary selection caret location. If pending delete then delete the primary selection, put it into the paste buffer, and reduce the primary selection size to 0. Reduce the secondary selection size to 0.
Errors: noPrimarySelection, noSecondarySelection
Copy: PROC [editor: PipalEdit.Editor];
Copy the secondary selection to the primary selection caret location. If pending delete then delete the primary selection, put it into the paste buffer, and reduce the primary selection size to 0.
Errors: noPrimarySelection, noSecondarySelection
Transpose: PROC [editor: PipalEdit.Editor];
Transpose the primary and secondary selections.
Errors: noPrimarySelection, noSecondarySelection
Delete: PROC [editor: PipalEdit.Editor];
Delete the primary selection, put it into the paste buffer, and reduce the primary selection size to 0.
Errors: noPrimarySelection
Paste: PROC [editor: PipalEdit.Editor];
Insert the paste buffer at the primary selection caret location.
Errors: noPrimarySelection
Erase: PROC [editor: PipalEdit.Editor];
Delete the character before the primary selection caret.
Errors: noPrimarySelection, noCharacterToErase
Selection
SetSelection: PROC [editor: PipalEdit.Editor, interval: PipalInt.Interval, selection: Selections ← primary, pendingDelete: BOOLFALSE, caretAfter: BOOLFALSE, granularity: SelectionGrain ← char];
CancelSelection: PROC [editor: PipalEdit.Editor, selection: Selections ← primary];
Invalidate the selection.
Interactive Editor
InteractiveEditor: PROC [size: PipalReal.Size] RETURNS [viewerData: PipalInteractiveEdit.ViewerData];
Make an empty editor.
END.