EControl Ltd. Forum Index EControl Ltd.
VCL libraries and software support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting the first and last modified character offset

 
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor
View previous topic :: View next topic  
Author Message
mstaszew



Joined: 21 Jul 2006
Posts: 67
Location: North Carolina, USA

PostPosted: Thu Apr 15, 2010 6:35 pm    Post subject: Getting the first and last modified character offset Reply with quote

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
Back to top
View user's profile Send private message
mstaszew



Joined: 21 Jul 2006
Posts: 67
Location: North Carolina, USA

PostPosted: Fri Apr 16, 2010 12:45 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group