Electric insert: do not insert again and again when insertion was deleted by pressing backspace
When a snippet or completion is auto-inserted (i.e., "electric-insert") then subsequent backspace removes it
and "electric-insertion" is disabled temporarily so the (apparently wrong) code is not inserted again.
This will make it - hopefully - less annoying in cases unwanted stuff is inserted.
--- a/SmallSense__CompletionController.st Wed Mar 04 09:51:20 2015 +0000
+++ b/SmallSense__CompletionController.st Wed Mar 04 06:01:34 2015 +0000
@@ -354,10 +354,11 @@
matches1 := list select:[:po | matcher1 value: prefix value: po stringToComplete ].
matches1 notEmptyOrNil ifTrue:[
matches1 size == 1 ifTrue:[
- | selection |
+ | selection completeElectric |
selection := matches1 anElement.
- (completeIfUnambiguous and: [(editView sensor hasKeyEventFor:editView) not]) ifTrue:[
+ completeElectric := completeIfUnambiguous and:[ support electricInsertSuppressed not ].
+ (completeElectric and: [(editView sensor hasKeyEventFor:editView) not]) ifTrue:[
self complete: selection afterKeyPress: keyOrNil.
^ true
] ifFalse:[
@@ -396,7 +397,7 @@
^ false.
"Created: / 17-06-2014 / 07:19:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 11-08-2014 / 14:52:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:15:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CompletionController methodsFor:'private-API'!
--- a/SmallSense__EditSupport.st Wed Mar 04 09:51:20 2015 +0000
+++ b/SmallSense__EditSupport.st Wed Mar 04 06:01:34 2015 +0000
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
Copyright (C) 2013-2015 Jan Vrany
@@ -23,7 +25,7 @@
Object subclass:#EditSupport
instanceVariableNames:'textView backspaceIsUndo completionController
completionEnvironment snippets ignoreKeystrokes
- ignoreKeystrokesPosition'
+ ignoreKeystrokesPosition electricInsertSuppressed'
classVariableNames:''
poolDictionaries:''
category:'SmallSense-Core-Services'
@@ -75,6 +77,10 @@
!EditSupport methodsFor:'accessing'!
+electricInsertSuppressed
+ ^ electricInsertSuppressed
+!
+
environment
^ completionEnvironment ? Smalltalk
@@ -369,9 +375,11 @@
initializeForTextView: anEditTextView
textView := anEditTextView.
backspaceIsUndo := false.
+ electricInsertSuppressed := false.
self initializeCompletion.
"Created: / 12-02-2015 / 00:16:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:14:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'private'!
--- a/SmallSense__SmalltalkEditSupport.st Wed Mar 04 09:51:20 2015 +0000
+++ b/SmallSense__SmalltalkEditSupport.st Wed Mar 04 06:01:34 2015 +0000
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
Copyright (C) 2013-2015 Jan Vrany
@@ -298,6 +300,7 @@
backspaceIsUndo ifTrue:[
textView undo.
backspaceIsUndo := false.
+ electricInsertSuppressed := true.
^ true.
].
].
@@ -307,6 +310,12 @@
^ self keyPressPaste.
].
+ electricInsertSuppressed ifTrue:[
+ (key isCharacter and:[ key isSeparator ]) ifTrue:[
+ electricInsertSuppressed := false.
+ ].
+ ].
+
key == $^ ifTrue:[
^ self keyPressReturnToken
@@ -334,18 +343,21 @@
^ false.
"Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 18-05-2014 / 12:45:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:05:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPressDoubleColon
+ electricInsertSuppressed ifTrue:[ ^ false ].
^ self electricInsertSnippetAfterDoubleColon
"Created: / 22-10-2013 / 03:08:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:07:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPressEqual
| line |
+ electricInsertSuppressed ifTrue:[ ^ false ].
line := textView listAt:textView cursorLine.
line isNil ifTrue:[ ^ false ].
line := line string.
@@ -358,6 +370,7 @@
^ false
"Created: / 22-10-2013 / 11:01:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:07:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPressOpenBracket
@@ -366,6 +379,7 @@
| line |
+ electricInsertSuppressed ifTrue:[ ^ false ].
line := textView listAt: textView cursorLine.
line notNil ifTrue:[
line := line string.
@@ -392,7 +406,7 @@
^ true.
"Created: / 22-01-2014 / 21:35:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 29-01-2014 / 10:30:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:07:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPressPaste
@@ -400,6 +414,7 @@
UserPreferences current smallSenseSmalltalkIndentOnPasteEnabled ifFalse:[ ^ false ].
+ electricInsertSuppressed ifTrue:[ ^ false ].
textView checkModificationsAllowed ifTrue:[
textSelected := textPasted := textView getTextSelectionOrTextSelectionFromHistory.
currentLineNo := textView currentLine.
@@ -423,12 +438,13 @@
^ true
"Created: / 03-05-2014 / 01:08:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 19-07-2014 / 00:13:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:07:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPressReturn
| line tokens c i t currentLineIndent closingBracketIndex |
+ electricInsertSuppressed ifTrue:[ ^ false ].
line := textView listAt: textView cursorLine.
line isNil ifTrue:[ ^ false ].
line := line string.
@@ -530,10 +546,11 @@
^ false.
"Created: / 25-07-2013 / 00:02:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 23-06-2014 / 20:22:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:07:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPressReturnToken
+ electricInsertSuppressed ifTrue:[ ^ false ].
RBFormatter spaceAfterReturnToken ifTrue:[
self electricDo:[
textView insertStringAtCursor:'^ '
@@ -543,7 +560,7 @@
^ false
"Created: / 24-07-2013 / 23:59:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 22-01-2014 / 21:10:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-03-2015 / 17:07:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!SmalltalkEditSupport methodsFor:'initialization'!
--- a/SmallSense__SmalltalkEditSupportTests.st Wed Mar 04 09:51:20 2015 +0000
+++ b/SmallSense__SmalltalkEditSupportTests.st Wed Mar 04 06:01:34 2015 +0000
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
Copyright (C) 2013-2015 Jan Vrany
@@ -120,6 +122,55 @@
"Created: / 11-08-2014 / 15:01:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+test_complete_if_unambiguous_04
+
+ UserPreferences current smallSenseCompleteIfUnambiguous: true.
+ codeView editedMethodOrClass: self class.
+ codeView contents:'editService'.
+ codeView setCursorCol: 12.
+
+ codeViewInteractor type: #(Return Tab).
+ codeViewInteractor type: 't'.
+ Delay waitForMilliseconds: 250.
+ codeViewInteractor type: 'h'.
+ self assert: (codeView list at: 2) = ' thisContext'.
+ Delay waitForMilliseconds: 250.
+ codeViewInteractor type: #(BackSpace).
+ self assert: (codeView list at: 2) = ' t'.
+ codeViewInteractor type: 'h'.
+ Delay waitForMilliseconds: 250.
+ self assert: (codeView list at: 2) = ' th'.
+ Delay waitForMilliseconds: 250.
+ codeViewInteractor type: 'e := t'.
+ Delay waitForMilliseconds: 250.
+ codeViewInteractor type: 'h'.
+ Delay waitForMilliseconds: 250.
+ self assert: (codeView list at: 2) = ' the := thisContext'.
+
+ "Created: / 03-03-2015 / 17:01:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_electric_snippet_do_01
+
+ UserPreferences current smallSenseCompleteIfUnambiguous: true.
+ codeView editedMethodOrClass: self class.
+ codeView contents:'editService
+ snippets do'.
+ codeView setCursorLine: 2; setCursorCol: 16.
+
+ codeViewInteractor type: ':'.
+ Delay waitForMilliseconds: 250.
+ self assert: (codeView list at: 2) = ' snippets do:[:snippet | ]'.
+ codeViewInteractor type: #(BackSpace).
+ self assert: (codeView list at: 2) = ' snippets do'.
+ codeViewInteractor type: ':'.
+ Delay waitForMilliseconds: 250.
+ self assert: (codeView list at: 2) = ' snippets do:'.
+
+ "Created: / 04-03-2015 / 05:54:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+
+!
+
test_electric_snippet_do_03
UserPreferences current smallSenseCompleteIfUnambiguous: true.