class: EditTextView
authorClaus Gittinger <cg@exept.de>
Mon, 28 Oct 2013 12:38:14 +0100
changeset 4818 22857701ea2f
parent 4817 597e3af71218
child 4819 2d77124d5a28
class: EditTextView added: #focusOut #previousReplacements #unmapped comment/format in: #again #release changed: #doKeyPress:x:y: #hasKeyboardFocus: #replaceSelectionBy:keepCursor:select: completion handling when focus changes
EditTextView.st
--- a/EditTextView.st	Mon Oct 28 12:37:17 2013 +0100
+++ b/EditTextView.st	Mon Oct 28 12:38:14 2013 +0100
@@ -88,7 +88,7 @@
 
 Object subclass:#LastReplacementInfo
 	instanceVariableNames:'lastReplacement lastStringToReplace lastReplaceWasMatch
-		lastReplaceIgnoredCase'
+		lastReplaceIgnoredCase stillCollectingInput previousReplacements'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:EditTextView
@@ -1480,6 +1480,12 @@
 !
 
 lastStringToReplace: aString
+!
+
+previousReplacements
+    "accessor for the code completion"
+
+    ^ lastReplacementInfo previousReplacements
 ! !
 
 !EditTextView methodsFor:'change & update'!
@@ -3687,7 +3693,7 @@
     l := cursorLine.
     c := cursorCol.
 
