2970 |
2970 |
2971 !ListView methodsFor:'queries'! |
2971 !ListView methodsFor:'queries'! |
2972 |
2972 |
2973 characterPositionOfLine:lineNr col:colArg |
2973 characterPositionOfLine:lineNr col:colArg |
2974 "given a line/col position, return the character index within the contents-string, |
2974 "given a line/col position, return the character index within the contents-string, |
2975 - used with Compilers error-positioning, which is based on character positions |
2975 - used with compiler's error-positioning, which is based on character positions |
2976 of the contents-string." |
2976 of the contents-string." |
2977 |
2977 |
2978 |lineString pos lineEndCharSize col| |
2978 |lineString charPos lineEndCharSize col| |
2979 |
2979 |
2980 lineEndCharSize := self lineEndCRLF ifTrue:[2] ifFalse:[1]. |
2980 lineEndCharSize := self lineEndCRLF ifTrue:[2] ifFalse:[1]. |
2981 |
2981 |
2982 self checkForExistingLine:lineNr. |
2982 self checkForExistingLine:lineNr. |
2983 pos := 1. |
2983 charPos := 1. |
2984 1 to:(lineNr - 1) do:[:lnr | |
2984 1 to:(lineNr - 1) do:[:lnr | |
2985 lineString := self at:lnr. |
2985 lineString := self at:lnr. |
2986 lineString notNil ifTrue:[ |
2986 lineString notNil ifTrue:[ |
2987 pos := pos + (lineString string "withoutTrailingSeparators") size |
2987 charPos := charPos + (lineString string "withoutTrailingSeparators") size |
2988 ]. |
2988 ]. |
2989 pos := pos + lineEndCharSize "the return-character" |
2989 charPos := charPos + lineEndCharSize "the return-character" |
2990 ]. |
2990 ]. |
2991 |
2991 |
2992 "/ if beyond end of line, do not advance into next line |
2992 "/ if beyond end of line, do not advance into next line |
2993 col := colArg min:(self at:lineNr) size. |
2993 col := colArg min:(self at:lineNr) size. |
2994 ^ pos + col - 1 |
2994 ^ charPos + col - 1 |
2995 |
2995 |
2996 "Modified: / 04-07-2006 / 19:14:25 / fm" |
2996 "Modified: / 04-07-2006 / 19:14:25 / fm" |
2997 "Modified: / 21-08-2011 / 11:03:19 / cg" |
2997 "Modified: / 21-08-2011 / 11:03:19 / cg" |
2998 ! |
2998 ! |
2999 |
2999 |