Class new title: TextImage subclassof: Textframe fields: 'c1 c2 begintypein superimage oldEntity sel' declare: 'bs paste Deletion on paragraphmenu ctlw esc off Scrap scrap cut ' Scrap_ t1 [Scrap _ t1] again | t1 [[self fintype  [Scrap _ Scrap text]]. t1 _ para findString: Deletion startingAt: c2. t1 = 0  [frame flash] self unselect. c1 _ t1. c2 _ c1 + Deletion length. self paste] align [para alignment_ (1 2 4 0 0 )  (1 + para alignment). self displayall. self reversefrom: c1 to: c2] begintypein_ t1 [begintypein _ t1] c1_ t1 [c1 _ t1] c2_ t1 [c2 _ t1] cancel [self flash] checklooks | t1 t2 t3 t4 [t1 _ (166 150 137 151 230 214 201 215 135 159 144 143 128 127 129 131 180 149 199 223 208 207 192 191 240 226 ) find: user kbck. t1 = 0  [false] user kbd. [oldEntity  [] oldEntity _ para. para _ para copy]. t1 = 25  [para _ para toBravo] t1 = 26  [para _ para fromBravo] t2 _ (1 2 4 256 1 2 4 256 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 )  t1. [t2 = 256  [t3 _ 255. t2 _ 0] t2 < 0  [t3 _ 0 - t2. t2 _ 0] t2 > 0 and t2 < 16  [t3 _ t2] t3 _ 240]. para maskrun: c1 to: c2 - 1 under: t3 to: t2. [t3 = 240  [self replace: c1 to: c2 - 1 with: (para copy: c1 to: c2 - 1)] self displaylines: (self lineofchar: c1) to: (self lineofchar: c2)]. self select] classInit [bs _ 8. ctlw _ 145. esc _ 160. cut _ 173. paste _ 158. Deletion _ nullString. Scrap _ Deletion. on _ 1. off _ 0. paragraphmenu _ Menu new string: 'again copy cut paste doit compile undo cancel align fit resize '] close [superimage _ nil] compile [self flash] complement [self complement: on] complement: t1 [t1 = sel  [] t1 = on and (user rawkbck or user redbug)  [] sel _ t1. self reversefrom: c1 to: c2] complementfrom: t1 to: t2 | t3 [t1 minY = t2 minY  [(([t1 minX  t2 minX  [t1 origin rect: t2 corner] t2 origin rect: t1 corner] intersect: frame) intersect: window) comp] [t1 minY > t2 minY  [t3 _ t1. t1 _ t2. t2 _ t3]]. t3 _ frame minX  t1 maxY rect: frame maxX  t2 minY. (((t1 origin rect: t3 maxX  t3 minY) intersect: frame) intersect: window) comp. ((t3 intersect: frame) intersect: window) comp. (((t3 minX  t3 maxY rect: t2 corner) intersect: frame) intersect: window) comp] contents [para] copy | t1 [t1 _ TextImage new paragraph: para copy frame: frame copy style: style copy. t1 c1_ c1. t1 c2_ c2. t1 begintypein_ begintypein. t1] copyselection [Scrap _ self selection] cut [self fintype. self replace: nullString. self select. Scrap _ Deletion] displayat: t1 effect: t2 clippedBy: t3 | t4 [super displayat: t1 effect: t2 clippedBy: t3] doit [self flash] edit: t1 | t2 t3 t4 [superimage _ t1. self show. self reversefrom: c1 to: c2. user waitnobug. until 1 = 2 do [user kbck  [self kbd] user yellowbug  [t4 _ paragraphmenu bug. t4 = 1  [self again] t4 = 2  [self copyselection] t4 = 3  [self cut] t4 = 4  [self paste] t4 = 5  [self doit] t4 = 6  [self compile] t4 = 7  [self undo] t4 = 8  [self cancel] t4 = 9  [self realign] t4 = 10  [self fit] t4 = 11  [self resize]] user redbug  [self reversefrom: c1 to: c2. t2 _ user mp. frame has: t2  [self select: t2] self] user tabletbug  [t2 _ user mp. frame has: t2  [self tabletBug] self reversefrom: c1 to: c2. self] user bluebug  [self reversefrom: c1 to: c2. self]]] enter [begintypein _ false. self show. self select] fintype [begintypein  [[begintypein < c1  [Scrap _ para copy: begintypein to: c1 - 1. c1 _ begintypein]]. begintypein _ false] false] fit | t1 [self white. frame extent_ frame width  1000. t1 _ self rectofchar: para length + 1. frame extent_ frame width  (t1 corner y - frame origin y). self show. frame border: 1 color: 1. self reversefrom: c1 to: c2] fixframe: t1 | t2 [t2 _ [frame  nil  [0] self frameoffset]. window _ t1 copy. window height_ window height | style lineheight - 2. frame _ Rectangle new origin: window origin + (2  t2) extent: window width - 4  9999. self measureall. window] flash [(frame intersect: window) flash] formerly [oldEntity] formerly: t1 [oldEntity _ t1] frame_ t1 [self fixframe: t1] frameoffset [frame minY - window minY] height | t1 [self pointofchar: para length + 1 andrect [t1]. t1 corner y - frame minY] hideData: t1 | t2 t3 t4 [t3 _ para hideData: t1. t2 _ String new: t3 length + 4. t4 _ Stream new. t4 of: t2. t4 append: t3. t2] kbd | t1 t2 [c1 < c2 and self checklooks  [] t1 _ Set new string: 16. [begintypein  [] Deletion _ self selection. begintypein _ c1]. while [t2 _ user kbdnext. t2] do [t2 = bs  [t1 empty  [c1 _ 1 max: c1 - 1. begintypein _ begintypein min: c1] t1 skip: 1] t2 = cut  [self cut] t2 = paste  [self paste] t2 = ctlw  [[t1 empty  [] self replace: t1. t1 reset. c1 _ c2]. c1 _ 1 max: c1 - 1. while (c1 > 1 and (para  (c1 - 1)) tokenish) do [c1 _ c1 - 1]. begintypein _ begintypein min: c1] t2 = esc  [[t1 empty  [self unselect] self replace: t1. c1 _ c2]. self fintype. c1 _ c2 - Scrap length. self complement] t1 next_ t2]. self replace: t1. c1 _ c2. self selectAndScroll] keyset leave [self complement: off] leftflush [self para flushleft] paragraph: t1 frame: t2 style: t3 [para _ t1. frame _ t2. style _ t3. [nil  para  [para _ nullString]]. begintypein _ 1. c2 _ begintypein. c1 _ c2. self para: para frame: frame style: style] paste [self fintype. self unselect. self replace: Scrap. self selectAndScroll] pressCode [4] realign [self align. sel _ on] rectangle [frame] replace: t1 [[oldEntity  [] oldEntity _ para. para _ para copy]. [begintypein  [] Deletion _ self selection]. self replace: c1 to: c2 - 1 with: t1. c2 _ c1 + t1 length] resize | t1 t2 t3 t4 [t1 _ frame origin. CornerCursor topage1. user waitbug. self white. frame corner_ frame origin. until user nobug do [self white. t2 _ superimage superimage mp + superimage superimage rectangle origin. frame corner_ t2 max: frame origin + (16  style lineheight). self displayat: frame origin effect: 0 clippedBy: frame]. NormalCursor topage1. self show. frame boxcomp. self reversefrom: c1 to: c2] reversefrom: t1 to: t2 | t3 t4 t5 [self pointofchar: t1 andrect [t5]. t3 _ t5. [t2 = t1  [t4 _ t3 + (1  0)] self pointofchar: t2 andrect [t5]. t4 _ t5]. self complementfrom: t3 to: t4] scrollPos | t1 [t1 _ self height - self lineheight. t1 = 0  [0.0] 0.0 - self frameoffset / t1] scrollTo: t1 [self scrollUp: self frameoffset + (t1 * self height) - 4] scrollUp: t1 [self scrollby: t1 / self lineheight] scrollby: t1 | t2 [t1 _ t1 * self lineheight max: self frameoffset. frame moveby: 0  (0 - t1). t1 abs  window height  [self show. self select] t2 _ window. window _ [t1 < 0  [window inset: 0  0 and: 0  (0 - t1)] window inset: 0  t1 and: 0  0]. window blt: window origin - (0  t1) mode: storing. [t1 < 0  [window corner y_ window origin y - t1] window origin y_ window corner y - t1]. self displayall. self select. window _ t2] select [self selectIn: nil] select: t1 [self complement: off. c2 _ t1. c1 _ c2. self selectAndScroll] selectAndScroll | t1 t2 t3 [t1 _ self lineheight. self select. t3 _ (self ptofchar: c1) y. t2 _ t3 - window minY. [t2  0  [t2 _ t3 + t1 - 1 - window maxY max: 0]]. t2  0  [self scrollby: t2 abs + t1 - 1 / t1 * t2 sign]] selectIn: t1 [sel _ off. [c1  nil  [c2 _ 1. c1 _ c2]]. self complement: on] selectRange [c1 to: c2 - 1] selectRange: t1 [c1 _ t1 start. c2 _ t1 stop] selecting | t1 t2 t3 t4 t5 t6 t7 t8 [t1 _ user mp. t2 _ self charofpoint: t1 andrect [t3]. self complement: off. self fintype. [t2 = c1 and c1 = c2  [while (user redbug and t2 = (self charofpt: user mp)) do []. user redbug  false  [self selectword. self select. true]]]. sel _ on. c2 _ t2. c1 _ c2. t4 _ t3 + (1  0). self complementfrom: t3 to: t4. t8 _ true. while [t1 _ user mpnext. t1] do [t5 _ self charofpoint: t1 andrect [t6]. [c1 = c2  [t7 _ t5  c2]]. [t7  [[t5 < c1  [t5 _ c1. self pointofchar: t5 andrect [t6]]]. self complementfrom: t6 to: t4. c2 _ t5. t4 _ t6] [t5 > c2  [t5 _ c2. self pointofchar: t5 andrect [t6]]]. self complementfrom: t3 to: t6. c1 _ t5. t3 _ t6]. t3 = t4  [t4 _ t3 + (1  0). self complementfrom: t3 to: t4]]. t7  [] self complementfrom: t4 - (1  0) to: t4] selection [para text empty  [para copy] para copy: c1 to: c2 - 1] selectionAsStream [Stream new of: para text from: c1 to: c2 - 1] selectword | t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 [t3 _ 1. t2 _ t3. t1 _ t2. t8 _ para text. t9 _ t8 length. t5 _ 1. t6 _ '([{<''" '. t7 _ ')]}>''" '. [c1  1  [t3 _ 1. t4 _ c1] c1 > t9  [t4 _ c1 - 1] t1 _ para  (c1 - 1). t4 _ t6 find: t1. t4 > 0  [t3 _ 1. t2 _ t7  t4. t4 _ c1 - 1] t1 _ para  c1. t4 _ t7 find: t1. t4 > 0  [t3 _ 1. t2 _ t6  t4. t4 _ c1] t1 _ 1. t4 _ c1]. until (t5 = 0 or t3 = 1  [t4  t9] t4  1) do [t4 _ t4 + t3. t10 _ t8  t4. t10 = t2  [t5 _ t5 - 1] t10 = t1  [t5 _ t5 + 1] t1 = 1  [(t8  t4) tokenish  [t4 = 1  [t3 _ 1. c1 _ t3. t4 _ c2]] t3 = 1  [c1 _ t4 + 1. t3 _ 1. t4 _ c2 - 1] t5 _ 0]]. [t5  0  [t4 _ t4 + t3]]. t3 = 1  [c2 _ t4 min: t9 + 1] c1 _ t4 + 1] show [[lastline = 0  [super show] self displayall]. sel _ off] showfitted | t1 [super show. t1 _ self rectofchar: para length. t1 bottom > frame bottom  [frame corner y_ t1 corner y. super show]] text [self para text] text: t1 width: t2 | t3 t4 [begintypein _ 1. c2 _ begintypein. c1 _ c2. t3 _ String new: 2. t3 word: 1 _ 16 * 7 + 256. t4 _ Rectangle new origin: 0  0 extent: t2  (DefaultTextStyle lineheight + 2). self paragraph: (Paragraph new text: t1 runs: t3 alignment: 2) frame: t4 style: DefaultTextStyle] typing [self kbd] undo [self fintype. self replace: Deletion. self complement] unselect [self complement: off] white [(frame inset: 2  2) clear: 0]