0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
105
|
13 |
'From Smalltalk/X, Version:2.10.5 on 14-mar-1995 at 11:12:00 am'!
|
|
14 |
|
0
|
15 |
TextView subclass:#EditTextView
|
105
|
16 |
instanceVariableNames:'cursorLine cursorVisibleLine cursorCol cursorShown
|
118
|
17 |
prevCursorState readOnly modified fixedSize exceptionBlock
|
|
18 |
errorMessage cursorFgColor cursorBgColor cursorType undoAction
|
|
19 |
typeOfSelection lastString lastReplacement lastAction replacing
|
|
20 |
showMatchingParenthesis hasKeyboardFocus'
|
105
|
21 |
classVariableNames:'DefaultCursorForegroundColor DefaultCursorBackgroundColor
|
118
|
22 |
DefaultCursorType'
|
105
|
23 |
poolDictionaries:''
|
|
24 |
category:'Views-Text'
|
0
|
25 |
!
|
|
26 |
|
|
27 |
EditTextView comment:'
|
5
|
28 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
29 |
All Rights Reserved
|
|
30 |
|
118
|
31 |
$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.24 1995-05-03 00:29:07 claus Exp $
|
0
|
32 |
'!
|
|
33 |
|
|
34 |
!EditTextView class methodsFor:'documentation'!
|
|
35 |
|
33
|
36 |
copyright
|
|
37 |
"
|
|
38 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
39 |
All Rights Reserved
|
33
|
40 |
|
|
41 |
This software is furnished under a license and may be used
|
|
42 |
only in accordance with the terms of that license and with the
|
|
43 |
inclusion of the above copyright notice. This software may not
|
|
44 |
be provided or otherwise made available to, or used by, any
|
|
45 |
other person. No title to or ownership of the software is
|
|
46 |
hereby transferred.
|
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
version
|
|
51 |
"
|
118
|
52 |
$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.24 1995-05-03 00:29:07 claus Exp $
|
33
|
53 |
"
|
|
54 |
!
|
|
55 |
|
0
|
56 |
documentation
|
|
57 |
"
|
|
58 |
a view for editable text - adds editing functionality to TextView
|
|
59 |
|
|
60 |
Instance variables:
|
|
61 |
|
|
62 |
cursorLine <Number> line where cursor sits (1..)
|
|
63 |
cursorVisibleLine <Number> visible line where cursor sits (1..nLinesShown)
|
|
64 |
cursorCol <Number> col where cursor sits (1..)
|
|
65 |
cursorShown <Boolean> true, if cursor is currently shown
|
|
66 |
prevCursorState <Boolean> temporary
|
|
67 |
readOnly <Boolean> true, if text may not be edited
|
|
68 |
modified <Boolean> true, if text has been modified
|
|
69 |
fixedSize <Boolean> true, if no lines may be added/removed
|
|
70 |
exceptionBlock <Block> block to be evaluated when readonly text is about to be modified
|
|
71 |
errorMessage <String> message text
|
|
72 |
cursorFgColor <Color> color used for cursor drawing
|
|
73 |
cursorBgColor <Color> color used for cursor drawing
|
59
|
74 |
cursorType <Symbol> how the cursor is drawn; currently implemented
|
|
75 |
are #block (solid-block cursor), #ibeam
|
|
76 |
(vertical bar at insertion point)
|
|
77 |
and #caret (caret below insertion-point)
|
7
|
78 |
undoAction <Block> block which undoes last cut, paste or replace
|
|
79 |
typeOfSelection <Symbol> #paste, if selection created by paste, nil otherwise
|
|
80 |
lastCut <String> last cut or replaced string
|
|
81 |
lastReplacement <String> last replacement
|
|
82 |
replacing <Boolean> true if entered characters replace last selection
|
|
83 |
showMatchingParenthesis <Boolean> if true, shows matching parenthesis
|
59
|
84 |
when entering one
|
33
|
85 |
|
|
86 |
used globals:
|
|
87 |
|
|
88 |
DeleteHistory <Text> last 1000 lines of deleted text
|
0
|
89 |
"
|
|
90 |
! !
|
|
91 |
|
59
|
92 |
!EditTextView class methodsFor:'defaults'!
|
|
93 |
|
|
94 |
updateStyleCache
|
60
|
95 |
DefaultCursorForegroundColor := StyleSheet colorAt:'textCursorForegroundColor'.
|
|
96 |
DefaultCursorBackgroundColor := StyleSheet colorAt:'textCursorBackgroundColor'.
|
59
|
97 |
DefaultCursorType := StyleSheet at:'textCursorType' default:#block.
|
|
98 |
! !
|
|
99 |
|
105
|
100 |
!EditTextView methodsFor:'private'!
|
|
101 |
|
|
102 |
textChanged
|
|
103 |
"triggered whenever text has been edited (not to confuse with
|
|
104 |
contentsChanged, which is triggered when the size has changed, and
|
|
105 |
is used to notify scrollers, other views etc.)"
|
|
106 |
|
|
107 |
super contentsChanged.
|
|
108 |
modified := true.
|
|
109 |
contentsWasSaved := false
|
|
110 |
! !
|
|
111 |
|
|
112 |
!EditTextView methodsFor:'editing'!
|
|
113 |
|
|
114 |
insert:aCharacter atLine:lineNr col:colNr
|
|
115 |
"insert a single character at lineNr/colNr"
|
|
116 |
|
|
117 |
|line lineSize newLine drawCharacterOnly|
|
|
118 |
|
|
119 |
readOnly ifTrue: [
|
118
|
120 |
exceptionBlock value:errorMessage.
|
|
121 |
^ self
|
105
|
122 |
].
|
|
123 |
aCharacter == (Character cr) ifTrue:[
|
118
|
124 |
self splitLine:lineNr before:colNr.
|
|
125 |
^ self
|
105
|
126 |
].
|
|
127 |
drawCharacterOnly := false.
|
|
128 |
self checkForExistingLine:lineNr.
|
|
129 |
line := list at:lineNr.
|
|
130 |
lineSize := line size.
|
|
131 |
(aCharacter == Character space) ifTrue:[
|
118
|
132 |
(colNr > lineSize) ifTrue:[
|
|
133 |
^ self
|
|
134 |
]
|
105
|
135 |
].
|
|
136 |
(lineSize == 0) ifTrue: [
|
118
|
137 |
newLine := String new:colNr.
|
|
138 |
drawCharacterOnly := true
|
105
|
139 |
] ifFalse: [
|
118
|
140 |
(colNr > lineSize) ifTrue: [
|
|
141 |
newLine := String new:colNr.
|
|
142 |
newLine replaceFrom:1 to:lineSize
|
|
143 |
with:line startingAt:1.
|
|
144 |
drawCharacterOnly := true
|
|
145 |
] ifFalse: [
|
|
146 |
newLine := String new:(lineSize + 1).
|
|
147 |
newLine replaceFrom:1 to:(colNr - 1)
|
|
148 |
with:line startingAt:1.
|
|
149 |
newLine replaceFrom:(colNr + 1) to:(lineSize + 1)
|
|
150 |
with:line startingAt:colNr
|
|
151 |
]
|
105
|
152 |
].
|
|
153 |
newLine at:colNr put:aCharacter.
|
|
154 |
aCharacter == (Character tab) ifTrue:[
|
118
|
155 |
newLine := self withTabsExpanded:newLine.
|
|
156 |
drawCharacterOnly := false
|
105
|
157 |
].
|
|
158 |
list at:lineNr put:newLine.
|
118
|
159 |
widthOfWidestLine notNil ifTrue:[
|
|
160 |
widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:line).
|
|
161 |
].
|
105
|
162 |
self textChanged.
|
|
163 |
shown ifTrue:[
|
118
|
164 |
drawCharacterOnly ifTrue:[
|
|
165 |
self redrawLine:lineNr col:colNr
|
|
166 |
] ifFalse:[
|
|
167 |
self redrawLine:lineNr from:colNr
|
|
168 |
]
|
105
|
169 |
]
|
|
170 |
!
|
|
171 |
|
|
172 |
withoutRedrawInsertStringWithoutCRs:aString atLine:lineNr col:colNr
|
|
173 |
"insert aString (which has no crs) at lineNr/colNr"
|
|
174 |
|
|
175 |
|strLen line lineSize newLine|
|
|
176 |
|
|
177 |
aString isNil ifTrue:[^ self].
|
|
178 |
readOnly ifTrue: [
|
118
|
179 |
exceptionBlock value:errorMessage.
|
|
180 |
^ self
|
105
|
181 |
].
|
|
182 |
strLen := aString size.
|
|
183 |
self checkForExistingLine:lineNr.
|
|
184 |
line := list at:lineNr.
|
|
185 |
line notNil ifTrue:[
|
118
|
186 |
lineSize := line size
|
105
|
187 |
] ifFalse:[
|
118
|
188 |
lineSize := 0
|
105
|
189 |
].
|
|
190 |
((colNr == 1) and:[lineSize == 0]) ifTrue: [
|
118
|
191 |
newLine := aString
|
105
|
192 |
] ifFalse:[
|
118
|
193 |
(lineSize == 0) ifTrue: [
|
|
194 |
newLine := String new:(colNr + strLen - 1)
|
|
195 |
] ifFalse: [
|
|
196 |
(colNr > lineSize) ifTrue: [
|
|
197 |
newLine := String new:(colNr + strLen - 1).
|
|
198 |
newLine replaceFrom:1 to:lineSize
|
|
199 |
with:line startingAt:1
|
|
200 |
] ifFalse: [
|
|
201 |
newLine := String new:(lineSize + strLen).
|
|
202 |
newLine replaceFrom:1 to:(colNr - 1)
|
|
203 |
with:line startingAt:1.
|
|
204 |
newLine replaceFrom:(colNr + strLen) to:(lineSize + strLen)
|
|
205 |
with:line startingAt:colNr
|
|
206 |
]
|
|
207 |
].
|
|
208 |
newLine replaceFrom:colNr to:(colNr + strLen - 1)
|
|
209 |
with:aString startingAt:1
|
105
|
210 |
].
|
|
211 |
|
|
212 |
(aString occurrencesOf:(Character tab)) == 0 ifFalse:[
|
118
|
213 |
newLine := self withTabsExpanded:newLine
|
105
|
214 |
].
|
|
215 |
|
|
216 |
list at:lineNr put:newLine.
|
118
|
217 |
widthOfWidestLine notNil ifTrue:[
|
|
218 |
widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:newLine).
|
|
219 |
].
|
105
|
220 |
self textChanged.
|
|
221 |
!
|
|
222 |
|
|
223 |
splitLine:lineNr before:colNr
|
|
224 |
"split the line linNr before colNr; the right part (from colNr)
|
|
225 |
is cut off and inserted after lineNr; the view is redrawn"
|
|
226 |
|
|
227 |
|line lineSize leftRest rightRest visLine w
|
|
228 |
srcY "{ Class: SmallInteger }" |
|
|
229 |
|
|
230 |
list isNil ifFalse:[
|
118
|
231 |
lineNr > (list size) ifFalse:[
|
|
232 |
(colNr == 1) ifTrue:[
|
|
233 |
self insertLine:nil before:lineNr.
|
|
234 |
^ self
|
|
235 |
].
|
|
236 |
line := list at:lineNr.
|
|
237 |
line isNil ifFalse:[
|
|
238 |
lineSize := line size.
|
|
239 |
(colNr <= lineSize) ifTrue:[
|
|
240 |
rightRest := line copyFrom:colNr to:lineSize.
|
|
241 |
(colNr > 1) ifTrue:[
|
|
242 |
leftRest := line copyTo:(colNr - 1)
|
|
243 |
]
|
|
244 |
] ifFalse:[
|
|
245 |
leftRest := line
|
|
246 |
]
|
|
247 |
].
|
|
248 |
leftRest notNil ifTrue:[
|
|
249 |
leftRest isBlank ifTrue:[leftRest := nil]
|
|
250 |
].
|
|
251 |
list at:lineNr put:leftRest.
|
|
252 |
self withoutRedrawInsertLine:rightRest before:(lineNr + 1).
|
|
253 |
|
|
254 |
visLine := self listLineToVisibleLine:(lineNr).
|
|
255 |
visLine notNil ifTrue:[
|
|
256 |
w := self widthForScrollBetween:lineNr
|
|
257 |
and:(firstLineShown + nLinesShown).
|
|
258 |
srcY := topMargin + (visLine * fontHeight).
|
|
259 |
self catchExpose.
|
|
260 |
self copyFrom:self x:textStartLeft y:srcY
|
|
261 |
toX:textStartLeft y:(srcY + fontHeight)
|
|
262 |
width:w
|
|
263 |
height:((nLinesShown - visLine - 1) * fontHeight).
|
|
264 |
self redrawLine:lineNr.
|
|
265 |
self redrawLine:(lineNr + 1).
|
|
266 |
self waitForExpose
|
|
267 |
].
|
|
268 |
widthOfWidestLine := nil. "/ unknown
|
|
269 |
self textChanged.
|
|
270 |
]
|
105
|
271 |
]
|
|
272 |
!
|
|
273 |
|
|
274 |
withoutRedrawInsertLine:aString before:lineNr
|
|
275 |
"insert the argument, aString before line lineNr; the string
|
|
276 |
becomes line nileNr; everything else is moved down; the view
|
|
277 |
is not redrawn"
|
|
278 |
|
|
279 |
|line|
|
|
280 |
|
|
281 |
readOnly ifTrue: [
|
|
282 |
exceptionBlock value:errorMessage.
|
|
283 |
^ self
|
|
284 |
].
|
|
285 |
line := aString.
|
|
286 |
line notNil ifTrue:[
|
|
287 |
line isBlank ifTrue:[
|
|
288 |
line := nil
|
|
289 |
] ifFalse:[
|
|
290 |
(line occurrencesOf:(Character tab)) == 0 ifFalse:[
|
|
291 |
line := self withTabsExpanded:line
|
|
292 |
]
|
|
293 |
]
|
|
294 |
].
|
|
295 |
list isNil ifTrue: [
|
|
296 |
list := StringCollection new:lineNr
|
|
297 |
] ifFalse: [
|
|
298 |
list grow:((list size + 1) max:lineNr)
|
|
299 |
].
|
|
300 |
|
|
301 |
"I have changed 'replaceFrom:to:with:startingAt:' to correctly handle
|
|
302 |
overlapping copy - if it didn't, we had to use:"
|
|
303 |
"
|
|
304 |
index := list size.
|
|
305 |
[index > lineNr] whileTrue: [
|
|
306 |
pIndex := index - 1.
|
|
307 |
list at:index put:(list at:pIndex).
|
|
308 |
index := pIndex
|
|
309 |
].
|
|
310 |
"
|
|
311 |
list replaceFrom:(lineNr + 1) to:(list size) with:list startingAt:lineNr.
|
|
312 |
list at:lineNr put:line.
|
|
313 |
!
|
|
314 |
|
|
315 |
insertLines:someText from:start to:end before:lineNr
|
|
316 |
"insert a bunch of lines before line lineNr"
|
|
317 |
|
|
318 |
|visLine w nLines "{ Class: SmallInteger }"
|
|
319 |
srcY "{ Class: SmallInteger }"
|
|
320 |
dstY "{ Class: SmallInteger }" |
|
|
321 |
|
|
322 |
readOnly ifTrue:[
|
118
|
323 |
^ self
|
105
|
324 |
].
|
|
325 |
visLine := self listLineToVisibleLine:lineNr.
|
|
326 |
(shown not or:[visLine isNil]) ifTrue:[
|
118
|
327 |
self withoutRedrawInsertLines:someText
|
|
328 |
from:start to:end
|
|
329 |
before:lineNr.
|
105
|
330 |
] ifFalse:[
|
118
|
331 |
nLines := end - start + 1.
|
|
332 |
((visLine + nLines) >= nLinesShown) ifTrue:[
|
|
333 |
self withoutRedrawInsertLines:someText
|
|
334 |
from:start to:end
|
|
335 |
before:lineNr.
|
|
336 |
self redrawFromVisibleLine:visLine to:nLinesShown
|
|
337 |
] ifFalse:[
|
|
338 |
w := self widthForScrollBetween:(lineNr + nLines)
|
|
339 |
and:(firstLineShown + nLines + nLinesShown).
|
|
340 |
srcY := topMargin + ((visLine - 1) * fontHeight).
|
|
341 |
dstY := srcY + (nLines * fontHeight).
|
|
342 |
"
|
|
343 |
stupid: must catchExpose before inserting new
|
|
344 |
stuff - since catchExpose may perform redraws
|
|
345 |
"
|
|
346 |
self catchExpose.
|
|
347 |
self withoutRedrawInsertLines:someText
|
|
348 |
from:start to:end
|
|
349 |
before:lineNr.
|
|
350 |
self copyFrom:self x:textStartLeft y:srcY
|
|
351 |
toX:textStartLeft y:dstY
|
|
352 |
width:w
|
|
353 |
height:(height - dstY).
|
|
354 |
self redrawFromVisibleLine:visLine to:(visLine + nLines - 1).
|
|
355 |
self waitForExpose
|
|
356 |
].
|
|
357 |
].
|
|
358 |
widthOfWidestLine notNil ifTrue:[
|
|
359 |
someText do:[:line |
|
|
360 |
widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:line).
|
|
361 |
]
|
105
|
362 |
].
|
|
363 |
self textChanged.
|
|
364 |
!
|
|
365 |
|
|
366 |
deleteFromLine:startLine col:startCol toLine:endLine col:endCol
|
|
367 |
"delete all text from startLine/startCol to endLine/endCol -
|
|
368 |
joining lines if nescessary"
|
|
369 |
|
|
370 |
|line lineSize|
|
|
371 |
|
|
372 |
readOnly ifTrue: [
|
118
|
373 |
exceptionBlock value:errorMessage.
|
|
374 |
^ self
|
105
|
375 |
].
|
|
376 |
list isNil ifTrue:[^ self].
|
|
377 |
|
|
378 |
(startLine == endLine) ifTrue:[
|
118
|
379 |
"delete chars within a line"
|
|
380 |
self deleteCharsAtLine:startLine fromCol:startCol toCol:endCol.
|
|
381 |
^ self
|
105
|
382 |
].
|
|
383 |
|
|
384 |
((startCol == 1) and:[endCol == 0]) ifTrue:[
|
118
|
385 |
"delete full lines only"
|
|
386 |
endLine > startLine ifTrue:[
|
|
387 |
self deleteFromLine:startLine toLine:(endLine - 1)
|
|
388 |
].
|
|
389 |
^ self
|
105
|
390 |
].
|
|
391 |
|
|
392 |
"delete right rest of 1st line"
|
|
393 |
self deleteCharsAtLine:startLine fromCol:startCol.
|
|
394 |
|
|
395 |
"delete the inner lines ..."
|
|
396 |
endLine > (startLine + 1) ifTrue:[
|
118
|
397 |
self deleteFromLine:(startLine + 1) toLine:(endLine - 1)
|
105
|
398 |
].
|
|
399 |
|
|
400 |
(endCol ~~ 0) ifTrue:[
|
118
|
401 |
"delete the left rest of the last line"
|
|
402 |
self deleteCharsAtLine:(startLine + 1) toCol:endCol.
|
|
403 |
|
|
404 |
"must add blanks, if startCal lies behond end of startLine"
|
|
405 |
line := list at:startLine.
|
|
406 |
lineSize := line size.
|
|
407 |
(startCol > lineSize) ifTrue:[
|
|
408 |
line isNil ifTrue:[
|
|
409 |
line := String new:(startCol - 1)
|
|
410 |
] ifFalse:[
|
|
411 |
line := line , (String new:(startCol - 1 - lineSize))
|
|
412 |
].
|
|
413 |
list at:startLine put:line.
|
|
414 |
widthOfWidestLine := nil. "/ i.e. unknown
|
|
415 |
self textChanged.
|
|
416 |
]
|
105
|
417 |
].
|
|
418 |
|
|
419 |
"merge the left rest of 1st line with right rest of last line into one"
|
|
420 |
self mergeLine:startLine
|
|
421 |
!
|
|
422 |
|
|
423 |
insertStringAtCursor:aString
|
|
424 |
"insert the argument, aString at cursor position
|
|
425 |
handle cr's correctly. A nil argument is interpreted as an empty line."
|
|
426 |
|
|
427 |
|start " { Class: SmallInteger }"
|
|
428 |
stop " { Class: SmallInteger }"
|
|
429 |
end " { Class: SmallInteger }"
|
|
430 |
subString|
|
|
431 |
|
|
432 |
aString isNil ifTrue:[
|
|
433 |
"new:"
|
|
434 |
self insertCharAtCursor:(Character cr).
|
|
435 |
^ self
|
|
436 |
].
|
|
437 |
((aString occurrencesOf:(Character cr)) == 0) ifTrue:[
|
|
438 |
^ self insertStringWithoutCRsAtCursor:aString
|
|
439 |
].
|
|
440 |
|
|
441 |
self insertLines:aString asStringCollection withCr:false.
|
|
442 |
|
|
443 |
"/ start := 1.
|
|
444 |
"/ end := aString size.
|
|
445 |
"/ "insert the 1st line"
|
|
446 |
"/ (cursorCol ~~ 1) ifTrue:[
|
|
447 |
"/ stop := aString indexOf:(Character cr) startingAt:start.
|
|
448 |
"/ stop == 0 ifTrue:[
|
|
449 |
"/ stop := end + 1
|
|
450 |
"/ ].
|
|
451 |
"/ subString := aString copyFrom:start to:(stop - 1).
|
|
452 |
"/ self insertStringWithoutCRsAtCursor:subString.
|
|
453 |
"/ self insertCharAtCursor:(Character cr).
|
|
454 |
"/ start := stop + 1
|
|
455 |
"/ ].
|
|
456 |
"/ "insert the block of full lines"
|
|
457 |
"/
|
|
458 |
"/ [start <= end] whileTrue:[
|
|
459 |
"/ stop := aString indexOf:(Character cr) startingAt:start.
|
|
460 |
"/ stop == 0 ifTrue:[
|
|
461 |
"/ stop := end + 1
|
|
462 |
"/ ].
|
|
463 |
"/ subString := aString copyFrom:start to:(stop - 1).
|
|
464 |
"/ self insertStringWithoutCRsAtCursor:subString.
|
|
465 |
"/ (stop < end) ifTrue:[
|
|
466 |
"/ self insertCharAtCursor:(Character cr)
|
|
467 |
"/ ].
|
|
468 |
"/ start := stop + 1
|
|
469 |
"/ ]
|
|
470 |
!
|
|
471 |
|
|
472 |
insertLines:lines withCr:withCr
|
|
473 |
"insert a bunch of lines at cursor position. Cursor
|
|
474 |
is moved behind insertion.
|
|
475 |
If withCr is true, append cr after last line"
|
|
476 |
|
|
477 |
|start end nLines|
|
|
478 |
|
|
479 |
lines notNil ifTrue:[
|
|
480 |
nLines := lines size.
|
|
481 |
(nLines == 1) ifTrue:[
|
|
482 |
self insertStringAtCursor:(lines at:1).
|
|
483 |
withCr ifTrue:[
|
|
484 |
self insertCharAtCursor:(Character cr)
|
|
485 |
]
|
|
486 |
] ifFalse:[
|
|
487 |
(cursorCol ~~ 1) ifTrue:[
|
|
488 |
self insertStringAtCursor:(lines at:1).
|
|
489 |
self insertCharAtCursor:(Character cr).
|
|
490 |
start := 2
|
|
491 |
] ifFalse:[
|
|
492 |
start := 1
|
|
493 |
].
|
|
494 |
withCr ifTrue:[
|
|
495 |
end := nLines
|
|
496 |
] ifFalse:[
|
|
497 |
end := nLines - 1
|
|
498 |
].
|
|
499 |
(start < nLines) ifTrue:[
|
|
500 |
(end >= start) ifTrue:[
|
|
501 |
self withCursorOffDo:[
|
|
502 |
self insertLines:lines
|
|
503 |
from:start to:end
|
|
504 |
before:cursorLine.
|
|
505 |
cursorLine := cursorLine + (end - start + 1).
|
|
506 |
cursorVisibleLine := self absoluteLineToVisibleLine:
|
|
507 |
cursorLine
|
|
508 |
]
|
|
509 |
]
|
|
510 |
].
|
|
511 |
withCr ifFalse:[
|
|
512 |
"last line without cr"
|
|
513 |
self insertStringAtCursor:(lines at:nLines)
|
|
514 |
]
|
|
515 |
]
|
|
516 |
]
|
|
517 |
!
|
|
518 |
|
|
519 |
insertStringWithoutCRsAtCursor:aString
|
|
520 |
"insert a string (which has no crs) at cursor position
|
|
521 |
- advance cursor"
|
|
522 |
|
|
523 |
aString notNil ifTrue:[
|
|
524 |
self withCursorOffDo:[
|
|
525 |
self insertString:aString atLine:cursorLine col:cursorCol.
|
|
526 |
cursorCol := cursorCol + aString size
|
|
527 |
]
|
|
528 |
]
|
|
529 |
!
|
|
530 |
|
|
531 |
withoutRedrawInsertLines:lines from:start to:end before:lineNr
|
|
532 |
"insert a bunch of lines before line lineNr; the view
|
|
533 |
is not redrawn"
|
|
534 |
|
|
535 |
|newLine newLines nLines|
|
|
536 |
|
|
537 |
readOnly ifTrue: [
|
|
538 |
exceptionBlock value:errorMessage.
|
|
539 |
^ self
|
|
540 |
].
|
|
541 |
|
|
542 |
nLines := end - start + 1.
|
|
543 |
newLines := Array new:(lines size).
|
|
544 |
start to:end do:[:index |
|
|
545 |
newLine := lines at:index.
|
|
546 |
newLine notNil ifTrue:[
|
|
547 |
newLine isBlank ifTrue:[
|
|
548 |
newLine := nil
|
|
549 |
] ifFalse:[
|
|
550 |
(newLine occurrencesOf:(Character tab)) == 0 ifFalse:[
|
|
551 |
newLine := self withTabsExpanded:newLine
|
|
552 |
]
|
|
553 |
]
|
|
554 |
].
|
|
555 |
newLines at:index put:newLine
|
|
556 |
].
|
|
557 |
list isNil ifTrue: [
|
|
558 |
list := StringCollection new:(lineNr + nLines + 1)
|
|
559 |
] ifFalse: [
|
|
560 |
list grow:((list size + nLines) max:(lineNr + nLines - 1))
|
|
561 |
].
|
|
562 |
|
|
563 |
"I have changed 'replaceFrom:to:with:startingAt:' to correctly handle
|
|
564 |
overlapping copy - if it didn't, we had to use:"
|
|
565 |
"
|
|
566 |
index := list size.
|
|
567 |
[index > lineNr] whileTrue: [
|
|
568 |
pIndex := index - 1.
|
|
569 |
list at:index put:(list at:pIndex).
|
|
570 |
index := pIndex
|
|
571 |
].
|
|
572 |
"
|
|
573 |
list replaceFrom:(lineNr + nLines) to:(list size) with:list startingAt:lineNr.
|
|
574 |
list replaceFrom:lineNr to:(lineNr + nLines - 1) with:newLines startingAt:start.
|
|
575 |
!
|
|
576 |
|
|
577 |
insertStringWithoutCRs:aString atLine:lineNr col:colNr
|
|
578 |
"insert aString (which has no crs) at lineNr/colNr"
|
|
579 |
|
|
580 |
self withoutRedrawInsertStringWithoutCRs:aString atLine:lineNr col:colNr.
|
|
581 |
shown ifTrue:[self redrawLine:lineNr from:colNr]
|
|
582 |
!
|
|
583 |
|
|
584 |
insertString:aString atLine:lineNr col:colNr
|
|
585 |
"insert the string, aString at line/col;
|
|
586 |
handle cr's correctly"
|
|
587 |
|
|
588 |
|start "{ Class: SmallInteger }"
|
|
589 |
stop "{ Class: SmallInteger }"
|
|
590 |
end "{ Class: SmallInteger }"
|
|
591 |
subString c
|
|
592 |
l "{ Class: SmallInteger }" |
|
|
593 |
|
|
594 |
|
|
595 |
aString isNil ifTrue:[^ self].
|
|
596 |
((aString occurrencesOf:(Character cr)) == 0) ifTrue:[
|
|
597 |
^ self insertStringWithoutCRs:aString atLine:lineNr col:colNr
|
|
598 |
].
|
|
599 |
l := lineNr.
|
|
600 |
c := colNr.
|
|
601 |
start := 1.
|
|
602 |
end := aString size.
|
|
603 |
[start <= end] whileTrue:[
|
|
604 |
stop := aString indexOf:(Character cr) startingAt:start.
|
|
605 |
stop == 0 ifTrue:[
|
|
606 |
stop := end + 1
|
|
607 |
].
|
|
608 |
subString := aString copyFrom:start to:(stop - 1).
|
|
609 |
self insertStringWithoutCRs:subString atLine:l col:c.
|
|
610 |
(stop < end) ifTrue:[
|
|
611 |
c := c + subString size.
|
|
612 |
self insert:(Character cr) atLine:l col:c.
|
|
613 |
l := l + 1.
|
|
614 |
c := 1
|
|
615 |
].
|
|
616 |
start := stop + 1
|
|
617 |
]
|
|
618 |
!
|
|
619 |
|
|
620 |
insertCharAtCursor:aCharacter
|
|
621 |
"insert a single character at cursor-position - advance cursor"
|
|
622 |
|
|
623 |
self withCursorOffDo:[
|
|
624 |
self insert:aCharacter atLine:cursorLine col:cursorCol.
|
|
625 |
aCharacter == (Character cr) ifTrue:[
|
|
626 |
self cursorReturn
|
|
627 |
] ifFalse:[
|
|
628 |
cursorCol := cursorCol + 1
|
|
629 |
].
|
|
630 |
self makeCursorVisible
|
|
631 |
]
|
|
632 |
!
|
|
633 |
|
|
634 |
insertLine:aString before:lineNr
|
|
635 |
"insert the line aString before line lineNr"
|
|
636 |
|
|
637 |
|visLine w
|
|
638 |
dstY "{ Class: SmallInteger }" |
|
|
639 |
|
|
640 |
visLine := self listLineToVisibleLine:lineNr.
|
|
641 |
(shown not or:[visLine isNil]) ifTrue:[
|
118
|
642 |
self withoutRedrawInsertLine:aString before:lineNr.
|
105
|
643 |
] ifFalse:[
|
118
|
644 |
w := self widthForScrollBetween:lineNr
|
|
645 |
and:(firstLineShown + nLinesShown).
|
|
646 |
dstY := topMargin + ((visLine ) * fontHeight).
|
|
647 |
self catchExpose.
|
|
648 |
self withoutRedrawInsertLine:aString before:lineNr.
|
|
649 |
self copyFrom:self x:textStartLeft y:(dstY - fontHeight)
|
|
650 |
toX:textStartLeft y:dstY
|
|
651 |
width:w
|
|
652 |
height:((nLinesShown - visLine "- 1") * fontHeight).
|
|
653 |
self redrawVisibleLine:visLine.
|
|
654 |
self waitForExpose.
|
|
655 |
].
|
|
656 |
widthOfWidestLine notNil ifTrue:[
|
|
657 |
widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:aString).
|
105
|
658 |
].
|
|
659 |
self textChanged.
|
|
660 |
!
|
|
661 |
|
|
662 |
mergeLine:lineNr
|
|
663 |
"merge line lineNr with line lineNr+1"
|
|
664 |
|
|
665 |
|leftPart rightPart bothParts nextLineNr|
|
|
666 |
|
|
667 |
list isNil ifFalse:[
|
|
668 |
nextLineNr := lineNr + 1.
|
|
669 |
(nextLineNr > list size) ifFalse:[
|
|
670 |
(list at:lineNr) isNil ifTrue:[
|
|
671 |
leftPart := ''
|
|
672 |
] ifFalse:[
|
|
673 |
leftPart := list at:lineNr
|
|
674 |
].
|
|
675 |
(list at:nextLineNr) isNil ifTrue:[
|
|
676 |
rightPart := ''
|
|
677 |
] ifFalse:[
|
|
678 |
rightPart := list at:nextLineNr
|
|
679 |
].
|
|
680 |
bothParts := leftPart , rightPart.
|
|
681 |
bothParts isBlank ifTrue:[bothParts := nil].
|
|
682 |
list at:lineNr put:bothParts.
|
|
683 |
self redrawLine:lineNr.
|
|
684 |
self deleteLine:nextLineNr
|
|
685 |
]
|
|
686 |
]
|
|
687 |
!
|
|
688 |
|
|
689 |
insertSelectedStringAtCursor:aString
|
|
690 |
"insert the argument, aString at cursor position and select it"
|
|
691 |
|
|
692 |
|startLine startCol|
|
|
693 |
|
|
694 |
startLine := cursorLine.
|
|
695 |
startCol := cursorCol.
|
|
696 |
self insertStringAtCursor:aString.
|
|
697 |
self selectFromLine:startLine col:startCol
|
|
698 |
toLine:cursorLine col:(cursorCol - 1)
|
|
699 |
!
|
|
700 |
|
118
|
701 |
deleteCharsAtLine:lineNr fromCol:startCol toCol:endCol
|
|
702 |
"delete characters from startCol to endCol in line lineNr"
|
|
703 |
|
|
704 |
|line lineSize newLine|
|
|
705 |
|
|
706 |
readOnly ifTrue: [
|
|
707 |
exceptionBlock value:errorMessage.
|
|
708 |
^ self
|
|
709 |
].
|
|
710 |
list isNil ifTrue: [^self].
|
|
711 |
(list size < lineNr) ifTrue: [^ self].
|
|
712 |
|
|
713 |
line := list at:lineNr.
|
|
714 |
line isNil ifTrue: [^self].
|
|
715 |
lineSize := line size.
|
|
716 |
(startCol > lineSize) ifTrue: [^ self].
|
|
717 |
(endCol == 0) ifTrue:[^ self].
|
|
718 |
(endCol < startCol) ifTrue:[^ self].
|
|
719 |
(startCol == endCol) ifTrue:[
|
|
720 |
self deleteCharAtLine:lineNr col:startCol.
|
|
721 |
^ self
|
|
722 |
].
|
|
723 |
(endCol >= lineSize) ifTrue:[
|
|
724 |
self deleteCharsAtLine:lineNr fromCol:startCol.
|
|
725 |
^ self
|
|
726 |
].
|
|
727 |
(startCol <= 1) ifTrue:[
|
|
728 |
self deleteCharsAtLine:lineNr toCol:endCol.
|
|
729 |
^ self
|
|
730 |
].
|
|
731 |
newLine := (line copyTo:(startCol - 1))
|
|
732 |
, (line copyFrom:(endCol + 1) to:lineSize).
|
|
733 |
|
|
734 |
newLine isBlank ifTrue:[
|
|
735 |
newLine := nil
|
|
736 |
].
|
|
737 |
list at:lineNr put:newLine.
|
|
738 |
widthOfWidestLine := nil. "/ i.e. unknown
|
|
739 |
self textChanged.
|
|
740 |
self redrawLine:lineNr
|
|
741 |
!
|
|
742 |
|
105
|
743 |
deleteCharAtLine:lineNr col:colNr
|
|
744 |
"delete single character at colNr in line lineNr"
|
|
745 |
|
118
|
746 |
|line lineSize newLine drawCharacterOnly wasLargest|
|
105
|
747 |
|
|
748 |
readOnly ifTrue: [
|
118
|
749 |
exceptionBlock value:errorMessage.
|
|
750 |
^ self
|
105
|
751 |
].
|
|
752 |
list isNil ifTrue: [^self].
|
|
753 |
(list size < lineNr) ifTrue: [^ self].
|
|
754 |
|
|
755 |
line := list at:lineNr.
|
|
756 |
line isNil ifTrue: [^self].
|
|
757 |
lineSize := line size.
|
|
758 |
(colNr > lineSize) ifTrue: [^ self].
|
|
759 |
|
118
|
760 |
wasLargest := (self widthOfLineString:line) == widthOfWidestLine.
|
|
761 |
|
105
|
762 |
drawCharacterOnly := false.
|
|
763 |
(colNr == lineSize) ifTrue:[
|
118
|
764 |
newLine := line copyTo:(lineSize - 1).
|
|
765 |
fontIsFixedWidth ifTrue:[
|
|
766 |
drawCharacterOnly := true
|
|
767 |
]
|
105
|
768 |
] ifFalse:[
|
118
|
769 |
newLine := String new:(lineSize - 1).
|
|
770 |
newLine replaceFrom:1 to:(colNr - 1)
|
|
771 |
with:line startingAt:1.
|
|
772 |
newLine replaceFrom:colNr to:(lineSize - 1)
|
|
773 |
with:line startingAt:(colNr + 1)
|
105
|
774 |
].
|
|
775 |
|
|
776 |
newLine isBlank ifTrue:[
|
118
|
777 |
newLine := nil
|
105
|
778 |
].
|
|
779 |
list at:lineNr put:newLine.
|
118
|
780 |
wasLargest ifTrue:[
|
|
781 |
widthOfWidestLine := nil. "/ i.e. unknown
|
|
782 |
].
|
105
|
783 |
self textChanged.
|
|
784 |
drawCharacterOnly ifTrue:[
|
118
|
785 |
self redrawLine:lineNr col:colNr
|
105
|
786 |
] ifFalse:[
|
118
|
787 |
self redrawLine:lineNr from:colNr
|
105
|
788 |
]
|
|
789 |
!
|
|
790 |
|
|
791 |
removeTrailingBlankLines
|
|
792 |
"remove all blank lines at end of text"
|
|
793 |
|
|
794 |
|lastLine "{ Class: SmallInteger }"
|
|
795 |
line finished|
|
|
796 |
|
|
797 |
lastLine := list size.
|
|
798 |
finished := false.
|
|
799 |
[finished] whileFalse:[
|
118
|
800 |
(lastLine <= 1) ifTrue:[
|
|
801 |
finished := true
|
|
802 |
] ifFalse:[
|
|
803 |
line := list at:lastLine.
|
|
804 |
line notNil ifTrue:[
|
|
805 |
line isBlank ifTrue:[
|
|
806 |
list at:lastLine put:nil.
|
|
807 |
line := nil
|
|
808 |
]
|
|
809 |
].
|
|
810 |
line notNil ifTrue:[
|
|
811 |
finished := true
|
|
812 |
] ifFalse:[
|
|
813 |
lastLine := lastLine - 1
|
|
814 |
]
|
|
815 |
]
|
105
|
816 |
].
|
|
817 |
(lastLine ~~ list size) ifTrue:[
|
118
|
818 |
list grow:lastLine.
|
105
|
819 |
"/ self textChanged
|
|
820 |
]
|
|
821 |
!
|
|
822 |
|
|
823 |
deleteCharsAtLine:lineNr toCol:colNr
|
|
824 |
"delete characters from start up to colNr in line lineNr"
|
|
825 |
|
|
826 |
|line lineSize newLine|
|
|
827 |
|
|
828 |
readOnly ifTrue: [
|
118
|
829 |
exceptionBlock value:errorMessage.
|
|
830 |
^ self
|
105
|
831 |
].
|
|
832 |
list isNil ifTrue: [^self].
|
|
833 |
(list size < lineNr) ifTrue: [^ self].
|
|
834 |
line := list at:lineNr.
|
|
835 |
line isNil ifTrue: [^self].
|
|
836 |
lineSize := line size.
|
|
837 |
(colNr >= lineSize) ifTrue:[
|
118
|
838 |
newLine := nil
|
105
|
839 |
] ifFalse:[
|
118
|
840 |
newLine := line copyFrom:(colNr + 1) to:lineSize.
|
|
841 |
newLine isBlank ifTrue:[
|
|
842 |
newLine := nil
|
|
843 |
]
|
105
|
844 |
].
|
|
845 |
list at:lineNr put:newLine.
|
118
|
846 |
widthOfWidestLine := nil. "/ i.e. unknown
|
105
|
847 |
self textChanged.
|
|
848 |
self redrawLine:lineNr
|
|
849 |
!
|
|
850 |
|
|
851 |
insertTabAtCursor
|
|
852 |
"insert spaces to next tab"
|
|
853 |
|
|
854 |
self withCursorOffDo:[
|
|
855 |
|nextTab|
|
|
856 |
|
|
857 |
nextTab := self nextTabAfter:cursorCol.
|
|
858 |
self insertStringAtCursor:(String new:(nextTab - cursorCol)).
|
|
859 |
self makeCursorVisible.
|
|
860 |
].
|
|
861 |
!
|
|
862 |
|
|
863 |
deleteSelection
|
|
864 |
"delete the selection"
|
|
865 |
|
|
866 |
readOnly ifTrue: [
|
|
867 |
exceptionBlock value:errorMessage.
|
|
868 |
^ self
|
|
869 |
].
|
|
870 |
selectionStartLine notNil ifTrue:[
|
|
871 |
self withCursorOffDo:[
|
|
872 |
|startLine startCol endLine endCol|
|
|
873 |
|
|
874 |
startLine := selectionStartLine.
|
|
875 |
startCol := selectionStartCol.
|
|
876 |
endLine := selectionEndLine.
|
|
877 |
endCol := selectionEndCol.
|
|
878 |
self unselectWithoutRedraw.
|
|
879 |
self deleteFromLine:startLine col:startCol
|
|
880 |
toLine:endLine col:endCol.
|
|
881 |
cursorCol := startCol.
|
|
882 |
cursorLine := startLine.
|
|
883 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
884 |
self makeCursorVisible
|
|
885 |
]
|
|
886 |
]
|
|
887 |
!
|
|
888 |
|
118
|
889 |
deleteFromLine:startLineNr toLine:endLineNr
|
|
890 |
"delete some lines"
|
|
891 |
|
|
892 |
readOnly ifTrue: [
|
|
893 |
exceptionBlock value:errorMessage.
|
|
894 |
^ self
|
|
895 |
].
|
|
896 |
list isNil ifTrue:[^ self].
|
|
897 |
list removeFromIndex:startLineNr toIndex:endLineNr.
|
|
898 |
widthOfWidestLine := nil. "/ i.e. unknown
|
|
899 |
self textChanged.
|
|
900 |
self redrawFromLine:startLineNr.
|
|
901 |
(firstLineShown >= list size) ifTrue:[
|
|
902 |
self makeLineVisible:(list size)
|
|
903 |
]
|
|
904 |
!
|
|
905 |
|
105
|
906 |
deleteLineWithoutRedraw:lineNr
|
|
907 |
"delete line - no redraw;
|
|
908 |
return true, if something was really deleted"
|
|
909 |
|
|
910 |
readOnly ifTrue:[
|
118
|
911 |
exceptionBlock value:errorMessage.
|
|
912 |
^ false
|
105
|
913 |
].
|
|
914 |
(list isNil or:[lineNr > list size]) ifTrue:[^ false].
|
|
915 |
list removeIndex:lineNr.
|
118
|
916 |
widthOfWidestLine := nil. "/ i.e. unknown
|
105
|
917 |
self textChanged.
|
|
918 |
^ true
|
|
919 |
!
|
|
920 |
|
|
921 |
deleteLinesWithoutRedrawFrom:startLine to:endLine
|
|
922 |
"delete lines - no redraw;
|
|
923 |
return true, if something was really deleted"
|
|
924 |
|
|
925 |
|lastLine|
|
|
926 |
|
|
927 |
readOnly ifTrue:[
|
118
|
928 |
exceptionBlock value:errorMessage.
|
|
929 |
^ false
|
105
|
930 |
].
|
|
931 |
(list isNil or:[startLine > list size]) ifTrue:[^ false].
|
|
932 |
(endLine > list size) ifTrue:[
|
118
|
933 |
lastLine := list size
|
105
|
934 |
] ifFalse:[
|
118
|
935 |
lastLine := endLine
|
105
|
936 |
].
|
|
937 |
list removeFromIndex:startLine toIndex:lastLine.
|
118
|
938 |
widthOfWidestLine := nil. "/ i.e. unknown
|
105
|
939 |
self textChanged.
|
|
940 |
^ true
|
|
941 |
!
|
|
942 |
|
|
943 |
deleteLine:lineNr
|
|
944 |
"delete line"
|
|
945 |
|
|
946 |
|visLine w
|
|
947 |
srcY "{ Class: SmallInteger }" |
|
|
948 |
|
|
949 |
w := self widthForScrollBetween:lineNr
|
|
950 |
and:(firstLineShown + nLinesShown).
|
|
951 |
(self deleteLineWithoutRedraw:lineNr) ifFalse:[^ self].
|
|
952 |
shown ifFalse:[^ self].
|
|
953 |
visLine := self listLineToVisibleLine:lineNr.
|
|
954 |
visLine notNil ifTrue:[
|
|
955 |
srcY := margin + topMargin + (visLine * fontHeight).
|
|
956 |
self catchExpose.
|
|
957 |
self copyFrom:self x:textStartLeft y:srcY
|
|
958 |
toX:textStartLeft y:(srcY - fontHeight)
|
|
959 |
width:w height:((nLinesShown - visLine) * fontHeight).
|
|
960 |
self redrawVisibleLine:nFullLinesShown.
|
|
961 |
(nFullLinesShown ~~ nLinesShown) ifTrue:[
|
|
962 |
self redrawVisibleLine:nLinesShown
|
|
963 |
].
|
|
964 |
self waitForExpose
|
|
965 |
]
|
|
966 |
!
|
|
967 |
|
|
968 |
deleteCursorLine
|
|
969 |
"delete the line where the cursor sits"
|
|
970 |
|
|
971 |
self withCursorOffDo:[
|
|
972 |
self deleteLine:cursorLine
|
|
973 |
]
|
|
974 |
!
|
|
975 |
|
|
976 |
deleteCharsAtLine:lineNr fromCol:colNr
|
|
977 |
"delete characters from colNr up to the end in line lineNr"
|
|
978 |
|
|
979 |
|line newLine|
|
|
980 |
|
|
981 |
readOnly ifTrue: [
|
118
|
982 |
exceptionBlock value:errorMessage.
|
|
983 |
^ self
|
105
|
984 |
].
|
|
985 |
list isNil ifTrue: [^self].
|
|
986 |
(list size < lineNr) ifTrue: [^ self].
|
|
987 |
line := list at:lineNr.
|
|
988 |
line isNil ifTrue: [^self].
|
|
989 |
(colNr > line size) ifTrue: [^ self].
|
|
990 |
newLine := line copyTo:(colNr - 1).
|
|
991 |
newLine isBlank ifTrue:[
|
118
|
992 |
newLine := nil
|
105
|
993 |
].
|
|
994 |
list at:lineNr put:newLine.
|
118
|
995 |
widthOfWidestLine := nil. "/ i.e. unknown
|
105
|
996 |
self textChanged.
|
|
997 |
self redrawLine:lineNr
|
|
998 |
!
|
|
999 |
|
|
1000 |
replaceSelectionBy:something
|
|
1001 |
"delete the selection (if any) and insert something, a character or string;
|
|
1002 |
leave cursor after insertion"
|
|
1003 |
|
|
1004 |
self replaceSelectionBy:something keepCursor:false
|
|
1005 |
!
|
|
1006 |
|
|
1007 |
replaceSelectionBy:something keepCursor:keep
|
|
1008 |
"delete the selection (if any) and insert something, a character or string;
|
|
1009 |
leave cursor after insertion or leave it, depending on keep"
|
|
1010 |
|
|
1011 |
|sel l c|
|
|
1012 |
|
|
1013 |
l := cursorLine.
|
|
1014 |
c := cursorCol.
|
|
1015 |
|
|
1016 |
sel := self selection.
|
|
1017 |
sel notNil ifTrue:[
|
|
1018 |
lastString := sel.
|
|
1019 |
self deleteSelection.
|
|
1020 |
replacing := true.
|
|
1021 |
lastReplacement := ''
|
|
1022 |
].
|
|
1023 |
(something isMemberOf:Character) ifTrue:[
|
|
1024 |
lastReplacement notNil ifTrue:[
|
|
1025 |
(lastReplacement endsWith:Character space) ifTrue:[
|
|
1026 |
lastReplacement := lastReplacement copyTo:(lastReplacement size - 1).
|
|
1027 |
lastReplacement := lastReplacement copyWith:something.
|
|
1028 |
lastReplacement := lastReplacement copyWith:Character space
|
|
1029 |
] ifFalse:[
|
|
1030 |
lastReplacement := lastReplacement copyWith:something.
|
|
1031 |
]
|
|
1032 |
].
|
|
1033 |
self insertCharAtCursor:something
|
|
1034 |
] ifFalse:[
|
|
1035 |
lastReplacement := something.
|
|
1036 |
self insertStringAtCursor:something
|
|
1037 |
].
|
|
1038 |
keep ifTrue:[
|
|
1039 |
self cursorLine:l col:c
|
|
1040 |
]
|
|
1041 |
!
|
|
1042 |
|
|
1043 |
deleteCharBeforeCursor
|
|
1044 |
"delete single character to the left of cursor and move cursor to left"
|
|
1045 |
|
|
1046 |
|oldSize lineNrAboveCursor|
|
|
1047 |
|
|
1048 |
(cursorCol == 1) ifFalse:[
|
|
1049 |
self withCursorOffDo:[
|
|
1050 |
cursorCol := cursorCol - 1.
|
|
1051 |
self deleteCharAtLine:cursorLine col:cursorCol
|
|
1052 |
]
|
|
1053 |
] ifTrue:[
|
|
1054 |
(cursorLine == 1) ifFalse:[
|
|
1055 |
oldSize := 0.
|
|
1056 |
lineNrAboveCursor := cursorLine - 1.
|
|
1057 |
list notNil ifTrue:[
|
|
1058 |
(list size >= lineNrAboveCursor) ifTrue:[
|
|
1059 |
(list at:lineNrAboveCursor) notNil ifTrue:[
|
|
1060 |
oldSize := (list at:lineNrAboveCursor) size
|
|
1061 |
]
|
|
1062 |
]
|
|
1063 |
].
|
|
1064 |
self mergeLine:lineNrAboveCursor.
|
|
1065 |
self withCursorOffDo:[
|
|
1066 |
cursorLine := lineNrAboveCursor.
|
|
1067 |
cursorCol := oldSize + 1.
|
|
1068 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine
|
|
1069 |
].
|
|
1070 |
self makeCursorVisible
|
|
1071 |
]
|
|
1072 |
]
|
|
1073 |
!
|
|
1074 |
|
|
1075 |
deleteCharAtCursor
|
|
1076 |
"delete single character under cursor"
|
|
1077 |
|
|
1078 |
self withCursorOffDo:[
|
|
1079 |
self deleteCharAtLine:cursorLine col:cursorCol
|
|
1080 |
]
|
|
1081 |
! !
|
|
1082 |
|
|
1083 |
!EditTextView methodsFor:'redrawing'!
|
|
1084 |
|
|
1085 |
redrawFromVisibleLine:startVisLine to:endVisLine
|
|
1086 |
"redraw a visible line range"
|
|
1087 |
|
|
1088 |
super redrawFromVisibleLine:startVisLine to:endVisLine.
|
|
1089 |
self redrawCursorIfBetweenVisibleLine:startVisLine and:endVisLine
|
|
1090 |
!
|
|
1091 |
|
|
1092 |
redrawCursorIfInVisibleLine:visLine
|
|
1093 |
"redraw the cursor, if it sits in visible line"
|
|
1094 |
|
|
1095 |
cursorShown ifTrue:[
|
|
1096 |
(visLine == cursorVisibleLine) ifTrue:[
|
|
1097 |
self drawCursorCharacter
|
|
1098 |
]
|
|
1099 |
]
|
|
1100 |
!
|
|
1101 |
|
|
1102 |
redrawCursorIfBetweenVisibleLine:startVisLine and:endVisLine
|
|
1103 |
"redraw the cursor, if it sits in a line range"
|
|
1104 |
|
|
1105 |
cursorShown ifTrue:[
|
|
1106 |
cursorVisibleLine notNil ifTrue:[
|
|
1107 |
(cursorVisibleLine between:startVisLine and:endVisLine) ifTrue:[
|
|
1108 |
self drawCursorCharacter
|
|
1109 |
]
|
|
1110 |
]
|
|
1111 |
]
|
|
1112 |
!
|
|
1113 |
|
|
1114 |
redrawVisibleLine:visLine from:startCol
|
|
1115 |
"redraw a visible line from startCol to the end of line"
|
|
1116 |
|
|
1117 |
super redrawVisibleLine:visLine from:startCol.
|
|
1118 |
self redrawCursorIfInVisibleLine:visLine
|
|
1119 |
!
|
|
1120 |
|
|
1121 |
redrawVisibleLine:visLine
|
|
1122 |
"redraw a visible line"
|
|
1123 |
|
|
1124 |
super redrawVisibleLine:visLine.
|
|
1125 |
self redrawCursorIfInVisibleLine:visLine
|
|
1126 |
!
|
|
1127 |
|
|
1128 |
redrawVisibleLine:visLine from:startCol to:endCol
|
|
1129 |
"redraw a visible line from startCol to endCol"
|
|
1130 |
|
|
1131 |
super redrawVisibleLine:visLine from:startCol to:endCol.
|
|
1132 |
self redrawCursorIfInVisibleLine:visLine
|
|
1133 |
!
|
|
1134 |
|
|
1135 |
redrawVisibleLine:visLine col:colNr
|
|
1136 |
"redraw the single character in visibleline at colNr"
|
|
1137 |
|
|
1138 |
cursorShown ifTrue:[
|
|
1139 |
(visLine == cursorVisibleLine) ifTrue:[
|
|
1140 |
(colNr == cursorCol) ifTrue:[
|
|
1141 |
self drawCursorCharacter.
|
|
1142 |
^ self
|
|
1143 |
]
|
|
1144 |
]
|
|
1145 |
].
|
|
1146 |
super redrawVisibleLine:visLine col:colNr
|
|
1147 |
! !
|
|
1148 |
|
|
1149 |
!EditTextView methodsFor:'scrolling'!
|
|
1150 |
|
|
1151 |
originChanged:delta
|
|
1152 |
"sent after scrolling - have to show the cursor if it was on before"
|
|
1153 |
|
|
1154 |
super originChanged:delta.
|
|
1155 |
"
|
|
1156 |
should we move the cursor with the scroll - or leave it ?
|
|
1157 |
"
|
|
1158 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
1159 |
prevCursorState ifTrue:[
|
|
1160 |
self showCursor
|
|
1161 |
]
|
|
1162 |
!
|
|
1163 |
|
|
1164 |
originWillChange
|
|
1165 |
"sent before scrolling - have to hide the cursor"
|
|
1166 |
|
|
1167 |
prevCursorState := cursorShown.
|
|
1168 |
cursorShown ifTrue:[
|
|
1169 |
self hideCursor
|
|
1170 |
]
|
|
1171 |
!
|
|
1172 |
|
|
1173 |
pageUp
|
|
1174 |
"page up - to keep cursor on same visible line, it has to be moved
|
|
1175 |
within the real text "
|
|
1176 |
|
|
1177 |
|prevCursorLine|
|
|
1178 |
|
|
1179 |
prevCursorLine := cursorVisibleLine.
|
|
1180 |
super pageUp.
|
|
1181 |
self cursorVisibleLine:prevCursorLine col:cursorCol
|
|
1182 |
!
|
|
1183 |
|
|
1184 |
pageDown
|
|
1185 |
"page down - to keep cursor on same visible line, it has to be moved
|
|
1186 |
within the real text "
|
|
1187 |
|
|
1188 |
|prevCursorLine|
|
|
1189 |
|
|
1190 |
prevCursorLine := cursorVisibleLine.
|
|
1191 |
super pageDown.
|
|
1192 |
self cursorVisibleLine:prevCursorLine col:cursorCol
|
|
1193 |
! !
|
|
1194 |
|
|
1195 |
!EditTextView methodsFor:'cursor handling'!
|
|
1196 |
|
|
1197 |
withCursorOffDo:aBlock
|
|
1198 |
"evaluate aBlock with cursor off"
|
|
1199 |
|
|
1200 |
(shown not or:[cursorShown not]) ifTrue:[
|
|
1201 |
^ aBlock value
|
|
1202 |
].
|
|
1203 |
self hideCursor.
|
|
1204 |
aBlock valueNowOrOnUnwindDo:[
|
|
1205 |
self showCursor
|
|
1206 |
]
|
|
1207 |
!
|
|
1208 |
|
|
1209 |
drawCursor
|
|
1210 |
"draw the cursor if shown and cursor is visible.
|
|
1211 |
(but not, if there is a selection - to avoid confusion)"
|
|
1212 |
|
|
1213 |
shown ifTrue:[
|
|
1214 |
cursorVisibleLine notNil ifTrue:[
|
|
1215 |
self hasSelection ifFalse:[
|
|
1216 |
self drawCursorCharacter
|
|
1217 |
]
|
|
1218 |
]
|
|
1219 |
]
|
|
1220 |
!
|
|
1221 |
|
|
1222 |
drawCursorCharacter
|
|
1223 |
"draw the cursor.
|
|
1224 |
(i.e. the cursor if no selection)
|
|
1225 |
- helper for many cursor methods"
|
|
1226 |
|
|
1227 |
hasKeyboardFocus ifTrue:[
|
|
1228 |
self drawFocusCursor
|
|
1229 |
] ifFalse:[
|
|
1230 |
self drawNoFocusCursor
|
|
1231 |
]
|
|
1232 |
!
|
|
1233 |
|
|
1234 |
makeCursorVisible
|
|
1235 |
"scroll to make cursor visible"
|
|
1236 |
|
|
1237 |
|line col|
|
|
1238 |
|
|
1239 |
cursorLine notNil ifTrue:[
|
|
1240 |
line := cursorLine.
|
|
1241 |
col := cursorCol.
|
|
1242 |
"
|
|
1243 |
if there is a selection, its better to
|
|
1244 |
have its start being visible, instead of the end
|
|
1245 |
"
|
|
1246 |
(selectionStartLine notNil
|
|
1247 |
and:[selectionEndLine notNil]) ifTrue:[
|
|
1248 |
|
|
1249 |
"/ that was wrong
|
|
1250 |
"/ ((line == selectionEndLine)
|
|
1251 |
"/ and:[selectionEndCol notNil
|
|
1252 |
"/ and:[col == (selectionEndCol+1)]]) ifTrue:[
|
|
1253 |
|
|
1254 |
line := selectionStartLine.
|
|
1255 |
col := selectionStartCol.
|
|
1256 |
].
|
|
1257 |
self makeLineVisible:line.
|
|
1258 |
self makeColVisible:col inLine:line
|
|
1259 |
]
|
|
1260 |
!
|
|
1261 |
|
|
1262 |
undrawCursor
|
|
1263 |
"undraw the cursor (i.e. redraw the character(s) under the cursor)"
|
|
1264 |
|
|
1265 |
cursorVisibleLine notNil ifTrue:[
|
|
1266 |
((cursorType == #caret) or:[cursorType == #solidCaret]) ifTrue:[
|
|
1267 |
"caret-cursor touches 4 characters"
|
|
1268 |
((cursorCol > 1) and:[fontIsFixedWidth]) ifTrue:[
|
|
1269 |
super redrawVisibleLine:cursorVisibleLine from:cursorCol-1 to:cursorCol.
|
|
1270 |
super redrawVisibleLine:cursorVisibleLine+1 from:cursorCol-1 to:cursorCol.
|
|
1271 |
] ifFalse:[
|
|
1272 |
"care for left margin"
|
|
1273 |
super redrawVisibleLine:cursorVisibleLine.
|
|
1274 |
super redrawVisibleLine:cursorVisibleLine+1.
|
|
1275 |
].
|
|
1276 |
^ self
|
|
1277 |
].
|
|
1278 |
cursorType == #ibeam ifTrue:[
|
|
1279 |
"ibeam-cursor touches 2 characters"
|
|
1280 |
cursorCol > 1 ifTrue:[
|
|
1281 |
super redrawVisibleLine:cursorVisibleLine from:cursorCol-1 to:cursorCol.
|
|
1282 |
] ifFalse:[
|
|
1283 |
"care for left margin"
|
|
1284 |
super redrawVisibleLine:cursorVisibleLine.
|
|
1285 |
].
|
|
1286 |
^ self
|
|
1287 |
].
|
|
1288 |
"block is simple - just one character under cursor"
|
|
1289 |
super redrawVisibleLine:cursorVisibleLine col:cursorCol
|
|
1290 |
]
|
|
1291 |
!
|
|
1292 |
|
|
1293 |
drawCursor:cursorType with:fgColor and:bgColor
|
|
1294 |
"draw a cursor; the argument cursorType specifies what type
|
|
1295 |
of cursor should be drawn."
|
|
1296 |
|
|
1297 |
|x y w char|
|
|
1298 |
|
|
1299 |
self hasSelection ifTrue:[
|
|
1300 |
"
|
|
1301 |
hide cursor, if there is a selection
|
|
1302 |
"
|
|
1303 |
^ super redrawVisibleLine:cursorVisibleLine col:cursorCol.
|
|
1304 |
].
|
|
1305 |
|
|
1306 |
cursorType == #block ifTrue:[
|
|
1307 |
super drawVisibleLine:cursorVisibleLine
|
|
1308 |
col:cursorCol
|
|
1309 |
with:fgColor
|
|
1310 |
and:bgColor.
|
|
1311 |
^ self
|
|
1312 |
].
|
|
1313 |
x := (self xOfCol:cursorCol inVisibleLine:cursorVisibleLine) - leftOffset.
|
|
1314 |
y := self yOfVisibleLine:cursorVisibleLine.
|
|
1315 |
|
|
1316 |
cursorType == #frame ifTrue:[
|
|
1317 |
super redrawVisibleLine:cursorVisibleLine col:cursorCol.
|
|
1318 |
|
|
1319 |
char := self characterUnderCursor asString.
|
|
1320 |
self paint:bgColor.
|
|
1321 |
self displayRectangleX:x y:y width:(font widthOf:char)
|
|
1322 |
height:fontHeight.
|
|
1323 |
^ self
|
|
1324 |
].
|
|
1325 |
cursorType == #ibeam ifTrue:[
|
|
1326 |
|
|
1327 |
self paint:bgColor.
|
|
1328 |
self displayLineFromX:x-1 y:y toX:x-1 y:(y + fontHeight - 1).
|
|
1329 |
self displayLineFromX:x y:y toX:x y:(y + fontHeight - 1).
|
|
1330 |
^ self
|
|
1331 |
].
|
|
1332 |
cursorType == #caret ifTrue:[
|
|
1333 |
y := y + fontHeight - 3.
|
|
1334 |
w := fontWidth // 2.
|
|
1335 |
self paint:bgColor.
|
|
1336 |
self lineWidth:2.
|
|
1337 |
self displayLineFromX:x-w y:y+w toX:x y:y.
|
|
1338 |
self displayLineFromX:x y:y toX:x+w y:y+w.
|
|
1339 |
].
|
|
1340 |
cursorType == #solidCaret ifTrue:[
|
|
1341 |
y := y + fontHeight - 3.
|
|
1342 |
w := fontWidth // 2.
|
|
1343 |
self paint:bgColor.
|
|
1344 |
self fillPolygon:(Array with:(x-w) @ (y+w)
|
|
1345 |
with:(x @ y)
|
|
1346 |
with:(x+w) @ (y+w))
|
|
1347 |
].
|
|
1348 |
!
|
|
1349 |
|
|
1350 |
hideCursor
|
|
1351 |
"make cursor invisible if currently visible; return true if cursor
|
|
1352 |
was visible"
|
|
1353 |
|
|
1354 |
cursorShown ifTrue: [
|
|
1355 |
self undrawCursor.
|
|
1356 |
cursorShown := false.
|
|
1357 |
^ true
|
|
1358 |
].
|
|
1359 |
^ false
|
|
1360 |
!
|
|
1361 |
|
|
1362 |
drawNoFocusCursor
|
|
1363 |
"draw the cursor for the case when the view has no keyboard focus"
|
|
1364 |
|
|
1365 |
self hasSelection ifTrue:[
|
|
1366 |
^ super redrawVisibleLine:cursorVisibleLine col:cursorCol.
|
|
1367 |
].
|
|
1368 |
cursorType ~~ #block ifTrue:[
|
|
1369 |
"these dont show unfocussed"
|
|
1370 |
^ self drawFocusCursor
|
|
1371 |
].
|
|
1372 |
self drawCursor:#frame with:cursorFgColor and:cursorBgColor
|
|
1373 |
!
|
|
1374 |
|
|
1375 |
showCursor
|
|
1376 |
"make cursor visible if currently invisible"
|
|
1377 |
|
|
1378 |
cursorShown ifFalse: [
|
|
1379 |
self drawCursor.
|
|
1380 |
cursorShown := true
|
|
1381 |
]
|
|
1382 |
!
|
|
1383 |
|
|
1384 |
cursorHome
|
|
1385 |
"scroll to top AND move cursor to first line of text"
|
|
1386 |
|
|
1387 |
self withCursorOffDo:[
|
|
1388 |
self scrollToTop.
|
|
1389 |
cursorCol := 1.
|
|
1390 |
cursorVisibleLine := 1.
|
|
1391 |
cursorLine := self visibleLineToAbsoluteLine:1.
|
|
1392 |
self makeCursorVisible.
|
|
1393 |
]
|
|
1394 |
!
|
|
1395 |
|
|
1396 |
drawFocusCursor
|
|
1397 |
"draw the cursor when the focus is in the view."
|
|
1398 |
|
|
1399 |
self hasSelection ifTrue:[
|
|
1400 |
^ super redrawVisibleLine:cursorVisibleLine col:cursorCol.
|
|
1401 |
].
|
|
1402 |
self drawCursor:cursorType with:cursorFgColor and:cursorBgColor.
|
|
1403 |
!
|
|
1404 |
|
|
1405 |
cursorReturn
|
|
1406 |
"move cursor to start of next line; scroll if at end of visible text"
|
|
1407 |
|
|
1408 |
self checkForExistingLine:(cursorLine + 1).
|
|
1409 |
cursorVisibleLine notNil ifTrue:[
|
|
1410 |
nFullLinesShown notNil ifTrue:[
|
|
1411 |
(cursorVisibleLine >= nFullLinesShown) ifTrue:[self scrollDown]
|
|
1412 |
]
|
|
1413 |
].
|
|
1414 |
self withCursorOffDo:[
|
|
1415 |
cursorCol := 1.
|
|
1416 |
cursorLine := cursorLine + 1.
|
|
1417 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine
|
|
1418 |
].
|
|
1419 |
self makeCursorVisible.
|
|
1420 |
!
|
|
1421 |
|
|
1422 |
cursorUp
|
|
1423 |
"move cursor up; scroll if at start of visible text"
|
|
1424 |
|
|
1425 |
(cursorLine == 1) ifFalse: [
|
|
1426 |
cursorLine isNil ifTrue:[
|
|
1427 |
cursorLine := firstLineShown + nFullLinesShown - 1.
|
|
1428 |
].
|
|
1429 |
"/ cursorVisibleLine notNil ifTrue:[
|
|
1430 |
self withCursorOffDo:[
|
|
1431 |
(cursorVisibleLine == 1) ifTrue:[self scrollUp].
|
|
1432 |
cursorLine := cursorLine - 1.
|
|
1433 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
1434 |
].
|
|
1435 |
"/ ] ifFalse:[
|
|
1436 |
"/ self makeCursorVisible.
|
|
1437 |
"/ ]
|
|
1438 |
]
|
|
1439 |
!
|
|
1440 |
|
|
1441 |
cursorToBottom
|
|
1442 |
"move cursor to last line of text"
|
|
1443 |
|
|
1444 |
self withCursorOffDo:[
|
|
1445 |
|newTop|
|
|
1446 |
|
|
1447 |
newTop := list size - nFullLinesShown.
|
|
1448 |
(newTop < 1) ifTrue:[
|
|
1449 |
newTop := 1
|
|
1450 |
].
|
|
1451 |
self scrollToLine:newTop.
|
|
1452 |
cursorCol := 1.
|
|
1453 |
cursorLine := list size.
|
|
1454 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
1455 |
self makeCursorVisible.
|
|
1456 |
]
|
|
1457 |
!
|
|
1458 |
|
|
1459 |
cursorDown
|
|
1460 |
"move cursor down; scroll if at end of visible text"
|
|
1461 |
|
|
1462 |
cursorVisibleLine notNil ifTrue:[
|
|
1463 |
self withCursorOffDo:[
|
|
1464 |
(cursorVisibleLine >= nFullLinesShown) ifTrue:[self scrollDown].
|
|
1465 |
cursorLine := cursorLine + 1.
|
|
1466 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine
|
|
1467 |
]
|
|
1468 |
] ifFalse:[
|
|
1469 |
cursorLine isNil ifTrue:[
|
|
1470 |
cursorLine := firstLineShown
|
|
1471 |
].
|
|
1472 |
cursorLine := cursorLine + 1.
|
|
1473 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
1474 |
self makeCursorVisible.
|
|
1475 |
].
|
|
1476 |
!
|
|
1477 |
|
|
1478 |
cursorRight
|
|
1479 |
"move cursor to right"
|
|
1480 |
|
|
1481 |
self withCursorOffDo:[cursorCol := cursorCol + 1].
|
|
1482 |
self makeCursorVisible.
|
|
1483 |
!
|
|
1484 |
|
|
1485 |
cursorLeft
|
|
1486 |
"move cursor to left"
|
|
1487 |
|
|
1488 |
(cursorCol == 1) ifFalse: [
|
|
1489 |
self withCursorOffDo:[cursorCol := cursorCol - 1]
|
|
1490 |
].
|
|
1491 |
self makeCursorVisible.
|
|
1492 |
!
|
|
1493 |
|
|
1494 |
cursorToEndOfLine
|
|
1495 |
"move cursor to end of current line"
|
|
1496 |
|
|
1497 |
self withCursorOffDo:[
|
|
1498 |
|line|
|
|
1499 |
|
|
1500 |
list isNil ifTrue:[
|
|
1501 |
cursorCol := 1
|
|
1502 |
] ifFalse:[
|
|
1503 |
line := list at:cursorLine.
|
|
1504 |
cursorCol := line size + 1
|
|
1505 |
].
|
|
1506 |
self makeCursorVisible.
|
|
1507 |
].
|
|
1508 |
!
|
|
1509 |
|
|
1510 |
cursorToBeginOfLine
|
|
1511 |
"move cursor to start of current line"
|
|
1512 |
|
|
1513 |
self withCursorOffDo:[
|
|
1514 |
cursorCol := 1
|
|
1515 |
].
|
|
1516 |
self makeCursorVisible.
|
|
1517 |
!
|
|
1518 |
|
|
1519 |
cursorTab
|
|
1520 |
"move cursor to next tabstop"
|
|
1521 |
|
|
1522 |
self withCursorOffDo:[
|
|
1523 |
cursorCol := self nextTabAfter:cursorCol
|
|
1524 |
].
|
|
1525 |
self makeCursorVisible.
|
|
1526 |
!
|
|
1527 |
|
|
1528 |
cursorLine:line col:col
|
|
1529 |
"this positions onto physical - not visible - line"
|
|
1530 |
|
|
1531 |
self withCursorOffDo:[
|
|
1532 |
cursorLine := line.
|
|
1533 |
cursorVisibleLine := self listLineToVisibleLine:line.
|
|
1534 |
cursorCol := col.
|
|
1535 |
(cursorCol < 1) ifTrue:[
|
|
1536 |
cursorCol := 1
|
|
1537 |
]
|
|
1538 |
].
|
|
1539 |
self makeCursorVisible.
|
|
1540 |
!
|
|
1541 |
|
|
1542 |
cursorBacktab
|
|
1543 |
"move cursor to prev tabstop"
|
|
1544 |
|
|
1545 |
self withCursorOffDo:[
|
|
1546 |
cursorCol := self prevTabBefore:cursorCol
|
|
1547 |
].
|
|
1548 |
self makeCursorVisible.
|
|
1549 |
!
|
|
1550 |
|
|
1551 |
cursorToNextWord
|
|
1552 |
"move the cursor to the beginning of the next word"
|
|
1553 |
|
|
1554 |
|col line searching|
|
|
1555 |
|
|
1556 |
(cursorLine > list size) ifTrue:[^ self].
|
|
1557 |
self wordAtLine:cursorLine col:cursorCol do:[
|
|
1558 |
:beginLine :beginCol :endLine :endCol :style |
|
|
1559 |
|
|
1560 |
line := endLine.
|
|
1561 |
col := endCol + 1.
|
|
1562 |
searching := true.
|
|
1563 |
[searching
|
|
1564 |
and:[(self characterAtLine:line col:col) isSeparator]] whileTrue:[
|
|
1565 |
self wordAtLine:line col:col do:[
|
|
1566 |
:beginLine :beginCol :endLine :endCol :style |
|
|
1567 |
|
|
1568 |
(line > list size) ifTrue:[
|
|
1569 |
"break out"
|
|
1570 |
searching := false
|
|
1571 |
] ifFalse:[
|
|
1572 |
line := endLine.
|
|
1573 |
col := endCol + 1.
|
|
1574 |
]
|
|
1575 |
]
|
|
1576 |
].
|
|
1577 |
self cursorLine:line col:col
|
|
1578 |
]
|
|
1579 |
!
|
|
1580 |
|
|
1581 |
cursorVisibleLine:visibleLineNr col:colNr
|
|
1582 |
"put cursor to visibleline/col"
|
|
1583 |
|
|
1584 |
self withCursorOffDo:[
|
|
1585 |
cursorLine := self visibleLineToAbsoluteLine:visibleLineNr.
|
|
1586 |
cursorVisibleLine := visibleLineNr.
|
|
1587 |
cursorCol := colNr.
|
|
1588 |
(cursorCol < 1) ifTrue:[
|
|
1589 |
cursorCol := 1
|
|
1590 |
]
|
|
1591 |
].
|
|
1592 |
self makeCursorVisible.
|
|
1593 |
!
|
|
1594 |
|
|
1595 |
cursorX:x y:y
|
|
1596 |
"put cursor to position next to x/y coordinate in view"
|
|
1597 |
|
|
1598 |
|line col|
|
|
1599 |
|
|
1600 |
line := self visibleLineOfY:y.
|
|
1601 |
col := self colOfX:x inVisibleLine:line.
|
|
1602 |
self cursorVisibleLine:line col:col.
|
|
1603 |
!
|
|
1604 |
|
|
1605 |
cursorToTop
|
|
1606 |
"move cursor to absolute home"
|
|
1607 |
|
|
1608 |
self cursorLine:1 col:1
|
|
1609 |
!
|
|
1610 |
|
|
1611 |
gotoLine:aLineNumber
|
|
1612 |
"position cursor onto line, aLineNumber.
|
|
1613 |
Make certain that this line is visible"
|
|
1614 |
|
|
1615 |
self makeLineVisible:aLineNumber.
|
|
1616 |
self cursorLine:aLineNumber col:1
|
|
1617 |
! !
|
|
1618 |
|
|
1619 |
!EditTextView methodsFor:'accessing'!
|
|
1620 |
|
|
1621 |
characterUnderCursor
|
|
1622 |
"return the character under the cursor - space if behond line.
|
|
1623 |
For non-block cursors, this is the character immediately to the right
|
|
1624 |
of the insertion-bar or caret."
|
|
1625 |
|
|
1626 |
^ self characterAtLine:cursorLine col:cursorCol
|
|
1627 |
!
|
|
1628 |
|
|
1629 |
list:something
|
|
1630 |
"position cursor home when setting contents"
|
|
1631 |
|
|
1632 |
super list:something.
|
|
1633 |
self cursorHome
|
|
1634 |
!
|
|
1635 |
|
|
1636 |
cursorForegroundColor:color1 backgroundColor:color2
|
|
1637 |
"set both cursor foreground and cursor background colors"
|
|
1638 |
|
|
1639 |
self hideCursor.
|
|
1640 |
cursorFgColor := color1 on:device.
|
|
1641 |
cursorBgColor := color2 on:device.
|
|
1642 |
self showCursor
|
|
1643 |
!
|
|
1644 |
|
|
1645 |
cursorLine
|
|
1646 |
"return the cursors line (1..).
|
|
1647 |
This is the absolute line; NOT the visible line"
|
|
1648 |
|
|
1649 |
^ cursorLine
|
|
1650 |
!
|
|
1651 |
|
|
1652 |
contents
|
|
1653 |
"return the contents as a String"
|
|
1654 |
|
|
1655 |
list isNil ifTrue:[^ ''].
|
|
1656 |
self removeTrailingBlankLines.
|
|
1657 |
^ list asStringWithCRs
|
|
1658 |
!
|
|
1659 |
|
|
1660 |
cursorCol
|
|
1661 |
"return the cursors col (1..).
|
|
1662 |
This is the absolute col; NOT the visible col"
|
|
1663 |
|
|
1664 |
^ cursorCol
|
|
1665 |
!
|
|
1666 |
|
|
1667 |
readOnly
|
|
1668 |
"make the text readonly"
|
|
1669 |
|
|
1670 |
readOnly := true
|
|
1671 |
!
|
|
1672 |
|
|
1673 |
fixedSize
|
|
1674 |
"make the texts size fixed (no lines may be added).
|
|
1675 |
OBSOLETE: use readOnly"
|
|
1676 |
|
|
1677 |
readOnly ifFalse:[
|
|
1678 |
readOnly := true.
|
|
1679 |
middleButtonMenu disable:#cut.
|
|
1680 |
middleButtonMenu disable:#paste.
|
|
1681 |
middleButtonMenu disable:#replace.
|
|
1682 |
middleButtonMenu disable:#indent
|
|
1683 |
]
|
|
1684 |
!
|
|
1685 |
|
|
1686 |
exceptionBlock:aBlock
|
|
1687 |
"define the action to be triggered when user tries to modify
|
|
1688 |
readonly text"
|
|
1689 |
|
|
1690 |
exceptionBlock := aBlock
|
|
1691 |
!
|
|
1692 |
|
|
1693 |
modified:aBoolean
|
|
1694 |
"set the modified flag"
|
|
1695 |
|
|
1696 |
modified := aBoolean
|
|
1697 |
!
|
|
1698 |
|
|
1699 |
modified
|
|
1700 |
"return true if text was modified"
|
|
1701 |
|
|
1702 |
^ modified
|
|
1703 |
!
|
|
1704 |
|
|
1705 |
fromFile:aFileName
|
|
1706 |
"take contents from a named file"
|
|
1707 |
|
|
1708 |
self contents:(aFileName asFilename readStream contents)
|
|
1709 |
! !
|
|
1710 |
|
0
|
1711 |
!EditTextView methodsFor:'initialization'!
|
|
1712 |
|
105
|
1713 |
initEvents
|
|
1714 |
"enable enter/leave events in addition"
|
|
1715 |
|
|
1716 |
super initEvents.
|
|
1717 |
self enableEnterLeaveEvents
|
|
1718 |
!
|
|
1719 |
|
|
1720 |
initStyle
|
|
1721 |
"initialize style specific stuff"
|
|
1722 |
|
|
1723 |
super initStyle.
|
|
1724 |
cursorFgColor := DefaultCursorForegroundColor.
|
|
1725 |
cursorFgColor isNil ifTrue:[cursorFgColor := bgColor].
|
|
1726 |
cursorBgColor := DefaultCursorBackgroundColor.
|
|
1727 |
cursorBgColor isNil ifTrue:[cursorBgColor := fgColor].
|
|
1728 |
cursorType := DefaultCursorType.
|
|
1729 |
!
|
|
1730 |
|
|
1731 |
realize
|
|
1732 |
"make the view visible"
|
|
1733 |
|
|
1734 |
super realize.
|
|
1735 |
cursorFgColor := cursorFgColor on:device.
|
|
1736 |
cursorBgColor := cursorBgColor on:device.
|
|
1737 |
!
|
|
1738 |
|
0
|
1739 |
initialize
|
25
|
1740 |
"initialize a new EditTextView;
|
|
1741 |
setup some instance variables"
|
|
1742 |
|
0
|
1743 |
super initialize.
|
|
1744 |
|
|
1745 |
self level:-1.
|
|
1746 |
errorMessage := 'Text may not me changed'.
|
|
1747 |
readOnly := false.
|
|
1748 |
fixedSize := false.
|
|
1749 |
exceptionBlock := [:errorText | ].
|
7
|
1750 |
cursorShown := prevCursorState := true.
|
0
|
1751 |
cursorLine := 1.
|
|
1752 |
cursorVisibleLine := 1.
|
|
1753 |
cursorCol := 1.
|
7
|
1754 |
modified := false.
|
46
|
1755 |
showMatchingParenthesis := false.
|
77
|
1756 |
hasKeyboardFocus := false. "/ true.
|
0
|
1757 |
!
|
|
1758 |
|
97
|
1759 |
editMenu
|
|
1760 |
"return the views middleButtonMenu"
|
|
1761 |
|
|
1762 |
|labels selectors m sub|
|
|
1763 |
|
|
1764 |
labels := #(
|
|
1765 |
"/ 'undo'
|
|
1766 |
'again'
|
|
1767 |
'-'
|
|
1768 |
'copy'
|
|
1769 |
'cut'
|
|
1770 |
'paste'
|
|
1771 |
'-'
|
|
1772 |
'accept'
|
|
1773 |
'='
|
|
1774 |
'others'
|
|
1775 |
).
|
|
1776 |
|
|
1777 |
selectors := #(
|
|
1778 |
"/ undo
|
|
1779 |
again
|
|
1780 |
nil
|
|
1781 |
copySelection
|
|
1782 |
cut
|
|
1783 |
paste
|
|
1784 |
nil
|
|
1785 |
accept
|
|
1786 |
nil
|
|
1787 |
others
|
|
1788 |
).
|
|
1789 |
|
|
1790 |
m := PopUpMenu
|
|
1791 |
labels:(resources array:labels)
|
|
1792 |
selectors:selectors.
|
|
1793 |
|
|
1794 |
labels := #(
|
|
1795 |
'search ...'
|
|
1796 |
'goto ...'
|
|
1797 |
'-'
|
|
1798 |
'font ...'
|
|
1799 |
'-'
|
|
1800 |
'indent'
|
|
1801 |
'-'
|
|
1802 |
'save as ...'
|
|
1803 |
'print'
|
|
1804 |
).
|
|
1805 |
|
|
1806 |
selectors := #(
|
|
1807 |
search
|
|
1808 |
gotoLine
|
|
1809 |
nil
|
|
1810 |
changeFont
|
|
1811 |
nil
|
|
1812 |
indent
|
|
1813 |
nil
|
|
1814 |
save
|
|
1815 |
print
|
|
1816 |
).
|
|
1817 |
|
|
1818 |
sub := PopUpMenu
|
|
1819 |
labels:(resources array:labels)
|
|
1820 |
selectors:selectors
|
|
1821 |
receiver:model.
|
|
1822 |
|
|
1823 |
m subMenuAt:#others put:sub.
|
|
1824 |
|
|
1825 |
readOnly ifTrue:[
|
|
1826 |
m disable:#paste
|
|
1827 |
].
|
|
1828 |
self hasSelection not ifTrue:[
|
|
1829 |
m disable:#copySelection.
|
|
1830 |
].
|
|
1831 |
(self hasSelection not or:[readOnly]) ifTrue:[
|
|
1832 |
m disable:#cut.
|
|
1833 |
sub disable:#indent.
|
|
1834 |
].
|
|
1835 |
^ m.
|
0
|
1836 |
! !
|
|
1837 |
|
|
1838 |
!EditTextView methodsFor:'event processing'!
|
|
1839 |
|
105
|
1840 |
buttonRelease:button x:x y:y
|
|
1841 |
"move the cursor to the click-position of previous button press"
|
|
1842 |
|
|
1843 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
1844 |
typeOfSelection := nil.
|
|
1845 |
selectionStartLine isNil ifTrue:[
|
|
1846 |
clickCol notNil ifTrue:[
|
|
1847 |
self cursorLine:clickLine col:clickCol
|
|
1848 |
]
|
|
1849 |
] ifFalse:[
|
|
1850 |
lastString := nil. "new selection invalidates remembered string"
|
|
1851 |
].
|
|
1852 |
self showCursor
|
|
1853 |
].
|
|
1854 |
super buttonRelease:button x:x y:y
|
0
|
1855 |
!
|
|
1856 |
|
62
|
1857 |
pointerEnter:state x:x y:y
|
77
|
1858 |
(windowGroup isNil or:[windowGroup focusView isNil]) ifTrue:[
|
|
1859 |
hasKeyboardFocus := true.
|
|
1860 |
cursorShown ifTrue: [self drawCursor].
|
|
1861 |
].
|
46
|
1862 |
super pointerEnter:state x:x y:y
|
|
1863 |
!
|
|
1864 |
|
62
|
1865 |
pointerLeave:state
|
77
|
1866 |
(windowGroup isNil or:[windowGroup focusView isNil]) ifTrue:[
|
|
1867 |
hasKeyboardFocus := false.
|
|
1868 |
cursorShown ifTrue: [self drawCursor].
|
|
1869 |
].
|
46
|
1870 |
super pointerLeave:state
|
|
1871 |
!
|
|
1872 |
|
105
|
1873 |
buttonPress:button x:x y:y
|
|
1874 |
"hide the cursor when button is activated"
|
|
1875 |
|
|
1876 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
1877 |
self hideCursor
|
|
1878 |
].
|
|
1879 |
(button == #paste) ifTrue:[
|
|
1880 |
self paste.
|
|
1881 |
^ self
|
|
1882 |
].
|
|
1883 |
super buttonPress:button x:x y:y
|
|
1884 |
!
|
|
1885 |
|
|
1886 |
sizeChanged:how
|
|
1887 |
"make certain, cursor is visible after the sizechange"
|
|
1888 |
|
|
1889 |
|cv|
|
|
1890 |
|
|
1891 |
cv := cursorVisibleLine.
|
|
1892 |
super sizeChanged:how.
|
|
1893 |
cv notNil ifTrue:[
|
|
1894 |
self makeLineVisible:cursorLine
|
|
1895 |
]
|
|
1896 |
!
|
|
1897 |
|
77
|
1898 |
showFocus
|
|
1899 |
hasKeyboardFocus := true.
|
|
1900 |
cursorShown ifTrue: [self drawCursor].
|
|
1901 |
super showFocus
|
|
1902 |
!
|
|
1903 |
|
0
|
1904 |
keyPress:key x:x y:y
|
|
1905 |
"handle keyboard input"
|
|
1906 |
|
|
1907 |
(key isMemberOf:Character) ifTrue:[
|
77
|
1908 |
readOnly ifFalse:[
|
|
1909 |
typeOfSelection == #paste ifTrue:[
|
|
1910 |
"pasted selection will NOT be replaced by keystroke"
|
|
1911 |
self unselect
|
|
1912 |
].
|
|
1913 |
|
|
1914 |
"replace selection by what is typed in -
|
|
1915 |
if word was selected with a space, keep it"
|
|
1916 |
|
|
1917 |
(selectStyle == #wordLeft) ifTrue:[
|
|
1918 |
self replaceSelectionBy:(' ' copyWith:key)
|
59
|
1919 |
] ifFalse:[
|
77
|
1920 |
(selectStyle == #wordRight) ifTrue:[
|
|
1921 |
self replaceSelectionBy:(key asString , ' ').
|
|
1922 |
self cursorLeft
|
|
1923 |
] ifFalse:[
|
|
1924 |
self replaceSelectionBy:key
|
|
1925 |
]
|
|
1926 |
].
|
|
1927 |
selectStyle := nil.
|
|
1928 |
|
|
1929 |
showMatchingParenthesis ifTrue:[
|
|
1930 |
"emacs style parenthesis shower"
|
|
1931 |
|
|
1932 |
"claus: only do it for closing parenthesis -
|
|
1933 |
otherwise its too anoying.
|
|
1934 |
"
|
33
|
1935 |
"
|
77
|
1936 |
(#( $( $) $[ $] ${ $} ) includes:key) ifTrue:[
|
|
1937 |
"
|
|
1938 |
(#( $) $] $} ) includes:key) ifTrue:[
|
|
1939 |
self searchForMatchingParenthesisFromLine:cursorLine col:(cursorCol - 1)
|
|
1940 |
ifFound:[:line :col |
|
|
1941 |
|savLine savCol|
|
|
1942 |
|
|
1943 |
savLine := cursorLine.
|
|
1944 |
savCol := cursorCol.
|
|
1945 |
self cursorLine:line col:col.
|
|
1946 |
device synchronizeOutput.
|
|
1947 |
OperatingSystem millisecondDelay:200.
|
|
1948 |
self cursorLine:savLine col:savCol
|
|
1949 |
]
|
|
1950 |
ifNotFound:[self showNotFound]
|
|
1951 |
onError:[device beep]
|
|
1952 |
].
|
59
|
1953 |
].
|
|
1954 |
].
|
|
1955 |
^ self
|
33
|
1956 |
].
|
0
|
1957 |
|
7
|
1958 |
replacing := false.
|
|
1959 |
|
33
|
1960 |
"
|
|
1961 |
Fn pastes a key-sequence (but only if not overlayed with
|
59
|
1962 |
another function in the keyboard map)
|
33
|
1963 |
|
|
1964 |
see TextView>>keyPress:x:y
|
|
1965 |
"
|
7
|
1966 |
(#(F1 F2 F3 F4 F5 F6 F7 F8 F9) includes:key) ifTrue:[
|
59
|
1967 |
device shiftDown ifFalse:[
|
|
1968 |
(Smalltalk at:#FunctionKeySequences) notNil ifTrue:[
|
81
|
1969 |
self paste:((Smalltalk at:#FunctionKeySequences) at:key) asStringCollection.
|
59
|
1970 |
^ self
|
|
1971 |
]
|
|
1972 |
]
|
7
|
1973 |
].
|
|
1974 |
|
0
|
1975 |
((key == #Paste) or:[key == #Insert]) ifTrue:[self paste. ^self].
|
|
1976 |
(key == #Cut) ifTrue:[self cut. ^self].
|
7
|
1977 |
(key == #Again) ifTrue:[self again. ^self].
|
0
|
1978 |
|
|
1979 |
(key == #Replace) ifTrue:[self replace. ^self].
|
59
|
1980 |
(key == #SelectWord) ifTrue:[
|
|
1981 |
self makeCursorVisible.
|
|
1982 |
^ self selectWordUnderCursor.
|
0
|
1983 |
].
|
|
1984 |
|
13
|
1985 |
(key == #SearchMatchingParent) ifTrue:[^ self searchForMatchingParenthesis.].
|
|
1986 |
(key == #SelectMatchingParents) ifTrue:[^ self searchForAndSelectMatchingParenthesis.].
|
|
1987 |
(key == #SelectToEnd) ifTrue:[^ self selectUpToEnd.].
|
|
1988 |
(key == #SelectFromBeginning) ifTrue:[^ self selectFromBeginning.].
|
0
|
1989 |
|
10
|
1990 |
" disabled - nobody liked it ...
|
|
1991 |
and if you like it, its better done in the keymap.
|
|
1992 |
|
0
|
1993 |
(key == #Ctrlb) ifTrue:[self unselect. self cursorLeft. ^self].
|
|
1994 |
(key == #Ctrlf) ifTrue:[self unselect. self cursorRight. ^self].
|
|
1995 |
(key == #Ctrln) ifTrue:[self unselect. self cursorDown. ^self].
|
|
1996 |
(key == #Ctrlp) ifTrue:[self unselect. self cursorUp. ^self].
|
10
|
1997 |
"
|
0
|
1998 |
|
10
|
1999 |
(key == #BeginOfLine) ifTrue:[self cursorToBeginOfLine. ^self].
|
|
2000 |
(key == #EndOfLine) ifTrue:[self cursorToEndOfLine. ^self].
|
59
|
2001 |
(key == #NextWord) ifTrue:[self cursorToNextWord. ^self].
|
|
2002 |
(key == #GotoLine) ifTrue:[self gotoLine. ^self].
|
|
2003 |
|
|
2004 |
(key == #CursorRight) ifTrue:[
|
|
2005 |
selectionStartLine notNil ifTrue:[
|
|
2006 |
cursorLine := selectionEndLine.
|
|
2007 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
2008 |
cursorCol := selectionEndCol.
|
|
2009 |
cursorCol == 0 ifTrue:[
|
|
2010 |
cursorCol := 1.
|
|
2011 |
].
|
|
2012 |
self unselect.
|
|
2013 |
self makeCursorVisible.
|
|
2014 |
cursorCol == 1 ifTrue:[^ self].
|
|
2015 |
].
|
|
2016 |
self cursorRight. ^self
|
0
|
2017 |
].
|
59
|
2018 |
(key == #CursorDown) ifTrue:[
|
|
2019 |
selectionStartLine notNil ifTrue:[
|
|
2020 |
cursorLine := selectionEndLine.
|
|
2021 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
2022 |
cursorCol := selectionEndCol.
|
|
2023 |
cursorCol == 0 ifTrue:[
|
|
2024 |
cursorCol := 1.
|
|
2025 |
cursorLine := cursorLine - 1.
|
|
2026 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
2027 |
].
|
|
2028 |
self makeCursorVisible
|
|
2029 |
].
|
|
2030 |
self unselect.
|
|
2031 |
self cursorDown. ^self
|
0
|
2032 |
].
|
59
|
2033 |
(key == #CursorLeft or:[key == #CursorUp]) ifTrue:[
|
|
2034 |
selectionStartLine notNil ifTrue:[
|
|
2035 |
cursorLine := selectionStartLine.
|
|
2036 |
cursorVisibleLine := self listLineToVisibleLine:cursorLine.
|
|
2037 |
cursorCol := selectionStartCol.
|
|
2038 |
self makeCursorVisible
|
|
2039 |
].
|
|
2040 |
self unselect.
|
|
2041 |
(key == #CursorLeft) ifTrue:[
|
|
2042 |
self cursorLeft. ^self
|
|
2043 |
].
|
|
2044 |
(key == #CursorUp) ifTrue:[
|
|
2045 |
self cursorUp. ^self
|
|
2046 |
].
|
0
|
2047 |
].
|
|
2048 |
|
|
2049 |
(key == #Return) ifTrue:[
|
59
|
2050 |
device shiftDown ifTrue:[
|
|
2051 |
self unselect. self cursorReturn. ^self
|
|
2052 |
].
|
|
2053 |
self unselect.
|
|
2054 |
self makeCursorVisible.
|
|
2055 |
self insertCharAtCursor:(Character cr).
|
|
2056 |
^self
|
0
|
2057 |
].
|
|
2058 |
(key == #Tab) ifTrue:[
|
59
|
2059 |
device shiftDown ifTrue:[
|
|
2060 |
"
|
|
2061 |
the old version used shift-tab as backtab,
|
|
2062 |
however, backtab was seldom used.
|
|
2063 |
An alternative is to make it a non-inserting tab ...
|
|
2064 |
"
|
|
2065 |
"/ self unselect. self cursorBacktab. ^self
|
|
2066 |
self unselect. self cursorTab. ^self
|
|
2067 |
].
|
|
2068 |
"
|
|
2069 |
uncomment line below, if you like RAND/INed/MAXed editor behavior
|
|
2070 |
(where tab-key is only cursor positioning)
|
|
2071 |
this was the original behavior of the TAB key, but many people
|
|
2072 |
complained ....
|
|
2073 |
"
|
|
2074 |
"/ self unselect. self cursorTab. ^self
|
|
2075 |
self unselect. self insertTabAtCursor. ^self
|
0
|
2076 |
].
|
7
|
2077 |
(key == #BackSpace) ifTrue:[
|
|
2078 |
|
|
2079 |
" old version just did unselect here "
|
|
2080 |
"
|
59
|
2081 |
self unselect.
|
7
|
2082 |
"
|
|
2083 |
" new version deletes selection if any "
|
59
|
2084 |
selectionStartLine notNil ifTrue:[
|
77
|
2085 |
self setTextSelection:(self selection).
|
59
|
2086 |
self deleteSelection. ^ self
|
|
2087 |
].
|
|
2088 |
self makeCursorVisible.
|
|
2089 |
self deleteCharBeforeCursor. ^self
|
7
|
2090 |
].
|
0
|
2091 |
(key == #Delete) ifTrue:[
|
59
|
2092 |
selectionStartLine notNil ifTrue:[
|
77
|
2093 |
self setTextSelection:(self selection).
|
59
|
2094 |
self deleteSelection. ^ self
|
|
2095 |
].
|
|
2096 |
self makeCursorVisible.
|
|
2097 |
self deleteCharBeforeCursor. ^self
|
0
|
2098 |
].
|
|
2099 |
(key == #Home) ifTrue:[
|
59
|
2100 |
self unselect. self cursorHome. ^self
|
0
|
2101 |
].
|
|
2102 |
(key == #End) ifTrue:[
|
59
|
2103 |
self unselect. self cursorToBottom. ^self
|
0
|
2104 |
].
|
|
2105 |
(key == #Escape) ifTrue:[
|
59
|
2106 |
self makeCursorVisible.
|
|
2107 |
self unselect. self selectCursorLine. ^ self
|
0
|
2108 |
].
|
|
2109 |
(key == #DeleteLine) ifTrue:[
|
59
|
2110 |
self makeCursorVisible.
|
|
2111 |
self unselect. self deleteCursorLine. ^self
|
0
|
2112 |
].
|
|
2113 |
super keyPress:key x:x y:y
|
|
2114 |
!
|
|
2115 |
|
105
|
2116 |
showNoFocus
|
|
2117 |
hasKeyboardFocus := false.
|
|
2118 |
cursorShown ifTrue: [self drawCursor].
|
|
2119 |
super showNoFocus
|
|
2120 |
|
|
2121 |
! !
|
|
2122 |
|
|
2123 |
!EditTextView methodsFor:'selections'!
|
|
2124 |
|
|
2125 |
unselect
|
|
2126 |
"forget and unhilight selection - must take care of cursor here"
|
|
2127 |
|
|
2128 |
self withCursorOffDo:[
|
|
2129 |
super unselect
|
|
2130 |
]
|
|
2131 |
!
|
|
2132 |
|
|
2133 |
selectFromLine:startLine col:startCol toLine:endLine col:endCol
|
|
2134 |
"when a range is selected, position the cursor behind the selection
|
|
2135 |
for easier editing. Also typeOfSelection is nilled here."
|
|
2136 |
|
|
2137 |
super selectFromLine:startLine col:startCol toLine:endLine col:endCol.
|
|
2138 |
self cursorLine:selectionEndLine col:(selectionEndCol + 1).
|
|
2139 |
typeOfSelection := nil
|
|
2140 |
!
|
|
2141 |
|
|
2142 |
selectAll
|
|
2143 |
"select the whole text.
|
|
2144 |
redefined to send super selectFrom... since we dont want the
|
|
2145 |
cursor to be moved in this case."
|
|
2146 |
|
|
2147 |
list isNil ifTrue:[
|
|
2148 |
self unselect
|
|
2149 |
] ifFalse:[
|
|
2150 |
super selectFromLine:1 col:1 toLine:(list size + 1) col:0.
|
|
2151 |
typeOfSelection := nil
|
|
2152 |
]
|
|
2153 |
!
|
|
2154 |
|
|
2155 |
selectCursorLine
|
|
2156 |
"select cursorline up to cursor position"
|
|
2157 |
|
|
2158 |
self selectFromLine:cursorLine col:1
|
|
2159 |
toLine:cursorLine col:cursorCol
|
|
2160 |
!
|
|
2161 |
|
|
2162 |
selectWordUnderCursor
|
|
2163 |
"select the word under the cursor"
|
|
2164 |
|
|
2165 |
self selectWordAtLine:cursorLine col:cursorCol
|
|
2166 |
!
|
|
2167 |
|
|
2168 |
selectFromBeginning
|
|
2169 |
"select the text from the beginning to the current cursor position."
|
|
2170 |
|
|
2171 |
|col|
|
|
2172 |
|
|
2173 |
list isNil ifTrue:[
|
|
2174 |
self unselect
|
|
2175 |
] ifFalse:[
|
|
2176 |
cursorCol == 0 ifTrue:[
|
|
2177 |
col := 0
|
|
2178 |
] ifFalse:[
|
|
2179 |
col := cursorCol - 1
|
|
2180 |
].
|
|
2181 |
super selectFromLine:1 col:1 toLine:cursorLine col:col.
|
|
2182 |
typeOfSelection := nil
|
|
2183 |
]
|
|
2184 |
!
|
|
2185 |
|
|
2186 |
selectUpToEnd
|
|
2187 |
"select the text from the current cursor position to the end."
|
|
2188 |
|
|
2189 |
list isNil ifTrue:[
|
|
2190 |
self unselect
|
|
2191 |
] ifFalse:[
|
|
2192 |
super selectFromLine:cursorLine col:cursorCol toLine:(list size + 1) col:0.
|
|
2193 |
typeOfSelection := nil
|
|
2194 |
]
|
|
2195 |
! !
|
|
2196 |
|
|
2197 |
!EditTextView methodsFor:'formatting'!
|
|
2198 |
|
|
2199 |
indent
|
|
2200 |
"indent selected line-range"
|
|
2201 |
|
|
2202 |
|start end|
|
|
2203 |
|
|
2204 |
selectionStartLine isNil ifTrue:[^ self].
|
|
2205 |
start := selectionStartLine.
|
|
2206 |
end := selectionEndLine.
|
|
2207 |
(selectionEndCol == 0) ifTrue:[
|
|
2208 |
end := end - 1
|
|
2209 |
].
|
|
2210 |
self unselect.
|
|
2211 |
self indentFromLine:start toLine:end
|
|
2212 |
!
|
|
2213 |
|
|
2214 |
indentFromLine:start toLine:end
|
|
2215 |
"indent a line-range - this is don by searching for the
|
|
2216 |
last non-empty line before start, and change the indent
|
|
2217 |
of the line based on that indent."
|
|
2218 |
|
|
2219 |
|leftStart lnr delta d line spaces|
|
|
2220 |
|
|
2221 |
"find a line to base indent on..."
|
|
2222 |
leftStart := 0.
|
|
2223 |
lnr := start.
|
|
2224 |
[(leftStart == 0) and:[lnr ~~ 1]] whileTrue:[
|
118
|
2225 |
lnr := lnr - 1.
|
|
2226 |
leftStart := self leftIndentOfLine:lnr
|
105
|
2227 |
].
|
|
2228 |
|
|
2229 |
(leftStart == 0) ifTrue:[^ self].
|
|
2230 |
|
|
2231 |
delta := leftStart - (self leftIndentOfLine:start).
|
|
2232 |
(delta == 0) ifTrue:[^ self].
|
|
2233 |
(delta > 0) ifTrue:[
|
118
|
2234 |
spaces := String new:delta
|
105
|
2235 |
].
|
|
2236 |
start to:end do:[:lineNr |
|
118
|
2237 |
line := self listAt:lineNr.
|
|
2238 |
line notNil ifTrue:[
|
|
2239 |
line isBlank ifTrue:[
|
|
2240 |
list at:lineNr put:nil
|
|
2241 |
] ifFalse:[
|
|
2242 |
(delta > 0) ifTrue:[
|
|
2243 |
line := spaces , line.
|
|
2244 |
widthOfWidestLine notNil ifTrue:[
|
|
2245 |
widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:line).
|
|
2246 |
]
|
|
2247 |
] ifFalse:[
|
|
2248 |
"check if deletion is ok"
|
|
2249 |
d := delta negated + 1.
|
|
2250 |
|
|
2251 |
line size > d ifTrue:[
|
|
2252 |
(line copyTo:(d - 1)) withoutSeparators isEmpty ifTrue:[
|
|
2253 |
line := line copyFrom:d
|
|
2254 |
]
|
|
2255 |
].
|
|
2256 |
widthOfWidestLine := nil
|
|
2257 |
].
|
|
2258 |
list at:lineNr put:line.
|
|
2259 |
self textChanged.
|
|
2260 |
]
|
|
2261 |
]
|
0
|
2262 |
].
|
105
|
2263 |
self redrawFromLine:start to:end
|
|
2264 |
! !
|
|
2265 |
|
|
2266 |
!EditTextView methodsFor:'undo & again'!
|
|
2267 |
|
|
2268 |
undo
|
|
2269 |
"currently not implemented"
|
|
2270 |
|
|
2271 |
undoAction notNil ifTrue:[
|
|
2272 |
undoAction value
|
|
2273 |
]
|
|
2274 |
!
|
|
2275 |
|
|
2276 |
again
|
|
2277 |
"repeat the last action (which was a cut or replace).
|
|
2278 |
If current selection is not last string, search forward to
|
|
2279 |
next occurence of it before repeating the last operation."
|
|
2280 |
|
|
2281 |
|s l c sel|
|
|
2282 |
|
|
2283 |
lastString notNil ifTrue:[
|
|
2284 |
s := lastString asString.
|
|
2285 |
"remove final cr"
|
|
2286 |
s := s copyTo:(s size - 1).
|
|
2287 |
|
|
2288 |
sel := self selection.
|
|
2289 |
|
|
2290 |
"if we are already there (after a find), ommit search"
|
|
2291 |
|
|
2292 |
(sel notNil and:[sel asString withoutSeparators = s]) ifTrue:[
|
|
2293 |
undoAction := [self insertLines:lastString atLine:cursorLine col:cursorCol].
|
|
2294 |
l := selectionStartLine "cursorLine".
|
|
2295 |
c := selectionStartCol "cursorCol".
|
|
2296 |
self deleteSelection.
|
|
2297 |
lastReplacement notNil ifTrue:[
|
|
2298 |
self insertLines:lastReplacement asStringCollection withCr:false.
|
|
2299 |
self selectFromLine:l col:c toLine:cursorLine col:(cursorCol - 1).
|
|
2300 |
].
|
|
2301 |
^ true
|
|
2302 |
].
|
|
2303 |
|
|
2304 |
self searchForwardFor:s startingAtLine:cursorLine col:cursorCol
|
|
2305 |
ifFound:
|
|
2306 |
[
|
|
2307 |
:line :col |
|
|
2308 |
|
|
2309 |
self selectFromLine:line col:col
|
|
2310 |
toLine:line col:(col + s size - 1).
|
|
2311 |
self makeLineVisible:line.
|
|
2312 |
undoAction := [self insertLines:lastString atLine:line col:col].
|
|
2313 |
|
|
2314 |
self deleteSelection.
|
|
2315 |
lastReplacement notNil ifTrue:[
|
|
2316 |
self insertLines:lastReplacement asStringCollection withCr:false.
|
|
2317 |
self selectFromLine:line col:col toLine:cursorLine col:(cursorCol - 1).
|
|
2318 |
].
|
|
2319 |
^ true
|
|
2320 |
]
|
|
2321 |
ifAbsent:
|
|
2322 |
[
|
|
2323 |
self showNotFound.
|
|
2324 |
^ false
|
|
2325 |
]
|
|
2326 |
]
|
|
2327 |
!
|
|
2328 |
|
|
2329 |
multipleAgain
|
|
2330 |
"repeat the last action (which was a cut or replace) until search fails"
|
|
2331 |
|
|
2332 |
[self again] whileTrue:[]
|
|
2333 |
! !
|
|
2334 |
|
|
2335 |
!EditTextView methodsFor:'menu actions'!
|
|
2336 |
|
|
2337 |
paste
|
|
2338 |
"paste copybuffer; if there is a selection, replace it.
|
|
2339 |
otherwise paste at cursor position. Replace is not done
|
|
2340 |
for originating by a paste, to allow multiple
|
|
2341 |
paste."
|
|
2342 |
|
|
2343 |
|sel|
|
|
2344 |
|
|
2345 |
((self hasSelection == true) and:[typeOfSelection ~~ #paste]) ifTrue:[
|
|
2346 |
^ self replace
|
|
2347 |
].
|
|
2348 |
sel := self getTextSelection.
|
|
2349 |
sel notNil ifTrue:[
|
|
2350 |
self paste:sel.
|
|
2351 |
]
|
|
2352 |
!
|
|
2353 |
|
|
2354 |
cut
|
|
2355 |
"cut selection into copybuffer"
|
|
2356 |
|
|
2357 |
|line col history sel|
|
|
2358 |
|
|
2359 |
sel := self selection.
|
|
2360 |
sel notNil ifTrue:[
|
|
2361 |
lastString := sel.
|
|
2362 |
line := selectionStartLine.
|
|
2363 |
col := selectionStartCol.
|
|
2364 |
undoAction := [self insertLines:lastString atLine:line col:col].
|
|
2365 |
|
|
2366 |
"
|
|
2367 |
remember in CopyBuffer
|
|
2368 |
"
|
|
2369 |
self setTextSelection:lastString.
|
|
2370 |
|
|
2371 |
"
|
|
2372 |
append to DeleteHistory (if there is one)
|
|
2373 |
"
|
|
2374 |
history := Smalltalk at:#DeleteHistory.
|
|
2375 |
history notNil ifTrue:[
|
|
2376 |
history addAll:(lastString asStringCollection).
|
|
2377 |
history size > 1000 ifTrue:[
|
|
2378 |
history := history copyFrom:(history size - 1000)
|
|
2379 |
].
|
|
2380 |
].
|
|
2381 |
|
|
2382 |
"
|
|
2383 |
now, delete it
|
|
2384 |
"
|
|
2385 |
self deleteSelection.
|
|
2386 |
lastReplacement := nil
|
|
2387 |
] ifFalse:[
|
|
2388 |
"
|
|
2389 |
a cut without selection will search&cut again
|
|
2390 |
"
|
|
2391 |
self again
|
|
2392 |
]
|
|
2393 |
!
|
|
2394 |
|
|
2395 |
defaultForGotoLine
|
|
2396 |
"return a default value to show in the gotoLine box"
|
|
2397 |
|
|
2398 |
cursorLine notNil ifTrue:[
|
|
2399 |
^ cursorLine
|
|
2400 |
].
|
|
2401 |
^ super defaultForGotoLine
|
|
2402 |
!
|
|
2403 |
|
|
2404 |
replace
|
|
2405 |
"replace selection by copybuffer"
|
|
2406 |
|
|
2407 |
|sel|
|
|
2408 |
|
|
2409 |
sel := self getTextSelection.
|
|
2410 |
sel notNil ifTrue:[
|
|
2411 |
self replace:sel
|
|
2412 |
]
|
|
2413 |
!
|
|
2414 |
|
|
2415 |
paste:someText
|
|
2416 |
"paste someText at cursor"
|
|
2417 |
|
|
2418 |
|s startLine startCol|
|
|
2419 |
|
|
2420 |
someText notNil ifTrue:[
|
|
2421 |
s := someText.
|
|
2422 |
s isString ifTrue:[
|
|
2423 |
s := s asStringCollection
|
|
2424 |
] ifFalse:[
|
|
2425 |
(s isKindOf:StringCollection) ifFalse:[
|
|
2426 |
self warn:'selection not convertable to Text'.
|
|
2427 |
^ self
|
|
2428 |
]
|
|
2429 |
].
|
|
2430 |
startLine := cursorLine.
|
|
2431 |
startCol := cursorCol.
|
|
2432 |
self insertLines:s asStringCollection withCr:false.
|
|
2433 |
self selectFromLine:startLine col:startCol
|
|
2434 |
toLine:cursorLine col:(cursorCol - 1).
|
|
2435 |
typeOfSelection := #paste.
|
|
2436 |
undoAction := [self cut].
|
|
2437 |
]
|
|
2438 |
!
|
|
2439 |
|
|
2440 |
replace:someText
|
|
2441 |
"replace selection by someText"
|
|
2442 |
|
|
2443 |
|selected selectedString replacement replacementString
|
|
2444 |
cutOffSpace addSpace|
|
|
2445 |
|
|
2446 |
selected := self selection.
|
|
2447 |
selected isNil ifTrue:[
|
|
2448 |
^ self paste:someText
|
|
2449 |
].
|
|
2450 |
self deleteSelection.
|
|
2451 |
|
|
2452 |
"take care, if we replace a selection without space by a word selected
|
|
2453 |
with one - in this case we usually do not want the space.
|
|
2454 |
But, if we replace a word-selected selection by something without a
|
|
2455 |
space, we DO want the space added."
|
|
2456 |
|
|
2457 |
cutOffSpace := false.
|
|
2458 |
addSpace := false.
|
|
2459 |
|
|
2460 |
replacement := someText copy.
|
|
2461 |
|
|
2462 |
selected size == 1 ifTrue:[
|
|
2463 |
selectedString := selected at:1.
|
|
2464 |
].
|
|
2465 |
selectedString notNil ifTrue:[
|
|
2466 |
((selectedString startsWith:' ') or:[selectedString endsWith:' ']) ifFalse:[
|
|
2467 |
"selection has no space"
|
|
2468 |
|
|
2469 |
((selectStyle == #wordleft) or:[selectStyle == #wordRight]) ifTrue:[
|
|
2470 |
cutOffSpace := true
|
|
2471 |
]
|
|
2472 |
] ifTrue:[
|
|
2473 |
addSpace := true
|
|
2474 |
]
|
|
2475 |
].
|
|
2476 |
|
|
2477 |
replacement size == 1 ifTrue:[
|
|
2478 |
replacementString := replacement at:1.
|
|
2479 |
cutOffSpace ifTrue:[
|
|
2480 |
(replacementString startsWith:' ') ifTrue:[
|
|
2481 |
replacementString := replacementString withoutSpaces
|
|
2482 |
].
|
|
2483 |
] ifFalse:[
|
|
2484 |
selectStyle == #wordLeft ifTrue:[
|
|
2485 |
"want a space at left"
|
|
2486 |
(replacementString startsWith:' ') ifFalse:[
|
|
2487 |
replacementString := replacementString withoutSpaces.
|
|
2488 |
replacementString := ' ' , replacementString
|
|
2489 |
]
|
|
2490 |
].
|
|
2491 |
selectStyle == #wordRight ifTrue:[
|
|
2492 |
"want a space at right"
|
|
2493 |
|
|
2494 |
(replacementString endsWith:' ') ifFalse:[
|
|
2495 |
replacementString := replacementString withoutSpaces.
|
|
2496 |
replacementString := replacementString , ' '
|
|
2497 |
]
|
|
2498 |
].
|
|
2499 |
].
|
|
2500 |
replacement at:1 put: replacementString.
|
|
2501 |
self paste:replacement
|
|
2502 |
] ifFalse:[
|
|
2503 |
self paste:someText.
|
|
2504 |
].
|
|
2505 |
lastString := selectedString.
|
|
2506 |
lastReplacement := someText
|
|
2507 |
!
|
|
2508 |
|
|
2509 |
showDeleted
|
|
2510 |
"open a readonly editor on all deleted text"
|
|
2511 |
|
|
2512 |
|v|
|
|
2513 |
|
|
2514 |
v := EditTextView openWith:(Smalltalk at:#ScratchBuffer).
|
|
2515 |
v readOnly.
|
|
2516 |
v topView label:'deleted text'.
|
|
2517 |
! !
|
|
2518 |
|
|
2519 |
!EditTextView methodsFor:'searching'!
|
|
2520 |
|
|
2521 |
setSearchPattern
|
|
2522 |
"set the searchpattern from the selection if there is one, and position
|
|
2523 |
cursor to start of pattern"
|
|
2524 |
|
|
2525 |
|sel|
|
|
2526 |
|
|
2527 |
"if last operation was a replcae, set pattern to last
|
|
2528 |
original string (for search after again)"
|
|
2529 |
|
|
2530 |
(lastString notNil and:[lastReplacement notNil]) ifTrue:[
|
|
2531 |
searchPattern := lastString asString withoutSeparators.
|
59
|
2532 |
^ self
|
33
|
2533 |
].
|
105
|
2534 |
|
|
2535 |
sel := self selection.
|
|
2536 |
sel notNil ifTrue:[
|
|
2537 |
self cursorLine:selectionStartLine col:selectionStartCol.
|
|
2538 |
searchPattern := sel asString withoutSeparators
|
|
2539 |
]
|
|
2540 |
!
|
|
2541 |
|
|
2542 |
searchFwd:pattern startingAtLine:startLine col:startCol ifAbsent:aBlock
|
|
2543 |
"do a forward search"
|
|
2544 |
|
|
2545 |
cursorLine isNil ifTrue:[^ self].
|
|
2546 |
self searchForwardFor:pattern startingAtLine:startLine col:startCol
|
|
2547 |
ifFound:[:line :col |
|
|
2548 |
self cursorLine:line col:col.
|
|
2549 |
self selectFromLine:line col:col
|
|
2550 |
toLine:line col:(col + pattern size - 1).
|
|
2551 |
self makeLineVisible:cursorLine
|
|
2552 |
] ifAbsent:aBlock
|
|
2553 |
!
|
|
2554 |
|
|
2555 |
searchFwd:pattern ifAbsent:aBlock
|
|
2556 |
"do a forward search"
|
|
2557 |
|
118
|
2558 |
|startCol|
|
|
2559 |
|
|
2560 |
"/ if there is no selection and the cursor is at the origin,
|
|
2561 |
"/ assume its the first search and do not skip the very first match
|
|
2562 |
startCol := cursorCol.
|
|
2563 |
self hasSelection ifFalse:[
|
|
2564 |
(cursorLine == 1 and:[cursorCol == 1]) ifTrue:[
|
|
2565 |
startCol := 0
|
|
2566 |
]
|
|
2567 |
].
|
|
2568 |
|
|
2569 |
self searchFwd:pattern startingAtLine:cursorLine col:startCol ifAbsent:aBlock
|
105
|
2570 |
!
|
|
2571 |
|
|
2572 |
searchBwd:pattern ifAbsent:aBlock
|
|
2573 |
"do a backward search"
|
|
2574 |
|
|
2575 |
|startLine startCol|
|
|
2576 |
|
|
2577 |
cursorLine isNil ifTrue:[^ self].
|
|
2578 |
selectionStartLine notNil ifTrue:[
|
|
2579 |
startLine := selectionStartLine.
|
|
2580 |
startCol := selectionStartCol
|
|
2581 |
] ifFalse:[
|
|
2582 |
startLine := cursorLine min:list size.
|
|
2583 |
startCol := cursorCol
|
|
2584 |
].
|
|
2585 |
self searchBackwardFor:pattern startingAtLine:startLine col:startCol
|
|
2586 |
ifFound:[:line :col |
|
|
2587 |
self cursorLine:line col:col.
|
|
2588 |
self selectFromLine:line col:col
|
|
2589 |
toLine:line col:(col + pattern size - 1).
|
|
2590 |
self makeLineVisible:cursorLine
|
|
2591 |
] ifAbsent:aBlock
|
0
|
2592 |
!
|
|
2593 |
|
105
|
2594 |
searchForMatchingParenthesisFromLine:startLine col:startCol
|
|
2595 |
ifFound:foundBlock
|
|
2596 |
ifNotFound:notFoundBlock
|
|
2597 |
onError:failBlock
|
|
2598 |
|
|
2599 |
"search for a matching parenthesis, parChar is one of '$( $[ ${ $) $] $}'.
|
|
2600 |
Search for the corresponding character is done forward if its an opening,
|
|
2601 |
backwards if its a closing parenthesis.
|
|
2602 |
Performs foundBlock with line/col as argument if found, notFoundBlock if not.
|
|
2603 |
If there is a nesting error, performs failBlock."
|
|
2604 |
|
|
2605 |
|i direction lineString line col parChar charSet ignoreSet closingChar
|
|
2606 |
ignoring delta endCol cc incSet decSet nesting maxLine|
|
|
2607 |
|
|
2608 |
charSet := #( $( $) $[ $] ${ $} ).
|
|
2609 |
ignoreSet := #( $' $" ).
|
|
2610 |
|
|
2611 |
parChar := self characterAtLine:startLine col:startCol.
|
|
2612 |
i := charSet indexOf:parChar.
|
|
2613 |
i == 0 ifTrue:[
|
|
2614 |
^ failBlock value "not a parenthesis"
|
|
2615 |
].
|
|
2616 |
direction := #( fwd bwd fwd bwd fwd bwd) at:i.
|
|
2617 |
closingChar := #( $) $( $] $[ $} ${ ) at:i.
|
|
2618 |
|
|
2619 |
col := startCol.
|
|
2620 |
line := startLine.
|
|
2621 |
direction == #fwd ifTrue:[
|
|
2622 |
delta := 1.
|
|
2623 |
incSet := #( $( $[ ${ ).
|
|
2624 |
decSet := #( $) $] $} ).
|
|
2625 |
] ifFalse:[
|
|
2626 |
delta := -1.
|
|
2627 |
incSet := #( $) $] $} ).
|
|
2628 |
decSet := #( $( $[ ${ ).
|
|
2629 |
].
|
|
2630 |
|
|
2631 |
nesting := 1.
|
|
2632 |
ignoring := false.
|
|
2633 |
lineString := list at:line.
|
|
2634 |
maxLine := list size.
|
|
2635 |
|
|
2636 |
col := col + delta.
|
|
2637 |
[nesting ~~ 0] whileTrue:[
|
|
2638 |
lineString notNil ifTrue:[
|
|
2639 |
direction == #fwd ifTrue:[
|
|
2640 |
endCol := lineString size.
|
|
2641 |
] ifFalse:[
|
|
2642 |
endCol := 1
|
|
2643 |
].
|
|
2644 |
col to:endCol by:delta do:[:runCol |
|
|
2645 |
cc := lineString at:runCol.
|
|
2646 |
|
|
2647 |
(ignoreSet includes:cc) ifTrue:[
|
|
2648 |
ignoring := ignoring not
|
|
2649 |
].
|
|
2650 |
ignoring ifFalse:[
|
|
2651 |
(incSet includes:cc) ifTrue:[
|
|
2652 |
nesting := nesting + 1
|
|
2653 |
] ifFalse:[
|
|
2654 |
(decSet includes:cc) ifTrue:[
|
|
2655 |
nesting := nesting - 1
|
|
2656 |
]
|
|
2657 |
]
|
|
2658 |
].
|
|
2659 |
nesting == 0 ifTrue:[
|
|
2660 |
"check if legal"
|
|
2661 |
|
|
2662 |
cc == closingChar ifFalse:[
|
|
2663 |
^ failBlock value
|
|
2664 |
].
|
|
2665 |
^ foundBlock value:line value:runCol.
|
|
2666 |
]
|
|
2667 |
].
|
|
2668 |
].
|
|
2669 |
line := line + delta.
|
|
2670 |
(line < 1 or:[line > maxLine]) ifTrue:[
|
|
2671 |
^ failBlock value
|
|
2672 |
].
|
|
2673 |
lineString := list at:line.
|
|
2674 |
direction == #fwd ifTrue:[
|
|
2675 |
col := 1
|
59
|
2676 |
] ifFalse:[
|
105
|
2677 |
col := lineString size
|
|
2678 |
]
|
0
|
2679 |
].
|
105
|
2680 |
|
|
2681 |
^ notFoundBlock value
|
|
2682 |
!
|
|
2683 |
|
|
2684 |
searchForMatchingParenthesis
|
|
2685 |
"search for a matching parenthesis starting at cursor position.
|
|
2686 |
Search for the corresponding character is done forward if its an opening,
|
|
2687 |
backwards if its a closing parenthesis.
|
|
2688 |
Positions the cursor if found, peeps if not"
|
|
2689 |
|
|
2690 |
self searchForMatchingParenthesisFromLine:cursorLine col:cursorCol
|
|
2691 |
ifFound:[:line :col | self cursorLine:line col:col]
|
|
2692 |
ifNotFound:[self showNotFound]
|
|
2693 |
onError:[device beep]
|
|
2694 |
!
|
|
2695 |
|
|
2696 |
searchForAndSelectMatchingParenthesis
|
|
2697 |
"select characters enclosed by matching parenthesis if one is under cusor"
|
|
2698 |
|
|
2699 |
self searchForMatchingParenthesisFromLine:cursorLine col:cursorCol
|
|
2700 |
ifFound:[:line :col |
|
|
2701 |
self selectFromLine:cursorLine col:cursorCol
|
|
2702 |
toLine:line col:col
|
|
2703 |
]
|
|
2704 |
ifNotFound:[self showNotFound]
|
|
2705 |
onError:[device beep]
|
0
|
2706 |
! !
|
105
|
2707 |
|