--- a/EditTextView.st Tue Oct 02 20:03:26 2001 +0200
+++ b/EditTextView.st Thu Oct 04 14:54:24 2001 +0200
@@ -22,7 +22,7 @@
autoIndent insertMode trimBlankLines wordWrap
replacementWordSelectStyle acceptChannel acceptEnabled st80Mode
disableIfInvisible cursorMovementWhenUpdating learnMode
- learnedMacro'
+ learnedMacro cursorLineHolder cursorColHolder'
classVariableNames:'DefaultCursorForegroundColor DefaultCursorBackgroundColor
DefaultCursorType DefaultCursorNoFocusForegroundColor ST80Mode
DefaultCursorTypeNoFocus'
@@ -724,6 +724,12 @@
^ cursorCol
!
+cursorColHolder
+ "return a valueHolder for the cursors column (1..)."
+
+ ^ cursorColHolder
+!
+
cursorLine
"return the cursors line (1..).
This is the absolute line; NOT the visible line"
@@ -731,6 +737,13 @@
^ cursorLine
!
+cursorLineHolder
+ "return a valueHolder for the cursors line (1..).
+ This is the absolute line; NOT the visible line"
+
+ ^ cursorLineHolder
+!
+
fixedSize
"make the texts size fixed (no lines may be added).
OBSOLETE: use readOnly"
@@ -1009,7 +1022,7 @@
|wasOn|
wasOn := self hideCursor.
- cursorCol := self validateCursorCol:newCol inLine:cursorLine.
+ self setValidatedCursorCol:newCol.
self makeCursorVisibleAndShowCursor:wasOn.
"Modified: 22.5.1996 / 14:25:53 / cg"
@@ -1026,10 +1039,7 @@
"/ cursor behond text ?
cursorLine > list size ifTrue:[
wasOn := self hideCursor.
- cursorLine := self validateCursorLine:(list size + 1).
- cursorCol := self validateCursorCol:cursorCol inLine:cursorLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
- "/ wasOn ifTrue:[self showCursor].
+ self setValidatedCursorLine:(list size + 1) col:cursorCol.
self makeCursorVisibleAndShowCursor:wasOn.
self beep.
].
@@ -1040,7 +1050,7 @@
cursorDown:n
"move cursor down by n lines; scroll if at end of visible text"
- |wasOn nv|
+ |wasOn nv nL|
cursorVisibleLine notNil ifTrue:[
wasOn := self hideCursor.
@@ -1048,18 +1058,13 @@
(nv >= nFullLinesShown) ifTrue:[
self scrollDown:(nv - nFullLinesShown + 1)
].
- cursorLine := self validateCursorLine:(cursorLine + n).
- cursorCol := self validateCursorCol:cursorCol inLine:cursorLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
- "/ wasOn ifTrue:[self showCursor].
+ self setValidatedCursorLine:(cursorLine + n) col:cursorCol.
self makeCursorVisibleAndShowCursor:wasOn.
] ifFalse:[
- cursorLine isNil ifTrue:[
- cursorLine := firstLineShown
+ (nL := cursorLine) isNil ifTrue:[
+ nL := firstLineShown
].
- cursorLine := self validateCursorLine:(cursorLine + n).
- cursorCol := self validateCursorCol:cursorCol inLine:cursorLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+ self setValidatedCursorLine:(nL + n) col:cursorCol.
self makeCursorVisible.
].
@@ -1106,8 +1111,8 @@
|wasOn newCol|
wasOn := self hideCursor.
- cursorLine := self validateCursorLine:line.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+ self setValidatedCursorLine:line.
+
(col < 1) ifTrue:[
newCol := 1
] ifFalse:[
@@ -1119,7 +1124,7 @@
newCol := (self listAt:(list size)) size + 1.
]
].
- cursorCol := self validateCursorCol:newCol inLine:cursorLine.
+ self setValidatedCursorCol:newCol.
self makeCursorVisibleAndShowCursor:wasOn.
"Modified: / 20.6.1998 / 18:19:06 / cg"
@@ -1150,9 +1155,7 @@
].
wasOn := self hideCursor.
- cursorLine := self validateCursorLine:cursorLine + 1.
- cursorCol := self validateCursorCol:1 inLine:cursorLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+ self setValidatedCursorLine:(cursorLine + 1) col:1.
self makeCursorVisibleAndShowCursor:wasOn.
"Modified: 22.5.1996 / 18:27:34 / cg"
@@ -1225,9 +1228,8 @@
newTop := 1
].
self scrollToLine:newTop.
- cursorLine := self validateCursorLine:list size.
- cursorCol := self validateCursorCol:1 inLine:cursorLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+
+ self setValidatedCursorLine:(list size) col:1.
self makeCursorVisibleAndShowCursor:wasOn.
@@ -1250,11 +1252,11 @@
cursorToEnd
"move cursor down below last line of text"
- |wasOn newTop l line|
-
- l := list size.
-
- cursorLine >= l ifTrue:[
+ |wasOn newTop lineNr line|
+
+ lineNr := list size.
+
+ cursorLine >= lineNr ifTrue:[
line := self listAt:cursorLine.
(line isNil or:[line isEmpty]) ifTrue:[
^ self
@@ -1263,15 +1265,14 @@
wasOn := self hideCursor.
- l := l + 1.
- newTop := l - nFullLinesShown.
+ lineNr := lineNr + 1.
+ newTop := lineNr - nFullLinesShown.
(newTop < 1) ifTrue:[
newTop := 1
].
self scrollToLine:newTop.
- cursorLine := self validateCursorLine:l.
- cursorCol := self validateCursorCol:1 inLine:1.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+
+ self setValidatedCursorLine:lineNr col:1.
self makeCursorVisibleAndShowCursor:wasOn.
@@ -1301,12 +1302,11 @@
newTop := 1
].
self scrollToLine:newTop.
- cursorLine := self validateCursorLine:list size.
- cursorCol := self validateCursorCol:(self listAt:cursorLine) size inLine:cursorLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+
+ self setValidatedCursorLine:list size.
+ self setCursorCol:(self validateCursorCol:(self listAt:cursorLine) size inLine:cursorLine).
self makeCursorVisibleAndShowCursor:wasOn.
-
!
cursorToFirstVisibleLine
@@ -1327,6 +1327,7 @@
|col line searching|
(cursorLine > list size) ifTrue:[^ self].
+
self wordAtLine:cursorLine col:cursorCol do:[
:beginLine :beginCol :endLine :endCol :style |
@@ -1356,7 +1357,7 @@
|col line searching l|
- (cursorLine > list size) ifTrue:[^ self].
+ (cursorLine > list size) ifTrue:[^ self]. "/ this is rubbish
self wordAtLine:cursorLine col:cursorCol do:[
:beginLine :beginCol :endLine :endCol :style |
@@ -1427,7 +1428,7 @@
|wasOn nv nl|
cursorLine isNil ifTrue:[
- cursorLine := firstLineShown + nFullLinesShown - 1.
+ self setCursorLine:(firstLineShown + nFullLinesShown - 1).
].
nl := cursorLine - n.
nl < 1 ifTrue:[nl := 1].
@@ -1440,14 +1441,8 @@
self scrollUp:(nv negated + 1)
].
].
- cursorLine := self validateCursorLine:nl.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
- cursorCol := self validateCursorCol:cursorCol inLine:cursorLine.
+ self setValidatedCursorLine:nl col:cursorCol.
wasOn ifTrue:[self showCursor].
-"/
-"/ to make cursor visible (even if below visible end):
-"/
-"/ self makeCursorVisibleAndShowCursor:wasOn.
]
"Modified: 22.5.1996 / 18:28:11 / cg"
@@ -1456,16 +1451,20 @@
cursorVisibleLine:visibleLineNr col:colNr
"put cursor to visibleline/col"
- |wasOn newCol|
+ |wasOn newCol listLine|
wasOn := self hideCursor.
- cursorLine := self validateCursorLine:(self visibleLineToAbsoluteLine:visibleLineNr).
+
+ listLine := self visibleLineToAbsoluteLine:visibleLineNr.
+ self setValidatedCursorLine:listLine.
cursorVisibleLine := visibleLineNr.
+
newCol := colNr.
(newCol < 1) ifTrue:[
newCol := 1
].
- cursorCol := self validateCursorCol:newCol inLine:cursorLine.
+ self setValidatedCursorCol:newCol.
+
self makeCursorVisibleAndShowCursor:wasOn.
"Modified: / 20.6.1998 / 18:40:28 / cg"
@@ -1692,6 +1691,47 @@
flag ifTrue:[self showCursor]
!
+setCursorCol:colNr
+ "strictly private: set the cursorCol"
+
+ cursorCol := colNr.
+ cursorColHolder value:cursorCol.
+!
+
+setCursorLine:lineNr
+ "strictly private: set the cursorLine"
+
+ cursorLine := lineNr.
+ cursorLineHolder value:cursorLine.
+ self updateCursorVisibleLine.
+!
+
+setCursorLine:lineNr col:colNr
+ "strictly private: set the cursorLine, col and update the visibleLine"
+
+ self setCursorLine:lineNr.
+ self setCursorCol:colNr.
+!
+
+setValidatedCursorCol:colNr
+ "strictly private: set the cursorCol"
+
+ self setCursorCol:(self validateCursorCol:colNr inLine:cursorLine).
+!
+
+setValidatedCursorLine:lineNr
+ "strictly private: set the cursorLine and update the visibleLine"
+
+ self setCursorLine:(self validateCursorLine:lineNr).
+!
+
+setValidatedCursorLine:lineNr col:colNr
+ "strictly private: set the cursorLine, col and update the visibleLine"
+
+ self setValidatedCursorLine:lineNr.
+ self setValidatedCursorCol:colNr.
+!
+
showCursor
"make cursor visible if currently invisible"
@@ -1783,6 +1823,13 @@
"Modified: / 15.12.1999 / 22:25:59 / cg"
!
+updateCursorVisibleLine
+ "strictly private: set the visibleLine from the cursorLine.
+ notice: visibleLine will be set to nil if the cursor is not visible"
+
+ cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+!
+
validateCursorCol:col inLine:line
"check of col is a valid cursor position; return a new col-nr if not.
Here, no limits are enforced (and col is returned),
@@ -2009,11 +2056,9 @@
endLine := selectionEndLine.
endCol := selectionEndCol.
self unselectWithoutRedraw.
- self deleteFromLine:startLine col:startCol
- toLine:endLine col:endCol.
- cursorCol := startCol.
- cursorLine := startLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+ self deleteFromLine:startLine col:startCol toLine:endLine col:endCol.
+ self setCursorLine:startLine col:startCol.
+
self makeCursorVisibleAndShowCursor:wasOn
]
!
@@ -2031,8 +2076,10 @@
beginLine := cursorLine.
deletedText := self textFromLine:beginLine col:beginCol toLine:endLine col:endCol.
self deleteFromLine:beginLine col:beginCol toLine:endLine col:endCol.
- undoAction := [ self cursorLine:beginLine col:beginCol.
- self paste:deletedText].
+ undoAction := [
+ self cursorLine:beginLine col:beginCol.
+ self paste:deletedText
+ ].
wasOn ifTrue:[ self showCursor ].
"Modified: / 22.2.2000 / 23:59:04 / cg"
@@ -2107,8 +2154,7 @@
(end >= start) ifTrue:[
wasOn := self hideCursor.
self insertLines:lines from:start to:end before:cursorLine.
- cursorLine := cursorLine + (end - start + 1).
- cursorVisibleLine := self absoluteLineToVisibleLine:cursorLine.
+ self setCursorLine:(cursorLine + (end - start + 1)).
wasOn ifTrue:[self showCursor].
]
].
@@ -2227,20 +2273,21 @@
"insert a string (which has no crs) at cursor position
- advance cursor"
- |wasOn oldLen newLen|
-
- aString notNil ifTrue:[
+ |wasOn oldLen newLen deltaLen|
+
+ aString size > 0 ifTrue:[
wasOn := self hideCursor.
(aString includes:Character tab) ifTrue:[
self checkForExistingLine:cursorLine.
oldLen := (list at:cursorLine) size.
self insertString:aString atLine:cursorLine col:cursorCol.
newLen := (list at:cursorLine) size.
- cursorCol := cursorCol + (newLen - oldLen).
+ deltaLen := newLen - oldLen.
] ifFalse:[
self insertString:aString atLine:cursorLine col:cursorCol.
- cursorCol := cursorCol + aString size.
+ deltaLen := aString size.
].
+ self setCursorCol:(cursorCol + deltaLen).
wasOn ifTrue:[self showCursor]
]
@@ -3472,12 +3519,11 @@
"/
"/ treat the whole selection as cursor
"/
- cursorLine := selectionEndLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+ self setCursorLine:selectionEndLine.
selectionEndCol == 0 ifTrue:[
selectionEndCol := 1.
].
- cursorCol := selectionEndCol.
+ self setCursorCol:selectionEndCol.
shifted ifTrue:[
self expandSelectionRight.
^ self
@@ -3502,13 +3548,11 @@
"/
"/ treat the whole selection as cursor
"/
- cursorLine := selectionEndLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
- cursorCol := selectionStartCol.
+ self setCursorLine:selectionEndLine.
+ self setCursorCol:selectionStartCol.
cursorCol == 0 ifTrue:[
- cursorCol := 1.
- cursorLine := cursorLine - 1.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+ self setCursorCol:1.
+ self setCursorLine:(cursorLine - 1).
].
self makeCursorVisible.
@@ -3559,11 +3603,10 @@
"/
"/ treat the whole selection as cursor
"/
- cursorLine := selectionStartLine.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
- cursorCol := selectionStartCol.
+ self setCursorLine:selectionStartLine.
+ self setCursorCol:selectionStartCol.
(key == #CursorLeft) ifTrue:[
- cursorCol := cursorCol+1. "/ compensate for followup crsr-left
+ self setCursorCol:(cursorCol+1). "/ compensate for followup crsr-left
].
self makeCursorVisible.
@@ -3719,10 +3762,7 @@
"view was made visible"
super mapped.
-"/ self makeCursorVisible.
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
-
- "Modified: 20.12.1996 / 14:15:56 / cg"
+ self updateCursorVisibleLine.
!
sizeChanged:how
@@ -3935,6 +3975,8 @@
fixedSize := false.
exceptionBlock := [:errorText | ].
cursorShown := prevCursorState := true.
+ cursorLineHolder := 1 asValue.
+ cursorColHolder := 1 asValue.
cursorLine := 1.
cursorVisibleLine := 1.
cursorCol := 1.
@@ -4524,7 +4566,7 @@
"
should we move the cursor with the scroll - or leave it ?
"
- cursorVisibleLine := self listLineToVisibleLine:cursorLine.
+ self updateCursorVisibleLine.
prevCursorState ifTrue:[
self showCursor
]
@@ -4974,5 +5016,5 @@
!EditTextView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.255 2001-10-02 16:32:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.256 2001-10-04 12:54:24 cg Exp $'
! !