Ticket #124: libwidg_fix_2_of_2_rev_68542cb0ed12_Issue__124__Fixed_problem_with_leftovers_after_undo_when_pasted_text_has_tabs.patch

File libwidg_fix_2_of_2_rev_68542cb0ed12_Issue__124__Fixed_problem_with_leftovers_after_undo_when_pasted_text_has_tabs.patch, 6.2 KB (added by jan vrany, 7 years ago)
  • EditTextView.st

    # HG changeset patch
    # User Jan Vrany <jan.vrany@fit.cvut.cz>
    # Date 1490171644 0
    #      Wed Mar 22 08:34:04 2017 +0000
    # Branch jv
    # Node ID 68542cb0ed123f520669ff69d560285dc99f1de3
    # Parent  bb1f1b7dccbc3fdf571c2ba887f99d415ce47977
    Issue #124: Fixed problem with leftovers after undo when pasted text has tabs
    
    This was caused by the fact that `#basicWithoutRedrawInsert...` expanded tabs
    by but it's caller (`#withoutRedrawInsert...`) created undo action based on
    size of original (unexpanded) string.
    
    So, we need to compute end column of undo delete-range action taking
    tab expansion into an account - the computation is done in new method
    `ListView >> #withTabs:computeSizeOf:startCol:`.
    
    diff -r bb1f1b7dccbc -r 68542cb0ed12 EditTextView.st
    a b  
    45304530    ].
    45314531!
    45324532
    4533 withoutRedrawInsertStringWithoutCRs:aString atLine:lineNr col:colNr
     4533withoutRedrawInsertStringWithoutCRs:string atLine:lineNr col:colNr
    45344534    "insert aString (which has no crs) at lineNr/colNr"
    45354535
    4536     self basicWithoutRedrawInsertStringWithoutCRs:aString atLine:lineNr col:colNr.
    4537     self addUndo:(DeleteRange line1:lineNr col1:colNr line2:lineNr col2:colNr+aString size-1 info:'insert').
     4536    | col2Nr |
     4537
     4538    self basicWithoutRedrawInsertStringWithoutCRs:string atLine:lineNr col:colNr.
     4539
     4540    col2Nr := self withTabs:ListView tab8Positions computeSizeOf:string startCol: colNr.
     4541    self addUndo:(DeleteRange line1:lineNr col1:colNr line2:lineNr col2:col2Nr info:'insert').
     4542
     4543    "Modified: / 22-03-2017 / 08:24:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    45384544!
    45394545
    45404546wrapLines
     
    51725178        newLine := self withTabs:(ListView tab8Positions) expand:newLine
    51735179    ].
    51745180
    5175     self basicListAt:lineNr put:(newLine ifNil:[newLine] ifNotNil:[newLine asSingleByteStringIfPossible]).
     5181    self basicListAt:lineNr put:(newLine isNil ifTrue:[newLine] ifFalse:[newLine asSingleByteStringIfPossible]).
    51765182    widthOfWidestLine notNil ifTrue:[
    51775183        widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:newLine).
    51785184    ].
    51795185    self textChanged.
    51805186
    51815187    "Modified: / 25-01-2012 / 00:37:29 / cg"
     5188    "Modified: / 21-03-2017 / 22:25:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    51825189! !
    51835190
    51845191!EditTextView methodsFor:'event handling'!
  • ListView.st

    diff -r bb1f1b7dccbc -r 68542cb0ed12 ListView.st
    a b  
    52335233    "Modified: 23.2.1996 / 19:10:36 / cg"
    52345234!
    52355235
     5236withTabs:tabulatorTable computeSizeOf:line startCol: startCol
     5237    "Expand tabs into spaces, return a SIZE of a `line` if
     5238     pasted after startCol.
     5239
     5240     BIG FAT WARNING: If you change this method, please make
     5241     sure it is in sync with #withTabs:expans: otherwise the
     5242     undo may break.
     5243
     5244     See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124
     5245     "
     5246
     5247
     5248    | dstIndex   "{ Class: SmallInteger }" |
     5249
     5250    line isNil ifTrue:[^ 0].
     5251    (line occurrencesOf: Character tab) == 0 ifTrue:[ ^ startCol + line size - 1 ].
     5252    dstIndex := startCol.
     5253    line do:[:character |
     5254        (character == (Character tab)) ifTrue:[
     5255            dstIndex := self nextTabAfter:dstIndex in:tabulatorTable.
     5256        ] ifFalse:[
     5257            dstIndex := dstIndex + 1
     5258        ].
     5259        "make stc-optimizer happy
     5260         - no need to return value of ifTrue:/ifFalse above"
     5261        0
     5262    ].
     5263    ^ dstIndex - 1.
     5264
     5265    "Created: / 22-03-2017 / 08:17:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     5266!
     5267
    52365268withTabs:tabulatorTable expand:line
    5237     "expand tabs into spaces, return a new line string,
     5269    "Expand tabs into spaces, return a new line string,
    52385270     or original line, if no tabs are included.
    52395271     good idea, to make this one a primitive, since it is called
    5240      many times if a big text is read from a file."
     5272     many times if a big text is read from a file.
     5273
     5274     BIG FAT WARNING: If you change this method, please make
     5275     sure it is in sync with #withTabs:computeSizeOf:startCol:
     5276     otherwise the undo may break.
     5277
     5278     See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124
     5279    "
    52415280
    52425281    |tmpString nString nTabs
    52435282     currentMax "{ Class: SmallInteger }"
     
    52595298    tmpString := line species new:currentMax.
    52605299    dstIndex := 1.
    52615300    line do:[:character |
    5262         (character == (Character tab)) ifTrue:[
    5263             nextTab := self nextTabAfter:dstIndex in:tabulatorTable.
    5264             [dstIndex < nextTab] whileTrue:[
    5265                 tmpString at:dstIndex put:(Character space).
    5266                 dstIndex := dstIndex + 1
    5267             ]
    5268         ] ifFalse:[
    5269             tmpString at:dstIndex put:character.
    5270             dstIndex := dstIndex + 1
    5271         ].
    5272         (dstIndex > currentMax) ifTrue:[
    5273             "
    5274              this cannot happen with <= 8 tabs
    5275             "
    5276             currentMax := currentMax + currentMax.
    5277             nString := line species new:currentMax.
    5278             nString replaceFrom:1 to:(dstIndex - 1)
    5279                            with:tmpString startingAt:1.
    5280             tmpString := nString.
    5281             nString := nil
    5282         ].
    5283 
    5284         "make stc-optimizer happy
    5285         - no need to return value of ifTrue:/ifFalse above"
    5286         0
     5301        (character == (Character tab)) ifTrue:[
     5302            nextTab := self nextTabAfter:dstIndex in:tabulatorTable.
     5303            [dstIndex < nextTab] whileTrue:[
     5304                tmpString at:dstIndex put:(Character space).
     5305                dstIndex := dstIndex + 1
     5306            ]
     5307        ] ifFalse:[
     5308            tmpString at:dstIndex put:character.
     5309            dstIndex := dstIndex + 1
     5310        ].
     5311        (dstIndex > currentMax) ifTrue:[
     5312            "
     5313             this cannot happen with <= 8 tabs
     5314            "
     5315            currentMax := currentMax + currentMax.
     5316            nString := line species new:currentMax.
     5317            nString replaceFrom:1 to:(dstIndex - 1)
     5318                           with:tmpString startingAt:1.
     5319            tmpString := nString.
     5320            nString := nil
     5321        ].
     5322
     5323        "make stc-optimizer happy
     5324        - no need to return value of ifTrue:/ifFalse above"
     5325        0
    52875326    ].
    52885327    dstIndex := dstIndex - 1.
    52895328    dstIndex == currentMax ifTrue:[
    5290         ^ tmpString
     5329        ^ tmpString
    52915330    ].
    52925331    ^ tmpString copyTo:dstIndex
    52935332
    5294     "Modified: 23.2.1996 / 19:11:01 / cg"
     5333    "Modified: / 23-02-1996 / 19:11:01 / cg"
     5334    "Modified (comment): / 22-03-2017 / 08:36:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    52955335!
    52965336
    52975337withTabsExpanded:line