Faculty of Information Technology
Software Engineering Group

Ticket #162: libwidg_fix_1_of_1_rev_dbfcd6a6cf68_Issue__162__ListView__contents_returns_CR_in_a_String_by_default.patch

File libwidg_fix_1_of_1_rev_dbfcd6a6cf68_Issue__162__ListView__contents_returns_CR_in_a_String_by_default.patch, 12.8 KB (added by Patrik Svestka, 2 years ago)

Fixing the CR at the EditTextView?

  • ListView.st

    # HG changeset patch
    # User Patrik Svestka <patrik.svestka@gmail.com>
    # Date 1500273130 -7200
    #      Mon Jul 17 08:32:10 2017 +0200
    # Branch jv
    # Node ID dbfcd6a6cf68df5c52601edd9b5c3a2cc76aa6e1
    # Parent  bfbeb793ace5104cdb34ac43855ce5454bb4b41c
    Issue #162: ListView>>contents returns CR in a String by default
    
    ListView>>contents automatically added CR at the end of StringCollection.  Now user
    has to specify if the line should end with CRLF or just CR.
    
    This patch fixes such situation.
    
    
     e.g. example Test code:
     test_02d
        textView contents:'This text is to continue    '.
        textView setCursorCol:25.
    
        textViewInteractor type: #BasicDelete.
        self assert:textView contents asString = 'This text is to continue   '.
    
    now correctly runs.
    
    https://swing.fit.cvut.cz/projects/stx-jv/ticket/162
    
    diff -r bfbeb793ace5 -r dbfcd6a6cf68 ListView.st
    a b  
    2020                fontIsFixedWidth fontWidth autoScroll autoScrollBlock
    2121                autoScrollDeltaT wordCheck includesNonStrings widthOfWidestLine
    2222                listMsg viewOrigin listChannel backgroundAlreadyClearedColor
    23                 scrollWhenUpdating scrollLocked lineEndCRLF highlightAreas
    24                 compareModelOnUpdate expandTabsWhenUpdating
     23                scrollWhenUpdating scrollLocked lineEndCRLF lineEndCR
     24                highlightAreas compareModelOnUpdate expandTabsWhenUpdating
    2525                checkLineEndConventionWhenUpdating
    2626                checkedLinesForWidthOfContentsComputation'
    2727        classVariableNames:'DefaultForegroundColor DefaultBackgroundColor DefaultTabPositions
     
    545545     somewhat to indented from the 3D border."
    546546
    547547    ^ height - (2 * margin) - topMargin
     548!
     549
     550
     551lineEndCR: aBoolean
     552    lineEndCR := aBoolean
     553
     554    "Created: / 17-07-2017 / 12:45:34 / svestkap"
     555!
     556
     557lineEndCRLF: aBoolean
     558    lineEndCRLF := aBoolean
     559
     560    "Created: / 17-07-2017 / 14:17:54 / svestkap"
    548561! !
    549562
    550563!ListView methodsFor:'accessing-behavior'!
     
    679692     Otherwise 'Character cr' is the line end (which is LF in unix)"
    680693
    681694    ^ lineEndCRLF ? false
    682 
    683     "Created: / 04-07-2006 / 19:05:01 / fm"
     695!
     696
     697lineEndCR
     698    "answer true if CRLF is not specified for the line end.
     699     'Character cr' is LF in unix"
     700
     701    ^ lineEndCR ? true
    684702!
    685703
    686704scrollWhenUpdating
     
    944962    list isNil ifTrue:[^ ''].
    945963
    946964    self lineEndCRLF ifTrue:[
    947         lineEnd := String crlf.
     965        lineEnd := String crlf.
    948966    ] ifFalse:[
    949         lineEnd := Character cr.
     967        self lineEndCR ifTrue:[
     968            lineEnd := Character cr.
     969        ].
    950970    ].
    951971
    952972    stringCollection := list asStringCollection.
    953973    ^ stringCollection
    954         asStringWith:lineEnd
    955         from:1 to:stringCollection size
    956         compressTabs:false
    957         final:lineEnd
     974        asStringWith:lineEnd
     975        from:1 to:stringCollection size
     976        compressTabs:false
     977        final:lineEnd
    958978
    959979    "Modified: / 04-07-2006 / 19:18:47 / fm"
     980    "Modified: / 14-07-2017 / 11:27:20 / svestkap"
    960981!
    961982
    962983contents:something
     
    26042625    partialLines := true.
    26052626    tabPositions := UserDefaultTabPositions ? self class defaultTabPositions.
    26062627    includesNonStrings := false.
    2607     lineEndCRLF := false.
    26082628    checkedLinesForWidthOfContentsComputation := nil."/ i.e. all
    26092629    self getFontParameters.
    26102630    self initializeWordCheckAction.
     
    26172637    autoScroll := true.
    26182638
    26192639    "Modified: / 03-07-2006 / 17:03:59 / cg"
     2640    "Modified: / 19-07-2017 / 11:28:01 / svestkap"
    26202641!
    26212642
    26222643initializeWordCheckAction
  • tests/EditTextViewTests.st

    diff -r bfbeb793ace5 -r dbfcd6a6cf68 tests/EditTextViewTests.st
    a b  
    1 "{ Package: 'stx:libwidg/tests' }"
    2 
    3 "{ NameSpace: Smalltalk }"
    4 
    5 TestCase subclass:#EditTextViewTests
    6         instanceVariableNames:'textView textViewInteractor'
    7         classVariableNames:''
    8         poolDictionaries:''
    9         category:'Views-Text-Tests'
    10 !
    11 
    12 
    13 !EditTextViewTests methodsFor:'running'!
    14 
    15 setUp
    16     | topView |
    17 
    18     Smalltalk loadPackage: 'stx:goodies/sunit/ext/ui'.
    19 
    20     topView := StandardSystemView new.
    21     topView extent: 320 @ 200.
    22     topView label: self printString.
    23     textView := EditTextView origin: 0.0@0.0 extent: 1.0@1.0 in: topView.
    24     textViewInteractor := textView interactor.
    25 
    26 
    27     topView open.
    28     topView waitUntilVisible.
    29 
    30     "Created: / 23-07-2014 / 07:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    31     "Modified: / 24-02-2015 / 08:22:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    32 !
    33 
    34 tearDown
    35     textView topView destroy.
    36 
    37     "Created: / 23-07-2014 / 07:17:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    38     "Modified: / 24-02-2015 / 08:17:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    39 ! !
    40 
    41 !EditTextViewTests methodsFor:'tests'!
    42 
    43 test_01
    44     textView contents: 'Hello, here is Smalltalk X'.
    45     textView setCursorCol: 14.
    46 
    47     textViewInteractor type: #SelectWord.
    48     self assert: textView selectionAsString = 'is'.
    49 
    50     textViewInteractor type: #CtrlShiftCursorRight.
    51     textViewInteractor type: #CtrlShiftCursorRight.
    52 
    53     self assert: textView selectionAsString = 'is Smalltalk '.
    54  
    55     "Created: / 24-02-2015 / 08:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    56 !
    57 
    58 test_issue124_case1_01
    59     "
    60     See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
    61     "   
    62 
    63     textView contents:'1234'.
    64     textView setCursorCol:3.
    65     textView selectToEndOfLine.
    66     self assert:textView selectionAsString = '34'.
    67     textView setClipboardText:'Smalltalk'.
    68     textViewInteractor type:#Paste.
    69     self assert:textView selectionAsString = 'Smalltalk'.
    70     self assert:textView contents asString = ('12Smalltalk' , Character cr).
    71     textViewInteractor type:#Undo.
    72     self assert:textView contents asString = ('1234' , Character cr).
    73 
    74     "Created: / 17-03-2017 / 09:46:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    75     "Modified (comment): / 04-05-2017 / 22:31:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    76 !
    77 
    78 test_issue124_case1_02
    79     "
    80     See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
    81     "
    82 
    83     textView contents:'1234'.
    84     textView setCursorCol:3.
    85     textView selectToEndOfLine.
    86     self assert:textView selectionAsString = '34'.
    87     textView setClipboardText:'1-LINEA
    88 2-LINEB
    89 3-LINEC
    90 '.
    91     textViewInteractor type:#Paste.
    92     self assert:textView selectionAsString = '1-LINEA
    93 2-LINEB
    94 3-LINEC
    95 '.
    96     self assert:textView contents asString = ('121-LINEA
    97 2-LINEB
    98 3-LINEC
    99 ').
    100     textViewInteractor type:#Undo.
    101     self assert:textView contents asString = ('1234' , Character cr).
    102 
    103     "Created: / 17-03-2017 / 09:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    104     "Modified: / 17-03-2017 / 14:13:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    105     "Modified (comment): / 04-05-2017 / 22:31:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    106 !
    107 
    108 test_issue124_case1_04
    109     "
    110     See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
    111     "
    112     textViewInteractor type:'1234'.
    113     self assert:textView contents asString = ('1234' , Character cr).
    114     textViewInteractor type:#Undo.
    115     self assert:textView contents asString = ('' , Character cr).
    116 
    117     "Created: / 17-03-2017 / 21:42:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    118     "Modified (comment): / 04-05-2017 / 22:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    119 !
    120 
    121 test_issue124_case1_05
    122     "
    123     See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
    124     "
    125 
    126     textViewInteractor type:'1234'.
    127     self assert:textView contents asString = ('1234' , Character cr).
    128     textView setClipboardText:'Blah blag'.
    129     textViewInteractor type:#Paste.
    130     self assert:textView contents asString = ('1234Blah blag' , Character cr).
    131     textViewInteractor type:#Undo.
    132     self assert:textView contents asString = ('1234' , Character cr).
    133     textViewInteractor type:#Undo.
    134     self assert:textView contents asString = ('' , Character cr).
    135 
    136     "Created: / 17-03-2017 / 22:43:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    137     "Modified (comment): / 04-05-2017 / 22:32:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    138 ! !
    139 
    140 !EditTextViewTests class methodsFor:'documentation'!
    141 
    142 version_HG
    143 
    144     ^ '$Changeset: <not expanded> $'
    145 ! !
    146 
     1'From Smalltalk/X jv-branch, Version:6.2.6.0 on 21-07-2017 at 12:31:21 PM'      !
     2
     3"{ Package: 'stx:libwidg/tests' }"
     4
     5"{ NameSpace: Smalltalk }"
     6
     7TestCase subclass:#EditTextViewTests
     8        instanceVariableNames:'textView textViewInteractor'
     9        classVariableNames:''
     10        poolDictionaries:''
     11        category:'Views-Text-Tests'
     12!
     13
     14
     15!EditTextViewTests methodsFor:'running'!
     16
     17setUp
     18    | topView |
     19
     20    Smalltalk loadPackage: 'stx:goodies/sunit/ext/ui'.
     21
     22    topView := StandardSystemView new.
     23    topView extent: 320 @ 200.
     24    topView label: self printString.
     25    textView := EditTextView origin: 0.0@0.0 extent: 1.0@1.0 in: topView.
     26    textViewInteractor := textView interactor.
     27    textView lineEndCR: false.
     28
     29    topView open.
     30    topView waitUntilVisible.
     31
     32    "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>"
     34    "Modified: / 21-07-2017 / 11:58:32 / svestkap"
     35!
     36
     37tearDown
     38    textView topView destroy.
     39
     40    "Created: / 23-07-2014 / 07:17:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     41    "Modified: / 24-02-2015 / 08:17:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     42! !
     43
     44!EditTextViewTests methodsFor:'tests'!
     45
     46test_01
     47    textView contents: 'Hello, here is Smalltalk X'.
     48    textView setCursorCol: 14.
     49
     50    textViewInteractor type: #SelectWord.
     51    self assert: textView selectionAsString = 'is'.
     52
     53    textViewInteractor type: #CtrlShiftCursorRight.
     54    textViewInteractor type: #CtrlShiftCursorRight.
     55
     56    self assert: textView selectionAsString = 'is Smalltalk '.
     57 
     58    "Created: / 24-02-2015 / 08:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     59!
     60
     61test_issue124_case1_01
     62    "
     63    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
     64    "   
     65
     66    textView contents:'1234'.
     67    textView setCursorCol:3.
     68    textView selectToEndOfLine.
     69    self assert:textView selectionAsString = '34'.
     70    textView setClipboardText:'Smalltalk'.
     71    textViewInteractor type:#Paste.
     72    self assert:textView selectionAsString = 'Smalltalk'.
     73    self assert:textView contents asString = '12Smalltalk'.
     74    textViewInteractor type:#Undo.
     75    self assert:textView contents asString = '1234'.
     76
     77    "Created: / 17-03-2017 / 09:46:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     78    "Modified (comment): / 04-05-2017 / 22:31:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     79    "Modified: / 21-07-2017 / 12:07:59 / svestkap"
     80!
     81
     82test_issue124_case1_02
     83    "
     84    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
     85    "
     86    textView lineEndCR: true. 
     87    textView contents:'1234'.
     88    textView setCursorCol:3.
     89    textView selectToEndOfLine.
     90    self assert:textView selectionAsString = '34'.
     91    textView setClipboardText:'1-LINEA
     922-LINEB
     933-LINEC
     94'.
     95    textViewInteractor type:#Paste.
     96    self assert:textView selectionAsString = '1-LINEA
     972-LINEB
     983-LINEC
     99'.
     100    self assert:textView contents asString = ('121-LINEA
     1012-LINEB
     1023-LINEC
     103').
     104    textView lineEndCR: false. 
     105    textViewInteractor type:#Undo.
     106    self assert:textView contents asString = '1234'.
     107
     108    "Created: / 17-03-2017 / 09:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     109    "Modified: / 17-03-2017 / 14:13:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     110    "Modified (comment): / 04-05-2017 / 22:31:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     111    "Modified: / 21-07-2017 / 12:09:03 / svestkap"
     112!
     113
     114test_issue124_case1_04
     115    "
     116    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
     117    "
     118    textViewInteractor type:'1234'.
     119    self assert:textView contents asString = '1234'.
     120    textViewInteractor type:#Undo.
     121    self assert:textView contents asString = ''.
     122
     123    "Created: / 17-03-2017 / 21:42:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     124    "Modified (comment): / 04-05-2017 / 22:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     125    "Modified: / 21-07-2017 / 12:09:28 / svestkap"
     126!
     127
     128test_issue124_case1_05
     129    "
     130    See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19
     131    "
     132
     133    textViewInteractor type:'1234'.
     134    self assert:textView contents asString = '1234'.
     135    textView setClipboardText:'Blah blag'.
     136    textViewInteractor type:#Paste.
     137    self assert:textView contents asString = '1234Blah blag'.
     138    textViewInteractor type:#Undo.
     139    self assert:textView contents asString = '1234'.
     140    textViewInteractor type:#Undo.
     141    self assert:textView contents asString = ''.
     142
     143    "Created: / 17-03-2017 / 22:43:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     144    "Modified (comment): / 04-05-2017 / 22:32:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     145    "Modified: / 21-07-2017 / 12:09:53 / svestkap"
     146! !
     147
     148!EditTextViewTests class methodsFor:'documentation'!
     149
     150version_HG
     151
     152    ^ '$Changeset: <not expanded> $'
     153! !
     154