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