EditTextView.st
branchjv
changeset 5867 ae5f44ecba6e
parent 5851 4826a8e601e7
parent 5860 acc60507b977
child 5898 dd3d011daf37
--- a/EditTextView.st	Tue Sep 13 07:02:36 2016 +0200
+++ b/EditTextView.st	Mon Sep 19 11:02:14 2016 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
               All Rights Reserved
@@ -1175,6 +1177,40 @@
     "Modified: 14.2.1997 / 17:35:24 / cg"
 !
 
+generateTextAfterEndHook:aBlock
+    "some applications may want to dynamically generate lines below the bottom line,
+     when the cursor is moved there.
+     For example, disassembly views or memory dumps (hex-dumps),
+     which want to automatically generate additional lines lazily,
+     but which cannot afford to generate the whole text in advance
+     (eg: who wants to disassemble gigabytes?).
+     If set, this hook is called whenever the cursor is about to be moved below the 
+     last line, getting the new lineNr (i.e > contents size) as argument.
+     It may generate more text (by setting my contents) and return a new cursor line
+     number, into which the cursor should be moved 
+     (eg. if 10 additional lines are generated, it may want to return oldSize+1, 
+     to make the cursor end in the last line which was inserted)"
+     
+    self setAttribute:#generateTextAfterEndHook to:aBlock
+!
+
+generateTextBeforeStartHook:aBlock
+    "some applications may want to dynamically generate lines above the top
+     line, when the cursor is moved there.
+     For example, disassembly views or memory dumps (hex-dumps),
+     which want to automatically generate additional lines lazily,
+     but which cannot afford to generate the whole text in advance
+     (eg: who wants to disassemble gigabytes?).
+     If set, this hook is called whenever the cursor is about to be moved above the 
+     top, getting the new lineNr (i.e < 1) as argument.
+     It may generate more text (by setting my contents) and return a new cursor line
+     number, into which the cursor should be moved 
+     (eg. if 10 additional lines are generated, it may want to return 10, to make the 
+     cursor end in the last line which was inserted)"
+     
+    self setAttribute:#generateTextBeforeStartHook to:aBlock
+!
+
 insertMode:aBoolean
     editMode value:(aBoolean ifTrue:[EditMode insertMode] ifFalse:[EditMode overwriteMode])
 
@@ -1769,16 +1805,31 @@
 cursorDown:n
     "move cursor down by n lines; scroll if at end of visible text"
 
-    |wasOn nv nL|
+    |inLastLine wasOn nv nL cursorColBefore|
 
     (nL := cursorLine) isNil ifTrue:[
         nL := firstLineShown
     ].
 
+    inLastLine := (nL == list size).
+    
+    inLastLine ifTrue:[
+        |generateTextAfterEndHook|
+
+        cursorColBefore := cursorCol.
+        (generateTextAfterEndHook := self getAttribute:#generateTextAfterEndHook) notNil ifTrue:[
+            wasOn := self hideCursor.
+            nL := generateTextAfterEndHook value:(nL + n).
+            self setValidatedCursorLine:nL col:cursorColBefore.
+            self makeCursorVisibleAndShowCursor:wasOn.
+            ^ self.
+        ].    
+    ].
+
     self st80EditMode ifTrue:[
         nL == list size ifTrue:[
             wasOn := self hideCursor.
-            self setValidatedCursorLine:(list size) col:(self listAt:list size) size + 1.
+            self setValidatedCursorLine:nL col:(self listAt:nL) size + 1.
             self makeCursorVisibleAndShowCursor:wasOn.
             self beep.
             ^ self.
@@ -1791,10 +1842,10 @@
         (nv >= nFullLinesShown) ifTrue:[
             self scrollDown:(nv - nFullLinesShown + 1)
         ].
-        self setValidatedCursorLine:(cursorLine + n) col:cursorCol.
+        self setValidatedCursorLine:(cursorLine + n) col:(cursorColBefore ? cursorCol).
         self makeCursorVisibleAndShowCursor:wasOn.
     ] ifFalse:[
-        self setValidatedCursorLine:(nL + n) col:cursorCol.
+        self setValidatedCursorLine:(nL + n) col:(cursorColBefore ? cursorCol).
         self makeCursorVisible.
     ].
 
@@ -2206,17 +2257,18 @@
 cursorUp:n
     "move cursor up n lines; scroll if at start of visible text"
 
-    |wasOn nv nl|
+    |wasOn nv nl cursorColBefore|
 
     cursorLine isNil ifTrue:[
         self setCursorLine:(firstLineShown + nFullLinesShown - 1).
     ].
     nl := cursorLine - n.
     nl < 1 ifTrue:[
-        |scrollAboveTopHandler|
+        |generateTextBeforeStartHook|
         
-        (scrollAboveTopHandler := self getAttribute:#scrollAboveTopHandler) notNil ifTrue:[
-            nl := scrollAboveTopHandler value:nl
+        cursorColBefore := cursorCol.
+        (generateTextBeforeStartHook := self getAttribute:#generateTextBeforeStartHook) notNil ifTrue:[
+            nl := generateTextBeforeStartHook value:nl
         ].    
         nl := nl max:1
     ].
@@ -2229,7 +2281,7 @@
                 self scrollUp:(nv negated + 1)
             ].
         ].
-        self setValidatedCursorLine:nl col:cursorCol.
+        self setValidatedCursorLine:nl col:(cursorColBefore ? cursorCol).
 "/        wasOn ifTrue:[self showCursor].
         self makeCursorVisibleAndShowCursor:wasOn.
     ]