Faculty of Information Technology
Software Engineering Group

Ticket #130: libwidg_fix_1_of_1_rev_c6976b98f3c3_Issue__130__Fixed_support_for_indenting_by_tab.patch

File libwidg_fix_1_of_1_rev_c6976b98f3c3_Issue__130__Fixed_support_for_indenting_by_tab.patch, 12.2 KB (added by Jan Vrany, 6 years ago)
  • EditTextView.st

    # HG changeset patch
    # User Jan Vrany <jan.vrany@fit.cvut.cz>
    # Date 1507761458 -3600
    #      Wed Oct 11 23:37:38 2017 +0100
    # Branch jv
    # Node ID c6976b98f3c370b4f06146d5398371767462d814
    # Parent  e301f5bd90b1f568837a4e095c1734d04968c489
    Issue #130: Fixed support for indenting by tab
    
    Allow indent a block of code by selecting a range of lines
    and pressing 'tab'. The behavior implemented is the same as
    the one in Sublime Text editor since I found it intuitive enough.
    
    diff -r e301f5bd90b1 -r c6976b98f3c3 EditTextView.st
    a b  
    536536    Standard: Selection is extended to include a space (first press) and a word right to previously selected one
    537537      (checked on Notepad, Gedit (GTK+), Sublime (Win+Lin), Eclipse, Firefox)
    538538
     539* Indenting selected block with Tab
     540  Scenario:
     541    1. Select a block (i.e, make selection that pans multiple lines)
     542    2. Press Tab
     543
     544    Traditional St/X: A single 'tab' is inserted
     545    Standard: all lines in the selection are indented.
     546
    539547"
    540548! !
    541549
     
    55115519                          #OpenSpecialCharacterWindow #InsertUUID
    55125520                          #'F*' #'f*')>
    55135521
    5514     |fKeyMacros shiftPressed ctrlPressed i event macroName
    5515      immediateCompletion currentUserPrefs rawKey|
     5522    |fKeyMacros shiftPressed ctrlPressed i event immediateCompletion currentUserPrefs rawKey|
    55165523
    55175524    currentUserPrefs := UserPreferences current.
    55185525
     
    58505857    ].
    58515858    ((key == #BackTab) or:[(key == #Tab)]) ifTrue:[
    58525859        self tabMeansNextField ifTrue:[^ super keyPress:key x:x y:y].
    5853 
    5854         self hasSelection ifTrue:[
    5855             selectStyle == #line ifTrue:[
    5856                 ((key == #Tab) and:[shiftPressed not]) ifTrue:[
    5857                     macroName := #IndentBy4.
    5858                 ] ifFalse:[
    5859                     macroName := #UndentBy4.
    5860                 ].
    5861                 macroName notNil ifTrue:[
    5862                     self executekeyboardMacroNamed:macroName.
    5863                 ].
    5864             ]
     5860        (self hasSelection and:[selectionStartLine ~~ selectionEndLine]) ifTrue:[
     5861            ((key == #Tab) and:[shiftPressed not]) ifTrue:[
     5862                self indentByTab.
     5863            ] ifFalse:[
     5864                self undentByTab.
     5865            ].
     5866            ^ self.
    58655867        ].
    58665868
    58675869        self unselect.
     
    59585960
    59595961    "Modified: / 06-02-1998 / 11:59:59 / stefan"
    59605962    "Modified: / 14-07-2011 / 12:08:28 / cg"
    5961     "Modified: / 31-03-2014 / 16:27:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     5963    "Modified: / 11-10-2017 / 23:08:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    59625964!
    59635965
    59645966executeKeyboardMacro:cmdMacro
     
    64386440            ]
    64396441        ]
    64406442    ].
     6443    "/ Update the selection, if not whole-lines...
     6444    (selectionStartLine == start and:[ selectionStartCol ~~ 1]) ifTrue:[
     6445        selectionStartCol := (selectionStartCol + delta) max: 1.
     6446    ].
     6447    (selectionEndLine == end and:[ selectionEndCol ~~ 0]) ifTrue:[
     6448        selectionEndCol := (selectionEndCol + delta) max: 1.
     6449    ].
    64416450
    64426451    anyChange ifTrue:[ self textChanged ].
    64436452
    64446453    "/ self redrawFromLine:start to:end
    64456454
    6446     "Modified: 5.3.1996 / 14:59:18 / cg"
     6455    "Modified: / 05-03-1996 / 14:59:18 / cg"
     6456    "Modified: / 11-10-2017 / 23:22:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    64476457!
    64486458
    64496459leftIndentForLine:lineNr
  • tests/EditTextViewTests.st

    diff -r e301f5bd90b1 -r c6976b98f3c3 tests/EditTextViewTests.st
    a b  
    33"{ NameSpace: Smalltalk }"
    44
    55TestCase subclass:#EditTextViewTests
    6         instanceVariableNames:'textView textViewInteractor'
     6        instanceVariableNames:'preferences textView textViewInteractor'
    77        classVariableNames:''
    88        poolDictionaries:''
    99        category:'Views-Text-Tests'
     
    1919
    2020    Smalltalk loadPackage: 'stx:goodies/sunit/ext/ui'.
    2121
     22    preferences := UserPreferences new.
     23    MessageTracer mock: #current  in: UserPreferences class do: [ preferences ].
     24    self assert: UserPreferences current == preferences.
     25
    2226    topView := StandardSystemView new.
    2327    topView extent: 320 @ 200.
    2428    topView label: self printString.
    2529    textView := EditTextView origin: 0.0@0.0 extent: 1.0@1.0 in: topView.
     30    textView setTabPositions: ListView tab4Positions.
     31
    2632    textViewInteractor := textView interactor.
    2733
    28 
    2934    topView open.
    3035    topView waitUntilVisible.
    3136
    3237    "Created: / 23-07-2014 / 07:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    33     "Modified: / 24-02-2015 / 08:22:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     38    "Modified (format): / 12-10-2017 / 23:17:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    3439!
    3540
    3641tearDown
    3742    textView topView destroy.
     43    MessageTracer unmock: #current  in: UserPreferences class
    3844
    3945    "Created: / 23-07-2014 / 07:17:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    40     "Modified: / 24-02-2015 / 08:17:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     46    "Modified: / 12-10-2017 / 22:59:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    4147! !
    4248
    4349!EditTextViewTests methodsFor:'tests'!
     
    137143
    138144    "Created: / 17-03-2017 / 22:43:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    139145    "Modified (comment): / 04-05-2017 / 22:32:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     146!
     147
     148test_issue130_01a
     149    "
     150    Test indenting code by Tab. Scenario:
     151        1. Position code to beggining of a line 2.
     152        2. Select a line by pression Shift-Down so that 'cursor' is before first character on line 3.
     153        3. Press Tab
     154
     155    Check that only line 2 has been indented.
     156    Check, that selection begin/end col has not been updated
     157
     158    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/130
     159    "   
     160    textView contents:'1111
     1612222
     1623333
     1634444'.
     164    textView cursorLine:2 col: 1.
     165
     166    textViewInteractor type:#ShiftDown.
     167    self assert: textView selectionStartCol == 1.
     168    self assert: textView selectionEndCol == 0.
     169    textViewInteractor type:#Tab.
     170    self assert: textView contents = '1111
     171    2222
     1723333
     1734444
     174'.
     175    self assert: textView selectionStartCol == 1.
     176    self assert: textView selectionEndCol == 0.
     177
     178    "Created: / 11-10-2017 / 22:29:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     179!
     180
     181test_issue130_01b
     182    "
     183    Test indenting code by Tab. Scenario:
     184        1. Position code to beggining of a line 2.
     185        2. Select 2 libes by pression Shift-Down twice so that 'cursor' is before first character on line 4.
     186        3. Press Tab
     187
     188    Check that only line 2 and 3 have been indented.
     189    Check, that selection has not been changed
     190
     191    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/130
     192    "   
     193    textView contents:'1111
     1942222
     1953333
     1964444'.
     197    textView cursorLine:2 col: 1.
     198
     199    textViewInteractor type:#ShiftDown.
     200    textViewInteractor type:#ShiftDown.
     201    self assert: textView selectionStartCol == 1.
     202    self assert: textView selectionEndCol == 0.   
     203    textViewInteractor type:#Tab.
     204    self assert: textView contents = '1111
     205    2222
     206    3333
     2074444
     208'.
     209    self assert: textView selectionStartCol == 1.
     210    self assert: textView selectionEndCol == 0.
     211
     212    "Created: / 11-10-2017 / 22:30:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     213!
     214
     215test_issue130_01c
     216    "
     217    Test indenting code by Tab. Like 01b but uses tab width of 8 spaces.
     218        1. Position code to beggining of a line 2.
     219        2. Select 2 libes by pression Shift-Down twice so that 'cursor' is before first character on line 4.
     220        3. Press Tab
     221
     222    Check that only line 2 and 3 have been indented.
     223    Check, that selection has not been changed
     224
     225    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/130
     226    "   
     227    textView setTabPositions: ListView tab8Positions.
     228    textView contents:'1111
     2292222
     2303333
     2314444'.
     232    textView cursorLine:2 col: 1.
     233
     234    textViewInteractor type:#ShiftDown.
     235    textViewInteractor type:#ShiftDown.
     236    self assert: textView selectionStartCol == 1.
     237    self assert: textView selectionEndCol == 0.   
     238    textViewInteractor type:#Tab.
     239    self assert: textView contents = '1111
     240        2222
     241        3333
     2424444
     243'.
     244    self assert: textView selectionStartCol == 1.
     245    self assert: textView selectionEndCol == 0.
     246
     247    "Created: / 12-10-2017 / 23:18:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     248!
     249
     250test_issue130_01d
     251    "
     252    Test indenting code by Tab. Like 01b but select from ;bottom' to 'top':
     253        1. Position code to beggining of a line 4.
     254        2. Select 2 libes by pression Shift-Uo twice so that 'cursor' is before first character on line 2.
     255        3. Press Tab
     256
     257    Check that only line 3 and 4 have been indented.
     258    Check, that selection has not been changed
     259
     260    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/130
     261    "   
     262    textView contents:'1111
     2632222
     2643333
     2654444'.
     266    textView cursorLine:5 col: 1.
     267
     268    textViewInteractor type:#ShiftUp.
     269    textViewInteractor type:#ShiftUp.
     270    self assert: textView selectionStartCol == 1.
     271    self assert: textView selectionEndCol == 0.   
     272    textViewInteractor type:#Tab.
     273    self assert: textView contents = '1111
     2742222
     275    3333
     276    4444
     277'.
     278    self assert: textView selectionStartCol == 1.
     279    self assert: textView selectionEndCol == 0.
     280
     281    "Created: / 12-10-2017 / 23:26:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     282    "Modified: / 12-10-2017 / 23:28:10 / jv"
     283!
     284
     285test_issue130_02a
     286    "
     287    Test indenting code by Tab. Scenario:
     288        1. Position code to the middle of line 2
     289        2. Select a line by pression Shift-Down so the end of the selection is in
     290           the middle of line 3
     291        3. Press Tab
     292
     293    Check that lines 2 and 3 have been indented.
     294    Check that selection has been 'indented' too.
     295
     296    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/130
     297    "   
     298    textView contents:'1111
     2992222
     3003333
     3014444'.
     302    textView cursorLine:2 col: 3.
     303
     304    textViewInteractor type:#ShiftDown.
     305    self assert: textView selectionStartCol == 3.
     306    self assert: textView selectionEndCol == 2.       
     307    textViewInteractor type:#Tab.
     308    self assert: textView contents = '1111
     309    2222
     310    3333
     3114444
     312'.
     313    self assert: textView selectionStartCol == 7.
     314    self assert: textView selectionEndCol == 6.
     315
     316    "Created: / 11-10-2017 / 22:33:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     317!
     318
     319test_issue130_02b
     320    "
     321    Test indenting code by Tab. Scenario:
     322        1. Position code to the middle of line 2
     323        2. Select 2 lines by pression Shift-Down twice so the end of the selection is in
     324           the middle of line 4
     325        3. Press Tab
     326
     327    Check that lines 2 to 4 have been indented.
     328    Check that selection has been 'indented' too.
     329
     330    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/130
     331    "   
     332    textView contents:'1111
     3332222
     3343333
     3354444'.
     336    textView cursorLine:2 col: 3.
     337
     338    textViewInteractor type:#ShiftDown.
     339    textViewInteractor type:#ShiftDown.     
     340    self assert: textView selectionStartCol == 3.
     341    self assert: textView selectionEndCol == 2.         
     342    textViewInteractor type:#Tab.
     343    self assert: textView contents = '1111
     344    2222
     345    3333
     346    4444
     347'.
     348    self assert: textView selectionStartCol == 7.
     349    self assert: textView selectionEndCol == 6.
     350
     351    "Created: / 11-10-2017 / 22:34:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     352!
     353
     354test_issue130_02c
     355    "
     356    Test indenting code by Tab. Scenario:
     357        1. Position code just before first non-bwhitespace character on
     358           (already indented) line 2.
     359        2. Select 2 lines by pressing Shift-Down so the end of the selection is
     360           just before first non-bwhitespace character on (already indented) line 3.
     361        3. Press Tab
     362
     363    Check that lines 2 and 3 have been indented.
     364    Check that selection has been 'indented' too.
     365
     366    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/130
     367    "   
     368    textView contents:'1111
     369    2222
     370    3333
     3714444'.
     372    textView cursorLine:2 col: 5.
     373
     374    textViewInteractor type:#ShiftDown.
     375    self assert: textView selectionStartCol == 5.
     376    self assert: textView selectionEndCol == 4.     
     377    textViewInteractor type:#Tab.
     378    self assert: textView contents = '1111
     379        2222
     380        3333
     3814444
     382'.
     383    self assert: textView selectionStartCol == 9.
     384    self assert: textView selectionEndCol == 8.
     385
     386    "Created: / 11-10-2017 / 22:35:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    140387! !
    141388
    142389!EditTextViewTests class methodsFor:'documentation'!