847 ] |
847 ] |
848 |
848 |
849 "Modified: / 30.8.1995 / 19:07:13 / claus" |
849 "Modified: / 30.8.1995 / 19:07:13 / claus" |
850 "Created: / 5.6.1997 / 12:40:06 / cg" |
850 "Created: / 5.6.1997 / 12:40:06 / cg" |
851 "Modified: / 26.7.1998 / 13:47:35 / cg" |
851 "Modified: / 26.7.1998 / 13:47:35 / cg" |
|
852 ! |
|
853 |
|
854 listAt:lineNr |
|
855 "given a lineNumber, return the corresponding string |
|
856 This is used for accessing; i.e. for non-string entries, this |
|
857 returns the corresponding string." |
|
858 |
|
859 |l| |
|
860 |
|
861 list isNil ifTrue:[^ nil]. |
|
862 (lineNr between:1 and:self size) ifFalse:[^ nil]. |
|
863 l := self at:lineNr. |
|
864 l isNil ifTrue:[^ l]. |
|
865 ^ self visibleStringFrom:l "/ l asString |
|
866 |
|
867 "Modified: 7.9.1995 / 15:54:59 / claus" |
852 ! |
868 ! |
853 |
869 |
854 removeFromIndex:startLineNr toIndex:endLineNr |
870 removeFromIndex:startLineNr toIndex:endLineNr |
855 "delete some lines" |
871 "delete some lines" |
856 |
872 |
2187 "/ (absLineNr >= (firstLineShown + nLinesShown)) ifTrue:[^ nil]. |
2203 "/ (absLineNr >= (firstLineShown + nLinesShown)) ifTrue:[^ nil]. |
2188 "/ ^ absLineNr - firstLineShown + 1 |
2204 "/ ^ absLineNr - firstLineShown + 1 |
2189 "/ |
2205 "/ |
2190 ! |
2206 ! |
2191 |
2207 |
2192 characterPositionOfLine:lineNr col:col |
|
2193 "given a line/col position, return the character index within the contents-string, |
|
2194 - used with Compilers error-positioning" |
|
2195 |
|
2196 |lineString pos| |
|
2197 |
|
2198 self checkForExistingLine:lineNr. |
|
2199 pos := 1. |
|
2200 1 to:(lineNr - 1) do:[:lnr | |
|
2201 lineString := self at:lnr. |
|
2202 lineString notNil ifTrue:[ |
|
2203 pos := pos + lineString size |
|
2204 ]. |
|
2205 pos := pos + 1 "the return-character" |
|
2206 ]. |
|
2207 ^ pos + col - 1 |
|
2208 |
|
2209 ! |
|
2210 |
|
2211 checkForExistingLine:lineNr |
2208 checkForExistingLine:lineNr |
2212 "check if a line for lineNr exists; if not, expand text" |
2209 "check if a line for lineNr exists; if not, expand text" |
2213 |
2210 |
2214 list isNil ifTrue: [ |
2211 list isNil ifTrue: [ |
2215 list := StringCollection new:lineNr. |
2212 list := StringCollection new:lineNr. |
2218 lineNr > (list size) ifTrue:[ |
2215 lineNr > (list size) ifTrue:[ |
2219 self grow:lineNr. |
2216 self grow:lineNr. |
2220 self contentsChanged |
2217 self contentsChanged |
2221 ] |
2218 ] |
2222 ] |
2219 ] |
2223 ! |
|
2224 |
|
2225 colOfCharacterPosition:charPos |
|
2226 "given a character index within the contents-string, |
|
2227 return the column number where the character is |
|
2228 - used to find line to hilight from Compilers error-position" |
|
2229 |
|
2230 |line| |
|
2231 |
|
2232 line := self lineOfCharacterPosition:charPos. |
|
2233 ^ charPos - (self characterPositionOfLine:line col:1) + 1. |
|
2234 |
|
2235 ! |
2220 ! |
2236 |
2221 |
2237 colOfX:x inVisibleLine:visLineNr |
2222 colOfX:x inVisibleLine:visLineNr |
2238 "given a visible lineNr and x-coordinate, return colNr" |
2223 "given a visible lineNr and x-coordinate, return colNr" |
2239 |
2224 |
2513 ^ line withoutEmphasis:emphasisToRemove. |
2498 ^ line withoutEmphasis:emphasisToRemove. |
2514 ]. |
2499 ]. |
2515 ^ line |
2500 ^ line |
2516 ! |
2501 ! |
2517 |
2502 |
2518 lineOfCharacterPosition:charPos |
|
2519 "given a character index within the contents-string, |
|
2520 return the lineNumber where the character is |
|
2521 - used to find line to hilight from Compilers error-position" |
|
2522 |
|
2523 |lineNr sum lastLine| |
|
2524 |
|
2525 lineNr := 1. |
|
2526 sum := 0. |
|
2527 lastLine := self size. |
|
2528 [(sum < charPos) and:[lineNr <= lastLine]] whileTrue:[ |
|
2529 sum := sum + (self at:lineNr) size + 1. |
|
2530 lineNr := lineNr + 1 |
|
2531 ]. |
|
2532 sum == charPos ifTrue:[ |
|
2533 ^ lineNr |
|
2534 ]. |
|
2535 |
|
2536 ^ lineNr - 1 |
|
2537 |
|
2538 "Modified: / 5.4.1998 / 17:19:28 / cg" |
|
2539 ! |
|
2540 |
|
2541 listAt:lineNr |
|
2542 "given a lineNumber, return the corresponding string |
|
2543 This is used for accessing; i.e. for non-string entries, this |
|
2544 returns the corresponding string." |
|
2545 |
|
2546 |l| |
|
2547 |
|
2548 list isNil ifTrue:[^ nil]. |
|
2549 (lineNr between:1 and:self size) ifFalse:[^ nil]. |
|
2550 l := self at:lineNr. |
|
2551 l isNil ifTrue:[^ l]. |
|
2552 ^ self visibleStringFrom:l "/ l asString |
|
2553 |
|
2554 "Modified: 7.9.1995 / 15:54:59 / claus" |
|
2555 ! |
|
2556 |
|
2557 listAt:lineNr from:startCol |
2503 listAt:lineNr from:startCol |
2558 "return right substring from startCol to end of a line" |
2504 "return right substring from startCol to end of a line" |
2559 |
2505 |
2560 |line| |
2506 |line| |
2561 |
2507 |
2570 |
2516 |
2571 |line stop lineLen| |
2517 |line stop lineLen| |
2572 |
2518 |
2573 line := self listAt:lineNr. |
2519 line := self listAt:lineNr. |
2574 line isNil ifTrue:[^ nil]. |
2520 line isNil ifTrue:[^ nil]. |
|
2521 |
2575 lineLen := line size. |
2522 lineLen := line size. |
2576 (startCol > lineLen) ifTrue:[^ nil]. |
2523 (startCol > lineLen) ifTrue:[^ nil]. |
2577 stop := endCol. |
2524 stop := endCol. |
2578 (stop > lineLen) ifTrue:[stop := lineLen]. |
2525 (stop > lineLen) ifTrue:[stop := lineLen]. |
2579 ^ line copyFrom:startCol to:stop |
2526 ^ line copyFrom:startCol to:stop |
2864 ^ ((visLineNr - 1) * fontHeight) + textStartTop |
2811 ^ ((visLineNr - 1) * fontHeight) + textStartTop |
2865 ! ! |
2812 ! ! |
2866 |
2813 |
2867 !ListView methodsFor:'queries'! |
2814 !ListView methodsFor:'queries'! |
2868 |
2815 |
|
2816 characterPositionOfLine:lineNr col:col |
|
2817 "given a line/col position, return the character index within the contents-string, |
|
2818 - used with Compilers error-positioning, which is based on character positions |
|
2819 of the contents-string." |
|
2820 |
|
2821 |lineString pos| |
|
2822 |
|
2823 self checkForExistingLine:lineNr. |
|
2824 pos := 1. |
|
2825 1 to:(lineNr - 1) do:[:lnr | |
|
2826 lineString := self at:lnr. |
|
2827 lineString notNil ifTrue:[ |
|
2828 pos := pos + lineString size |
|
2829 ]. |
|
2830 pos := pos + 1 "the return-character" |
|
2831 ]. |
|
2832 ^ pos + col - 1 |
|
2833 ! |
|
2834 |
|
2835 colOfCharacterPosition:charPos |
|
2836 "given a character index within the contents-string, |
|
2837 return the column number where the character is |
|
2838 - used to find line to hilight from Compilers error-position" |
|
2839 |
|
2840 |line| |
|
2841 |
|
2842 line := self lineOfCharacterPosition:charPos. |
|
2843 ^ charPos - (self characterPositionOfLine:line col:1) + 1. |
|
2844 |
|
2845 ! |
|
2846 |
2869 currentLine |
2847 currentLine |
2870 "the current line (for relative gotos); |
2848 "the current line (for relative gotos); |
2871 since listViews have no cursor, the first shown line is returned here. |
2849 since listViews have no cursor, the first shown line is returned here. |
2872 Redefined in editTextView, to return the cursors line." |
2850 Redefined in editTextView, to return the cursors line." |
2873 |
2851 |
3003 lineIsVisible:line |
2981 lineIsVisible:line |
3004 "is line visible?" |
2982 "is line visible?" |
3005 |
2983 |
3006 (line >= firstLineShown and:[ line < (firstLineShown + nLinesShown) ]) ifTrue:[ ^ true ]. |
2984 (line >= firstLineShown and:[ line < (firstLineShown + nLinesShown) ]) ifTrue:[ ^ true ]. |
3007 ^ false. |
2985 ^ false. |
|
2986 ! |
|
2987 |
|
2988 lineOfCharacterPosition:charPos |
|
2989 "given a character index within the contents-string, |
|
2990 return the lineNumber where the character is |
|
2991 - used to find line to hilight from Compilers error-position" |
|
2992 |
|
2993 |lineNr sum lastLine| |
|
2994 |
|
2995 lineNr := 1. |
|
2996 sum := 0. |
|
2997 lastLine := self size. |
|
2998 [(sum < charPos) and:[lineNr <= lastLine]] whileTrue:[ |
|
2999 sum := sum + (self at:lineNr) size + 1. |
|
3000 lineNr := lineNr + 1 |
|
3001 ]. |
|
3002 sum == charPos ifTrue:[ |
|
3003 ^ lineNr |
|
3004 ]. |
|
3005 |
|
3006 ^ lineNr - 1 |
|
3007 |
|
3008 "Modified: / 5.4.1998 / 17:19:28 / cg" |
3008 ! |
3009 ! |
3009 |
3010 |
3010 numberOfLines |
3011 numberOfLines |
3011 "return the number of lines the text has" |
3012 "return the number of lines the text has" |
3012 |
3013 |