-    sel := self selection.
+    sel := self selectionAsString.
     sel isNil ifTrue:[
         selStartLine := l.
         selStartCol := c.
@@ -3699,20 +3705,17 @@
 
         self deleteSelection.
         replacing := true.
+        lastReplacementInfo rememberReplacement.
         lastReplacementInfo lastReplacement: ''.
+        lastReplacementInfo stillCollectingInput:true.
         undoSupport actionInfo:'replace'.
     ].
 
     something isCharacter ifTrue:[
         lastReplacementInfo lastReplacement notNil ifTrue:[
-"/ "XXX - replacing text with spaces ..."
-"/            (lastReplacement endsWith:Character space) ifTrue:[
-"/                lastReplacement := lastReplacementInfo lastReplacement copyWithoutLast:1 "copyTo:(lastReplacement size - 1)".
-"/                lastReplacement := lastReplacementInfo lastReplacement copyWith:something.
-"/                lastReplacement := lastReplacementInfo lastReplacement copyWith:Character space
-"/            ] ifFalse:[
+            lastReplacementInfo stillCollectingInput ifTrue:[
                 lastReplacementInfo lastReplacement: (lastReplacementInfo lastReplacement copyWith:something).
-"/            ]
+            ].
         ].
         self isInInsertMode ifTrue:[
             self insertCharAtCursor:something
@@ -4811,13 +4814,15 @@
                           #'F*' #'f*')>
 
     |fKeyMacros shiftPressed ctrlPressed i event macroName
-     immediateCompletion|
+     immediateCompletion currentUserPrefs|
+
+    currentUserPrefs := UserPreferences current.
 
     "/ experimental
-    immediateCompletion := UserPreferences current immediateCodeCompletion.
+    immediateCompletion := currentUserPrefs immediateCodeCompletion.
     (immediateCompletion 
-    or:[UserPreferences current codeCompletionOnControlKey
-    or:[UserPreferences current codeCompletionOnTabKey]]) ifTrue:[
+    or:[currentUserPrefs codeCompletionOnControlKey
+    or:[currentUserPrefs codeCompletionOnTabKey]]) ifTrue:[
         completionSupport isNil ifTrue:[
             self initializeCompletionSupport.
         ].
@@ -4830,11 +4835,18 @@
         (completionSupport handleKeyPress:key x:x y:y) ifTrue:["eaten" ^ self].
     ].
 
+    key isSymbol ifTrue:[
+        (device modifierKeys includes:key) ifFalse:[
+            lastReplacementInfo stillCollectingInput:false.
+        ]
+    ].
     (key == #LearnKeyboardMacro) ifTrue:[
+        lastReplacementInfo stillCollectingInput:false.
         self toggleLearnMode.
         ^ self
     ].
     (key == #ExecuteKeyboardMacro) ifTrue:[
+        lastReplacementInfo stillCollectingInput:false.
         self executeLearnedKeyboardMacro.
         ^ self.
     ].
@@ -4871,7 +4883,7 @@
     (key == #BackSpace or:[key == #BasicBackspace]) ifTrue:[
         selectionStartLine notNil ifTrue:[
             ((key == #BasicBackspace)
-            or:[ UserPreferences current deleteSetsClipboardText not ])
+            or:[ currentUserPrefs deleteSetsClipboardText not ])
             ifTrue:[
                 self deleteSelection.
             ] ifFalse: [
@@ -4920,7 +4932,7 @@
         (('[fF][0-9]' match:key)
         or:['[fF][0-9][0-9]' match:key]) ifTrue:[
             shiftPressed ifFalse:[
-                fKeyMacros := UserPreferences current functionKeySequences.
+                fKeyMacros := currentUserPrefs functionKeySequences.
                 fKeyMacros notNil ifTrue:[
                     (fKeyMacros includesKey:key) ifTrue:[
                         self pasteOrReplace:(fKeyMacros at:key) asStringCollection.
@@ -5148,7 +5160,7 @@
 "/            self setLastStringToReplace: self selection asStringWithoutFinalCR.
 "/            lastReplacementInfo lastReplacement: nil.
             ((key == #BasicDelete)
-            or:[UserPreferences current deleteSetsClipboardText not]) ifTrue:[
+            or:[currentUserPrefs deleteSetsClipboardText not]) ifTrue:[
                 self deleteSelection.
             ] ifFalse:[
                 self copyAndDeleteSelection.
@@ -5400,6 +5412,14 @@
 
 !EditTextView methodsFor:'focus handling'!
 
+focusOut
+    super focusOut.
+
+    completionSupport notNil ifTrue:[
+        completionSupport release.
+    ].
+!
+
 hasKeyboardFocus:aBoolean
     "sent by the windowGroup, a delegate or myself to make me show a block cursor
      (otherwise, I would not know about this)"
@@ -5414,7 +5434,7 @@
 
     hasKeyboardFocus ifFalse:[
         completionSupport notNil ifTrue:[
-            completionSupport editViewLostFocus.
+            completionSupport release editViewLostFocus.
         ].
     ].
 
@@ -5432,6 +5452,14 @@
     "Modified: 11.12.1996 / 16:56:54 / cg"
 !
 
+unmapped
+    super unmapped.
+
+    completionSupport notNil ifTrue:[
+        completionSupport release.
+    ].
+!
+
 wantsFocusWithPointerEnter
     "return true, if I want the focus when
      the mouse pointer enters"
@@ -8165,6 +8193,40 @@
 
 lastStringToReplace:something
     lastStringToReplace := something.
+!
+
+previousReplacements
+    ^ previousReplacements ? #()
+!
+
+stillCollectingInput
+    ^ stillCollectingInput
+!
+
+stillCollectingInput:aBoolean
+    stillCollectingInput := aBoolean.
+! !
+
+!EditTextView::LastReplacementInfo methodsFor:'history'!
+
+rememberReplacement
+    "remember the previous replacement (called when a new one appears).
+     Mostly for the benefit of the code completion..."
+
+    |oldString newString|
+
+    oldString := lastStringToReplace.
+    newString := lastReplacement.
+    (oldString notEmptyOrNil and:[newString notEmptyOrNil]) ifTrue:[
+        previousReplacements isNil ifTrue:[
+            previousReplacements := OrderedCollection new.
+        ].
+        previousReplacements := previousReplacements reject:[:entry | entry key = oldString].
+        previousReplacements addFirst:(oldString -> newString).
+        previousReplacements size > 20 ifTrue:[
+            previousReplacements removeLast.
+        ]
+    ].
 ! !
 
 !EditTextView::PasteString methodsFor:'accessing'!
@@ -8423,10 +8485,10 @@
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.592 2013-10-24 08:14:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.593 2013-10-28 11:38:14 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.592 2013-10-24 08:14:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.593 2013-10-28 11:38:14 cg Exp $'
 ! !