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 , 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 4530 4530 ]. 4531 4531 ! 4532 4532 4533 withoutRedrawInsertStringWithoutCRs: aString atLine:lineNr col:colNr4533 withoutRedrawInsertStringWithoutCRs:string atLine:lineNr col:colNr 4534 4534 "insert aString (which has no crs) at lineNr/colNr" 4535 4535 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>" 4538 4544 ! 4539 4545 4540 4546 wrapLines … … 5172 5178 newLine := self withTabs:(ListView tab8Positions) expand:newLine 5173 5179 ]. 5174 5180 5175 self basicListAt:lineNr put:(newLine i fNil:[newLine] ifNotNil:[newLine asSingleByteStringIfPossible]).5181 self basicListAt:lineNr put:(newLine isNil ifTrue:[newLine] ifFalse:[newLine asSingleByteStringIfPossible]). 5176 5182 widthOfWidestLine notNil ifTrue:[ 5177 5183 widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:newLine). 5178 5184 ]. 5179 5185 self textChanged. 5180 5186 5181 5187 "Modified: / 25-01-2012 / 00:37:29 / cg" 5188 "Modified: / 21-03-2017 / 22:25:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" 5182 5189 ! ! 5183 5190 5184 5191 !EditTextView methodsFor:'event handling'! -
ListView.st
diff -r bb1f1b7dccbc -r 68542cb0ed12 ListView.st
a b 5233 5233 "Modified: 23.2.1996 / 19:10:36 / cg" 5234 5234 ! 5235 5235 5236 withTabs: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 5236 5268 withTabs:tabulatorTable expand:line 5237 " expand tabs into spaces, return a new line string,5269 "Expand tabs into spaces, return a new line string, 5238 5270 or original line, if no tabs are included. 5239 5271 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 " 5241 5280 5242 5281 |tmpString nString nTabs 5243 5282 currentMax "{ Class: SmallInteger }" … … 5259 5298 tmpString := line species new:currentMax. 5260 5299 dstIndex := 1. 5261 5300 line do:[:character | 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 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 5287 5326 ]. 5288 5327 dstIndex := dstIndex - 1. 5289 5328 dstIndex == currentMax ifTrue:[ 5290 5329 ^ tmpString 5291 5330 ]. 5292 5331 ^ tmpString copyTo:dstIndex 5293 5332 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>" 5295 5335 ! 5296 5336 5297 5337 withTabsExpanded:line