--- a/Tools__CodeNavigationService.st Sat Feb 15 19:36:39 2014 +0100
+++ b/Tools__CodeNavigationService.st Sat Feb 15 22:17:30 2014 +0100
@@ -67,6 +67,7 @@
"
! !
+
!CodeNavigationService class methodsFor:'accessing'!
label
@@ -525,6 +526,32 @@
!CodeNavigationService methodsFor:'private'!
+elementAtCharacterPosition: pos
+ | treeIndex low high mid midEl |
+
+ treeIndex := codeView syntaxElements.
+ treeIndex isNil ifTrue:[ ^ nil ].
+ low := 1.
+ high := treeIndex size.
+
+ [ low <= high ] whileTrue:[
+ mid := (low + high) >> 1.
+ midEl := treeIndex at: mid.
+ pos < midEl start ifTrue:[
+ high := mid - 1.
+ ] ifFalse:[
+ midEl stop < pos ifTrue:[
+ low := mid + 1.
+ ] ifFalse:[
+ ^ midEl
+ ].
+ ].
+ ].
+ ^ nil.
+
+ "Created: / 15-02-2014 / 10:14:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
elementAtCursor
^self elementAtLine: textView cursorLine col: textView cursorCol - 1
@@ -532,35 +559,13 @@
!
elementAtLine:line col:colArg
- |characterPosition syntaxElements index element col|
+ |col|
"/ if beyond end of line, do not advance into next line
col := colArg min:(textView listAt:line) size.
+ ^ self elementAtCharacterPosition: (textView characterPositionOfLine:line col:col)
- characterPosition := textView characterPositionOfLine:line col:col.
- syntaxElements := codeView syntaxElements.
- syntaxElements isEmptyOrNil ifTrue:[
- ^ nil.
- ].
- 0"1" to:0 by:-1 do:[:d |
- index := (syntaxElements indexForInserting:characterPosition) - d.
- index > syntaxElements size ifTrue:[^nil].
- element := syntaxElements at:index ifAbsent:nil.
- element notNil ifTrue:[
- (characterPosition between: element start and: element stop) ifTrue:[^element].
- ].
- index + 1 > syntaxElements size ifTrue:[^nil].
- element := syntaxElements at:index + 1 ifAbsent:nil.
- element notNil ifTrue:[
- (characterPosition between: element start and: element stop) ifTrue:[^element].
- ].
-
- ].
- ^nil
-
- "Created: / 25-06-2010 / 14:40:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 21-08-2011 / 11:03:29 / cg"
- "Modified: / 02-10-2013 / 01:22:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 15-02-2014 / 10:15:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
elementAtX:x y:y
@@ -835,14 +840,14 @@
!CodeNavigationService class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeNavigationService.st,v 1.41 2014-02-05 19:08:25 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeNavigationService.st,v 1.42 2014-02-15 21:17:30 vrany Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeNavigationService.st,v 1.41 2014-02-05 19:08:25 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__CodeNavigationService.st,v 1.42 2014-02-15 21:17:30 vrany Exp $'
!
version_SVN
- ^ '$Id: Tools__CodeNavigationService.st,v 1.41 2014-02-05 19:08:25 cg Exp $'
+ ^ '$Id: Tools__CodeNavigationService.st,v 1.42 2014-02-15 21:17:30 vrany Exp $'
! !