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