From: Masatsugu Nagata (nagata@kurims.kyoto-u.ac.jp)
Date: 8 Mar 01, 02:27 EST
From: Masatsugu Nagata <nagata@kurims.kyoto-u.ac.jp>
Subject: Twiddle? - correction
My apologies. The 'transposeChars' proc that I have just posted had
a bug. It works fine when there is no selection when the proc is called
(in which case the proc simply transposes the characters before and after
the current position, leaving the position unchanged (and leaves nothing
selected), while it does nothing if the position was at the beginning or
at the end of the file), but when there was a text selection when the proc
was called, it behaves as: does nothing if only one character was selected;
and transposes the first and the last character of the selection, and
leaves the region selected, when two or more characters were selected.
The bug was that it failed to do anything if two or more chars were
selected _and_ the selection started at the beginning of file (that is,
when $pos == 0.)
Here is the corrected proc, fixing the bug. Please replace the proc
with this one. The difference is that I have moved the line
if {!$pos || ($pos == [maxPos])} return;
to 13 lines below the original (after the large "if" clause)
(and removed the unnecessary ";" character after the "return")
proc transposeChars {} {
set pos [getPos]
if {[string length [set text [getSelect]]]} {
if {[string length $text] == 1} {
return
} else {
set sel [expr [selEnd] - 1]
set one [lookAt $sel]
set two [lookAt $pos]
replaceText $pos [expr $sel + 1] \
"$one[getText [expr $pos+1] $sel]$two"
select $pos [expr $sel+1]
return
}
}
if {!$pos || ($pos == [maxPos])} return
set one [lookAt $pos]
set two [lookAt [expr $pos-1]]
replaceText [expr $pos-1] [expr $pos + 1] "$one$two"
goto $pos
}
Sorry for the bug,
Mark
--
Mark Nagata
mailto:nagata@kurims.kyoto-u.ac.jp
_______________________________________________
AlphaTcl-developers mailing list
AlphaTcl-developers@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/alphatcl-developers