-- Typescript.tip; Last Edited by Paxton, October 26, 1982 3:22 pm

OPTIONS
  Fast, 
  PrintKeys;

-- general definitions

[DEF,ClickTime,(200)]

[DEF,Click,(~1 Up BEFORE [ClickTime] AND ~1 Down BEFORE [ClickTime])]

[DEF,BothUp,(~1 Up WHILE ~2 Up)]

[DEF,WhileSixUp,
	(WHILE ~1 Up WHILE ~2 Up WHILE ~3 Up WHILE ~4 Up WHILE ~5 Up WHILE ~6 Up)]

[DEF,CTRL,(Ctrl Down | Spare3 Down)]

[DEF,SHIFT,(LeftShift Down | RightShift Down)]

[DEF,IfShift,(SELECT ENABLE FROM
	[SHIFT] => ~1;
	ENDCASE => ~2)]

-- top level trigger select

SELECT TRIGGER FROM

  [DEF,Sel,(SELECT ENABLE FROM
      [SHIFT] => { ~2 Coords SelSecondary ToPrimary ForceSelNotPendDel ~1 };
      ENDCASE => { ~2 Coords ForceSelNotPendDel ~1 })]

  [DEF,MouseClick,(SELECT TRIGGER FROM
      [Click,~1] => [Sel,~3,~1Mouse];
      ENDCASE => [Sel,~2,~1Mouse])]
    
  Red Down => [MouseClick,Red,SelChar,SelNode];
    
  Yellow Down => SELECT ENABLE FROM
    Red Up => [MouseClick,Yellow,SelWord,SelBranch];
    ENDCASE;
      
  [DEF,Extend,([Sel,~1 SelStartExtend,BlueMouse])]
  
  Blue Down => SELECT ENABLE FROM
    [BothUp,Red,Yellow] => SELECT TRIGGER FROM
      [Click,Blue] => SELECT TRIGGER FROM
         [Click,Blue] => [Extend,SelExpand];
         ENDCASE => [Extend,SelReduce];
      ENDCASE => [Extend];
    ENDCASE;

  Mouse =>
    SELECT ENABLE FROM
      Red Down => [Sel,SelUpdate,SelSame];
      Yellow Down => [Sel,SelUpdate,SelSame];
      Blue Down => { Coords SelSame SelSameEnd SelSamePendDel SelExtend };
      ENDCASE;

  Red Up [WhileSixUp,LeftShift,RightShift,Blue,RightShift,Ctrl,Spare3] => DoEdit;

  Yellow Up [WhileSixUp,LeftShift,RightShift,Blue,Red,Ctrl,Spare3] => DoEdit;

  Blue Up [WhileSixUp,LeftShift,RightShift,Yellow,Red,Ctrl,Spare3] => DoEdit;

  LeftShift Up [WhileSixUp,Red,Yellow,Blue,RightShift,Ctrl,Spare3] => DoEdit;
  
  RightShift Up [WhileSixUp,Red,Yellow,Blue,LeftShift,Ctrl,Spare3] => DoEdit;
  
  Ctrl Up [WhileSixUp,LeftShift,Red,Yellow,Blue,Spare3,RightShift] => DoEdit;
  
  Spare3 Up [WhileSixUp,LeftShift,Red,Yellow,Blue,Ctrl,RightShift] => DoEdit;
  
  Spare2 Down =>
    [IfShift,{ IntermediateUser PreviousPlaceholder },{ IntermediateUser NextPlaceholder }];

  ESC Down => Char;

  LF Down => Char;

  BS Down WHILE LeftShift Up WHILE RightShift Up => BackSpace;
  
  DEL Down => SELECT ENABLE FROM
      [CTRL] => Abort;
      [SHIFT] => EditAbort;
      Red Down => EditAbort;
      Yellow Down => EditAbort;
      Blue Down => EditAbort;
      ENDCASE => Delete;

  A Down WHILE [CTRL] => BackSpace;
  C Down WHILE [CTRL] => Char;
  H Down WHILE [CTRL] => BackSpace;
  Q Down WHILE [CTRL] => Char;
  O Down WHILE [CTRL] => Char;
  P Down WHILE [CTRL] => { IntermediateUser Paste };
  R Down WHILE [CTRL] => Char;
  S Down WHILE [CTRL] =>	-- copy primary
  	{ IntermediateUser MakeNotPendingDelete ToSecondary SelSecondary SelNotPendDel };
  T Down WHILE [CTRL] => Char;
  W Down WHILE [CTRL] => BackWord;
  X Down WHILE [CTRL] => Char;
  Z Down WHILE [CTRL] => Char;

  ENDCASE.