2918 "Created: / 20-09-2006 / 15:29:12 / cg" |
2918 "Created: / 20-09-2006 / 15:29:12 / cg" |
2919 ! ! |
2919 ! ! |
2920 |
2920 |
2921 !ListView methodsFor:'queries'! |
2921 !ListView methodsFor:'queries'! |
2922 |
2922 |
2923 characterPositionOfLine:lineNr col:col |
2923 characterPositionOfLine:lineNr col:colArg |
2924 "given a line/col position, return the character index within the contents-string, |
2924 "given a line/col position, return the character index within the contents-string, |
2925 - used with Compilers error-positioning, which is based on character positions |
2925 - used with Compilers error-positioning, which is based on character positions |
2926 of the contents-string." |
2926 of the contents-string." |
2927 |
2927 |
2928 |lineString pos lineEndCharSize| |
2928 |lineString pos lineEndCharSize col| |
2929 |
2929 |
2930 lineEndCharSize := self lineEndCRLF ifTrue:[2] ifFalse:[1]. |
2930 lineEndCharSize := self lineEndCRLF ifTrue:[2] ifFalse:[1]. |
2931 |
2931 |
2932 self checkForExistingLine:lineNr. |
2932 self checkForExistingLine:lineNr. |
2933 pos := 1. |
2933 pos := 1. |
2934 1 to:(lineNr - 1) do:[:lnr | |
2934 1 to:(lineNr - 1) do:[:lnr | |
2935 lineString := self at:lnr. |
2935 lineString := self at:lnr. |
2936 lineString notNil ifTrue:[ |
2936 lineString notNil ifTrue:[ |
2937 pos := pos + lineString size |
2937 pos := pos + (lineString string "withoutTrailingSeparators") size |
2938 ]. |
2938 ]. |
2939 pos := pos + lineEndCharSize "the return-character" |
2939 pos := pos + lineEndCharSize "the return-character" |
2940 ]. |
2940 ]. |
|
2941 |
|
2942 "/ if beyond end of line, do not advance into next line |
|
2943 col := colArg min:(self at:lineNr) size. |
2941 ^ pos + col - 1 |
2944 ^ pos + col - 1 |
2942 |
2945 |
2943 "Modified: / 04-07-2006 / 19:14:25 / fm" |
2946 "Modified: / 04-07-2006 / 19:14:25 / fm" |
|
2947 "Modified: / 21-08-2011 / 11:03:19 / cg" |
2944 ! |
2948 ! |
2945 |
2949 |
2946 colOfCharacterPosition:charPos |
2950 colOfCharacterPosition:charPos |
2947 "given a character index within the contents-string, |
2951 "given a character index within the contents-string, |
2948 return the column number where the character is |
2952 return the column number where the character is |
3099 lineOfCharacterPosition:charPos |
3103 lineOfCharacterPosition:charPos |
3100 "given a character index within the contents-string, |
3104 "given a character index within the contents-string, |
3101 return the lineNumber where the character is |
3105 return the lineNumber where the character is |
3102 - used to find line to hilight from Compilers error-position" |
3106 - used to find line to hilight from Compilers error-position" |
3103 |
3107 |
3104 |lineNr sum lastLine lineEndCharSize| |
3108 |lineNr sum lastLine lineEndCharSize l| |
3105 |
3109 |
3106 lineEndCharSize := self lineEndCRLF ifTrue:[2] ifFalse:[1]. |
3110 lineEndCharSize := self lineEndCRLF ifTrue:[2] ifFalse:[1]. |
3107 |
3111 |
3108 lineNr := 1. |
3112 lineNr := 1. |
3109 sum := 0. |
3113 sum := 0. |
3110 lastLine := self size. |
3114 lastLine := self size. |
3111 [(sum < charPos) and:[lineNr <= lastLine]] whileTrue:[ |
3115 [(sum < charPos) and:[lineNr <= lastLine]] whileTrue:[ |
3112 sum := sum + (self at:lineNr) size + lineEndCharSize. |
3116 l := (self at:lineNr) ? ''. |
|
3117 sum := sum + (l string "withoutTrailingSeparators" size) + lineEndCharSize. |
3113 lineNr := lineNr + 1 |
3118 lineNr := lineNr + 1 |
3114 ]. |
3119 ]. |
3115 sum == charPos ifTrue:[ |
3120 sum == charPos ifTrue:[ |
3116 ^ lineNr |
3121 ^ lineNr |
3117 ]. |
3122 ]. |
3118 |
3123 |
3119 ^ lineNr - 1 |
3124 ^ lineNr - 1 |
3120 |
3125 |
3121 "Modified: / 04-07-2006 / 19:13:32 / fm" |
3126 "Modified: / 04-07-2006 / 19:13:32 / fm" |
3122 "Modified: / 05-07-2011 / 22:52:11 / cg" |
3127 "Modified: / 21-08-2011 / 10:50:12 / cg" |
3123 ! |
3128 ! |
3124 |
3129 |
3125 numberOfLines |
3130 numberOfLines |
3126 "return the number of lines the text has" |
3131 "return the number of lines the text has" |
3127 |
3132 |