|
From: Jeff R. <jef...@ea...> - 2001-03-23 22:17:24
|
In the spirit of changing those little things that frustrate me I made a
fairly drastic change to SynEdit today and am wondering what people think.
I am pretty sure there are some problems with it (though it works great for
me).
Problem:
======
When selecting text in columnar selection mode-- if eoTrimTrailingSpaces is
on the trailing spaces-- even in the block-- should be trimmed from the end
of the lines. e.g:
a
aa
aaa
aaaa
Selecting the above in a 4x4 block would produce
"a "
"aa "
"aaa "
"aaaa"
I have always thought (because the original text include line ends) it
should produce:
"a"
"aa"
"aaa"
"aaaa"
whereas selecting a 4x4 block in the following example should include the
white spaces because you are not selecting line ends and therefore should
not trim:
a b
aa b
aaa b
aaaab
Make sense? Well if you agree with the problem, let's keep going (this is
long)...
Solution:
======
GetSelText needs to be modified:
the procedure CopyPaddedAndForward should be changed to a function which
returns the trimmed amount
//!! Changed to function
function CopyPaddedAndForward(const S: string; Index, Count: Integer;
var P: PChar) : Integer;
var
OldP: PChar;
Len: Integer;
begin
Result:= 0;
OldP := P;
CopyAndForward(S, Index, Count, P);
Len := Count - (P - OldP);
//!! Added check and result
if not (eoTrimTrailingSpaces in Options)
then begin
FillChar(P^, Len, #$20);
Inc(P, Len);
end else
Result:= Len;
end;
Now the use of this function needs to be changed below. In the smColumn
case I changed only the NON MBCS code (I wasn't as sure about the MBCS)--
that block should look like:
{$IFNDEF SYN_MBCSSUPPORT}
ColLen := ColTo - ColFrom;
TotalLen := ColLen + (ColLen + Length(sLineBreak)) * (Last -
First);
// step2: build up result string
SetLength(Result, TotalLen);
P := PChar(Result);
for i := First to Last - 1 do begin
//!! modified
TotalLen:= TotalLen - CopyPaddedAndForward(Lines[i], ColFrom,
ColLen, P);
CopyAndForward(sLineBreak, 1, MaxInt, P);
end;
//!! modified
TotalLen:= TotalLen-CopyPaddedAndForward(Lines[Last], ColFrom,
ColLen, P);
//!! Reset the length (might have shortened)
SetLength(Result, TotalLen);
{$ELSE}
The string is initially set to the full length but then the TotalLen field
is decremented as spaces are trimmed. Then the string length is set again
with the new total. This should complete the fix for the copying. Pasting
the copied contents works as expected-- however undo-ing that paste does not
work so I added some more changes (this is where things get ugly...). In
order to change this I had to move the Undo list addition out of
PasteFromClipboard (yikes!) and into the function InsertColumn in
SetSelTextPrimitive.
in PasteFromClipboard:
if PasteMode <> smLine then
fUndoList.AddChange(crPaste, StartOfBlock, EndOfBlock, SelText,
PasteMode)
else begin
if CaretX = 1 then
fUndoList.AddChange(crPaste, Point(1, StartOfBlock.y),
Point(CharsInWindow, EndOfBlock.y - 1), SelText, smLine)
else
fUndoList.AddChange(crPaste, Point(1, StartOfBlock.y),
EndOfBlock, SelText, smNormal);
end;
changes to:
if PasteMode = smColumn then
//!!Do nothing now handled in InsertColumn
else if PasteMode = smLine then
begin
if CaretX = 1 then
fUndoList.AddChange(crPaste, Point(1, StartOfBlock.y),
Point(CharsInWindow, EndOfBlock.y - 1), SelText, smLine)
else
fUndoList.AddChange(crPaste, Point(1, StartOfBlock.y),
EndOfBlock, SelText, smNormal);
end else
fUndoList.AddChange(crPaste, StartOfBlock, EndOfBlock, SelText,
PasteMode);
Now in InsertColumn (in SetSelTextPrimitive) we add:
//!! Add undo change here!
fUndoList.AddChange(crPaste, Point(InsertPos, CaretY),
Point(InsertPos+(P-Start), CaretY), '', smNormal);
This goes just before the "end" which matches "if P <> Start then begin".
Now some of the problems with this are 1) uses smNormal instead of PasteMode
2) Happens for other insert operations (is that bad?) 3) replace text is
''-- but this is okay because the deletion is handled earlier in
pastefromclipboard 4) again MBCS may (probably) not work right.
Whew! That's it... It is working great for me-- I am just wondering how
other people are feeling about it.
Thanks,
Jeff Rafter
Defined Systems
http://www.defined.net
|