mstaszew
Joined: 21 Jul 2006 Posts: 67 Location: North Carolina, USA
|
Posted: Thu Apr 15, 2010 6:35 pm Post subject: Getting the first and last modified character offset |
|
|
I'm trying to maintain the first and last character modified. So far I've been doing something similar to this...
In form constructor...
Code: |
StartOffset := MAXINT;
EndOffset := -1;
|
In Memo.OnTextChanged...
Code: |
if (Pos >= 0) and (Count <> 0) then
begin
{ First modified char offset }
StartOffset:= Min(Pos, StartOffset);
{ Last modified offset }
if Pos + Abs(Count) < EndOffset then
EndOffset:= EndOffset+ Count
else
begin
if Pos < EndOffsetthen
begin
if Count > 0 then
EndOffset:= EndOffset+ Count
else
EndOffset:= EndOffset+ (EndOffset- (Pos + Abs(Count)));
end
else if Count > 0 then
EndOffset:= Pos + Count
else
EndOffset:= Pos;
end;
end;
|
My logic in the OnTextChanged may need some tweaking, but I've abandoned it for now given a road block that I've hit. Pasting text and undoing text modifications (and possibly other operations) cause OnTextChanged to fire multiple times. For instance, if I undo a paste then I get an OnTextChanged event first for the text removal, then for the same text's addition, and again for its removal. A paste is also generating multiple events. One for the paste and another for the text replacement (if tabs are to be converted to spaces).
Do you have any suggestions on how to achieve my goal or is there a way to cause the OnTextChanged event to fire once for the net change?
Thanks,
Michael |
|
mstaszew
Joined: 21 Jul 2006 Posts: 67 Location: North Carolina, USA
|
Posted: Fri Apr 16, 2010 12:45 pm Post subject: |
|
|
Disregard the previous message. I noticed that your bookmarks are handling the text changes correctly and copied that logic with a few minor tweaks for my needs and all seems fine now.
Thanks,
Michael |
|