SmallSense__JavaEditSupport.st
changeset 458 de41bf2025c0
parent 451 ef7e8e25df63
child 1072 a44c741ee5ef
equal deleted inserted replaced
457:dddd3409f0a0 458:de41bf2025c0
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4 stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
     2 stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
     5 Copyright (C) 2013-2015 Jan Vrany
     3 Copyright (C) 2013-2015 Jan Vrany
     6 
     4 
     7 This library is free software; you can redistribute it and/or
     5 This library is free software; you can redistribute it and/or
   203 
   201 
   204     key == #Return ifTrue:[ 
   202     key == #Return ifTrue:[ 
   205         ^ self keyPressReturn.
   203         ^ self keyPressReturn.
   206     ]. 
   204     ]. 
   207 
   205 
       
   206     UserPreferences current smallSenseElectricEditSupportEnabled ifFalse:[ ^ false ].     
       
   207 
   208     key == ${ ifTrue:[
   208     key == ${ ifTrue:[
   209         ^ self keyPressOpenCurly
   209         ^ self keyPressOpenCurly
   210     ].
   210     ].
   211 
   211 
   212     key == Character space ifTrue:[
   212     key == Character space ifTrue:[
   214     ].
   214     ].
   215 
   215 
   216     ^ false
   216     ^ false
   217 
   217 
   218     "Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   218     "Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   219     "Modified: / 13-08-2014 / 15:30:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   219     "Modified: / 04-05-2015 / 00:09:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   220 !
   220 !
   221 
   221 
   222 keyPressOpenCurly
   222 keyPressOpenCurly
   223     | line tokens i |
   223     | line tokens i |
   224 
   224 
   268     "/ First, check if the cursor is at the end of line, i.e., if
   268     "/ First, check if the cursor is at the end of line, i.e., if
   269     "/ there's no text after the cursor...
   269     "/ there's no text after the cursor...
   270     lineNr := textView cursorLine.
   270     lineNr := textView cursorLine.
   271     line := textView listAt: lineNr.
   271     line := textView listAt: lineNr.
   272     i := line size.
   272     i := line size.
   273     [ i > 0 and:[ (c := line at:i) isSeparator ] ] whileTrue:[ i := i - 1 ].    
   273     i >= textView cursorCol ifTrue:[ 
   274     i <= textView cursorCol ifFalse:[ 
   274         [ i > 0 and:[ (c := line at:i) isSeparator ] ] whileTrue:[ i := i - 1 ].    
   275         "/ If not, do not indent...
   275         i <= textView cursorCol ifFalse:[ 
   276         ^ false 
   276             "/ If not, do not indent...
       
   277             ^ false 
       
   278         ].
   277     ].
   279     ].
   278 
   280 
   279     "/ Search for closest non-empty line above
   281     "/ Search for closest non-empty line above
   280     lineNr := textView cursorLine.
   282     lineNr := textView cursorLine.
   281     line := textView listAt: lineNr.
   283     [ lineNr > 0 and:[ (line := textView list at: lineNr ifAbsent:[nil]) isEmptyOrNil ] ] whileTrue:[ lineNr := lineNr - 1 ].
   282     [ line isEmptyOrNil and:[lineNr > 0 ] ] whileTrue:[ lineNr := lineNr - 1 ].
       
   283     lineNr == 0 ifTrue:[ 
   284     lineNr == 0 ifTrue:[ 
   284         "/ No such line found, givin up
   285         "/ No such line found, givin up
   285         ^ false.
   286         ^ false.
   286     ].
   287     ].
   287     indent := line indexOfNonSeparator.
   288     indent := line indexOfNonSeparator.
   296         textView cursorCol: indent.
   297         textView cursorCol: indent.
   297     ].
   298     ].
   298     ^ true
   299     ^ true
   299 
   300 
   300     "Created: / 13-08-2014 / 15:30:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   301     "Created: / 13-08-2014 / 15:30:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   301     "Modified: / 31-03-2015 / 13:30:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   302     "Modified: / 04-05-2015 / 00:17:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   302 ! !
   303 ! !
   303 
   304 
   304 !JavaEditSupport methodsFor:'initialization'!
   305 !JavaEditSupport methodsFor:'initialization'!
   305 
   306 
   306 initializeForService: anEditService    
   307 initializeForService: anEditService