TextView.st
changeset 6456 c01624d73342
parent 6454 64f4dc5b8c5a
child 6459 070961cd245f
equal deleted inserted replaced
6455:e761c8425f5d 6456:c01624d73342
  1627     "
  1627     "
  1628      special - if clicked on a parenthesis, select to matching
  1628      special - if clicked on a parenthesis, select to matching
  1629      (must de before doing the ST80 stuff below)
  1629      (must de before doing the ST80 stuff below)
  1630     "
  1630     "
  1631     ((sel := self selection) size == 1
  1631     ((sel := self selection) size == 1
  1632     and:[(sel := sel at:1) size == 1]) ifTrue:[
  1632      and:[(sel := sel at:1) size == 1]) ifTrue:[
  1633         ch := sel at:1.
  1633         ch := sel at:1.
  1634 
  1634 
  1635         ((self isOpeningParenthesis:ch)
  1635         ((self isOpeningParenthesis:ch)
  1636         or:[ (self isClosingParenthesis:ch) ]) ifTrue:[
  1636          or:[self isClosingParenthesis:ch]) ifTrue:[
  1637             self
  1637             self
  1638                 searchForMatchingParenthesisFromLine:selectionStartLine col:selectionStartCol
  1638                 searchForMatchingParenthesisFromLine:selectionStartLine col:selectionStartCol
  1639                 ifFound:[:line :col |
  1639                 ifFound:[:line :col |
  1640                               |prevLine prevCol moveBack pos1|
  1640                               |prevLine prevCol moveBack pos1|
  1641 
  1641 
  1796     ]
  1796     ]
  1797 
  1797 
  1798     "Created: / 11-09-1997 / 04:12:55 / cg"
  1798     "Created: / 11-09-1997 / 04:12:55 / cg"
  1799     "Modified: / 14-06-2011 / 14:04:59 / cg"
  1799     "Modified: / 14-06-2011 / 14:04:59 / cg"
  1800     "Modified (format): / 13-02-2017 / 20:32:08 / cg"
  1800     "Modified (format): / 13-02-2017 / 20:32:08 / cg"
       
  1801     "Modified (format): / 18-10-2018 / 17:06:07 / Stefan Vogel"
  1801 !
  1802 !
  1802 
  1803 
  1803 extendSelectionToX:x y:y
  1804 extendSelectionToX:x y:y
  1804     "mouse-move while button was pressed - handle selection changes"
  1805     "mouse-move while button was pressed - handle selection changes"
  1805 
  1806 
  4474      col    "{ Class: SmallInteger }"
  4475      col    "{ Class: SmallInteger }"
  4475      delta  "{ Class: SmallInteger }"
  4476      delta  "{ Class: SmallInteger }"
  4476      endCol "{ Class: SmallInteger }"
  4477      endCol "{ Class: SmallInteger }"
  4477      runCol "{ Class: SmallInteger }"
  4478      runCol "{ Class: SmallInteger }"
  4478      cc prevCC nextCC incSet decSet
  4479      cc prevCC nextCC incSet decSet
  4479      nesting "{ Class: SmallInteger }"
  4480      nesting 
  4480      maxLine "{ Class: SmallInteger }"
  4481      maxLine "{ Class: SmallInteger }"
  4481      ign skip anySet
  4482      ign skip anySet
  4482      eol1 eol2|
  4483      eol1 eol2 inLineComment idx|
  4483 
  4484 
  4484     self assert:(openingCharacters size == closingCharacters size).
  4485     self assert:(openingCharacters size == closingCharacters size).
  4485 
  4486 
  4486     charSet := openingCharacters , closingCharacters.
  4487     charSet := openingCharacters , closingCharacters.
  4487 
  4488 
  4491         ^ failBlock value   "not a parenthesis"
  4492         ^ failBlock value   "not a parenthesis"
  4492     ].
  4493     ].
  4493 
  4494 
  4494     direction := (i <= openingCharacters size) ifTrue:[#fwd] ifFalse:[#bwd].
  4495     direction := (i <= openingCharacters size) ifTrue:[#fwd] ifFalse:[#bwd].
  4495     closingChar := (closingCharacters , openingCharacters) at:i.
  4496     closingChar := (closingCharacters , openingCharacters) at:i.
       
  4497 
       
  4498     "nesting is a Stack containing {expected char . line number of found char} tuples"
       
  4499     nesting := Stack new.
       
  4500     nesting push:{closingChar. startLine}.
  4496 
  4501 
  4497     eol1 := eolCommentSequence at:1 ifAbsent:nil.
  4502     eol1 := eolCommentSequence at:1 ifAbsent:nil.
  4498     eol2 := eolCommentSequence at:2 ifAbsent:nil.
  4503     eol2 := eolCommentSequence at:2 ifAbsent:nil.
  4499 
  4504 
  4500     col := startCol.
  4505     col := startCol.
  4510     ].
  4515     ].
  4511     anySet := Set new.
  4516     anySet := Set new.
  4512     anySet addAll:incSet; addAll:decSet; addAll:ignoreSet.
  4517     anySet addAll:incSet; addAll:decSet; addAll:ignoreSet.
  4513     anySet := (anySet select:[:c | c isCharacter]) asString.
  4518     anySet := (anySet select:[:c | c isCharacter]) asString.
  4514 
  4519 
  4515     nesting := 1.
       
  4516     ignoring := false.
  4520     ignoring := false.
  4517     lineString := list at:line.
  4521     lineString := list at:line.
  4518     maxLine := list size.
  4522     maxLine := list size.
  4519 
  4523 
  4520     col := col + delta.
  4524     col := col + delta.
  4521     [nesting ~~ 0] whileTrue:[
  4525     [nesting notEmpty] whileTrue:[
  4522         (lineString notNil
  4526         (lineString notNil and:[lineString includesAny:anySet]) ifTrue:[
  4523         and:[lineString includesAny:anySet]) ifTrue:[
  4527             inLineComment := false.
  4524             direction == #fwd ifTrue:[
  4528             direction == #fwd ifTrue:[
  4525                 endCol := lineString size.
  4529                 endCol := lineString size.
  4526             ] ifFalse:[
  4530             ] ifFalse:[
  4527                 endCol := 1
  4531                 endCol := 1
  4528             ].
  4532             ].
  4529 
  4533 
  4530             col to:endCol by:delta do:[:rCol |
  4534             col to:endCol by:delta do:[:rCol |
  4531                 runCol := rCol.
  4535                 runCol := rCol.
  4532 
       
  4533                 cc := lineString at:runCol.
  4536                 cc := lineString at:runCol.
  4534                 runCol < lineString size ifTrue:[
  4537                 runCol < lineString size ifTrue:[
  4535                     nextCC := lineString at:runCol+1
  4538                     nextCC := lineString at:runCol+1
  4536                 ] ifFalse:[
  4539                 ] ifFalse:[
  4537                     nextCC := nil
  4540                     nextCC := nil
  4542                     prevCC := nil
  4545                     prevCC := nil
  4543                 ].
  4546                 ].
  4544 
  4547 
  4545                 ign := skip := false.
  4548                 ign := skip := false.
  4546 
  4549 
  4547                 "/ check for comments.
  4550                 (cc == eol1 and:[nextCC == eol2]) ifTrue:[
  4548 
  4551                     "/ check for comments, do not search for a matching '"' in a "/ comment.
  4549                 ((cc == eol1 and:[nextCC == eol2])
  4552                     inLineComment := skip := true.
  4550                 or:[prevCC == $$ ]) ifTrue:[
  4553                     [nesting top second = line] whileTrue:[
  4551                     "/ do nothing
  4554                         "while doing backward searching we have found a line comment
  4552 
  4555                          containing a opening/closing char"
       
  4556                         nesting pop.
       
  4557                     ].
       
  4558                 ] ifFalse:[prevCC == $$ ifTrue:[
       
  4559                     "/ do not search for a matching peer for $( or $[...
  4553                     skip := true.
  4560                     skip := true.
  4554                 ] ifFalse:[
  4561                 ] ifFalse:[
  4555                     ignoreSet do:[:ignore |
  4562                     ignoreSet do:[:eachCharToIgnore |
  4556                         ignore == cc ifTrue:[
  4563                         eachCharToIgnore == cc ifTrue:[
  4557                             ign := true
  4564                             ign := true
  4558                         ] ifFalse:[
  4565                         ] ifFalse:[
  4559                             ignore isString ifTrue:[
  4566                             eachCharToIgnore isString ifTrue:[
  4560                                 cc == (ignore at:2) ifTrue:[
  4567                                 cc == (eachCharToIgnore at:2) ifTrue:[
  4561                                     runCol > 1 ifTrue:[
  4568                                     runCol > 1 ifTrue:[
  4562                                         (lineString at:(runCol-1)) == (ignore at:1) ifTrue:[
  4569                                         (lineString at:(runCol-1)) == (eachCharToIgnore at:1) ifTrue:[
  4563                                             skip := true
  4570                                             skip := true
  4564                                         ]
  4571                                         ]
  4565                                     ]
  4572                                     ]
  4566                                 ] ifFalse:[
  4573                                 ] ifFalse:[
  4567                                     cc == (ignore at:1) ifTrue:[
  4574                                     cc == (eachCharToIgnore at:1) ifTrue:[
  4568                                         runCol < lineString size ifTrue:[
  4575                                         runCol < lineString size ifTrue:[
  4569                                             (lineString at:(runCol+1)) == (ignore at:2) ifTrue:[
  4576                                             (lineString at:(runCol+1)) == (eachCharToIgnore at:2) ifTrue:[
  4570                                                 skip := true
  4577                                                 skip := true
  4571                                             ]
  4578                                             ]
  4572                                         ]
  4579                                         ]
  4573                                     ]
  4580                                     ]
  4574                                 ]
  4581                                 ]
  4575                             ]
  4582                             ]
  4576                         ]
  4583                         ]
  4577                     ]
  4584                     ]
       
  4585                 ]].
       
  4586 
       
  4587                 (inLineComment not & ign) ifTrue:[
       
  4588                     "/ íf in a line comment, single ' and " may occur.
       
  4589                     "/ ignoring means, that we ignore non-matching peers.
       
  4590                     ignoring ifTrue:[
       
  4591                         nesting pop first ~= cc ifTrue:[
       
  4592                             ^ failBlock value.
       
  4593                         ].
       
  4594                         ignoring := false.
       
  4595                     ] ifFalse:[
       
  4596                         nesting push:{cc . line}.
       
  4597                         ignoring := true.
       
  4598                     ].
  4578                 ].
  4599                 ].
  4579 
  4600 
  4580                 ign ifTrue:[
  4601                 (ignoring | skip | inLineComment) ifFalse:[
  4581                     ignoring := ignoring not
  4602                     ((idx := incSet indexOf:cc) ~~0) ifTrue:[
  4582                 ].
  4603                         nesting push:{(decSet at:idx). line}.
  4583 
  4604                     ] ifFalse:[
  4584                 ignoring ifFalse:[
  4605                         (decSet includes:cc) ifTrue:[
  4585                     skip ifFalse:[
  4606                             nesting pop first ~= cc ifTrue:[
  4586                         (incSet includes:cc) ifTrue:[
  4607                                 ^ failBlock value.
  4587                             nesting := nesting + 1
  4608                             ].
  4588                         ] ifFalse:[
       
  4589                             (decSet includes:cc) ifTrue:[
       
  4590                                 nesting := nesting - 1
       
  4591                             ]
       
  4592                         ]
  4609                         ]
  4593                     ]
  4610                     ]
  4594                 ].
  4611                 ].
  4595 
  4612 
  4596                 nesting == 0 ifTrue:[
  4613                 nesting isEmpty ifTrue:[
  4597                     "check if legal"
       
  4598                     skip ifFalse:[
  4614                     skip ifFalse:[
  4599                         cc == closingChar ifFalse:[
       
  4600                             ^ failBlock value
       
  4601                         ].
       
  4602                         ^ foundBlock value:line value:runCol.
  4615                         ^ foundBlock value:line value:runCol.
  4603                     ]
  4616                     ]
  4604                 ]
  4617                 ].
  4605             ].
  4618             ].
  4606         ].
  4619         ].
  4607         line := line + delta.
  4620         line := line + delta.
  4608         (line < 1 or:[line > maxLine]) ifTrue:[
  4621         (line < 1 or:[line > maxLine]) ifTrue:[
  4609             ^ failBlock value
  4622             ^ failBlock value
  4617     ].
  4630     ].
  4618     ^ notFoundBlock value
  4631     ^ notFoundBlock value
  4619 
  4632 
  4620     "Modified: / 15-10-1996 / 12:22:30 / cg"
  4633     "Modified: / 15-10-1996 / 12:22:30 / cg"
  4621     "Modified (comment): / 13-02-2017 / 20:32:43 / cg"
  4634     "Modified (comment): / 13-02-2017 / 20:32:43 / cg"
       
  4635     "Modified (format): / 18-10-2018 / 18:42:55 / Stefan Vogel"
  4622 !
  4636 !
  4623 
  4637 
  4624 searchFwd
  4638 searchFwd
  4625     "search forward for the same pattern or selection again"
  4639     "search forward for the same pattern or selection again"
  4626 
  4640