Recent

Author Topic: SynEdit and Text Manipulation  (Read 7440 times)

ecalogiuri

  • Jr. Member
  • **
  • Posts: 74
SynEdit and Text Manipulation
« on: October 28, 2010, 06:59:47 am »
Hi boys,
in these days i working with SynEdit and I need to manipulate text insert from user at runtime, but i do not know how to solve some problems...

For examples, i have this piece of code:

Code: [Select]
Var CurrLine : String;
Begin
...
...

CurrLine := SynEdit1.LineText;

CurrLine := ProcessMyCurrentLine(CurrLine);  //This function transforms the current line...

SynEdit1.LineText := CurrLine;

End;

This work fine, on screen i see the current line correctly manipulate, but the SynEdit does not notice that the text is modified and the undo function not work...

I try to set SynEdit1.Modified := True; but does not work  :( :( :(

How can I set SynEdit to:
1) realizes that the text was modified (with yellow line on Gutter).
2) enable the undo function (if the user want to cancel the last operation).
3) enable redo...

Thanks for any suggestions,
Enzo.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12199
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit and Text Manipulation
« Reply #1 on: October 28, 2010, 12:26:04 pm »
Yes you can...

There are two function that will behave exactly like user-typed input:

 property TextBetweenPoints[aStartPoint, aEndPoint: TPoint]: String
 property TextBetweenPointsEx[aStartPoint, aEndPoint: TPoint; CaretMode: TSynCaretAdjustMode]: String

for example
  TextBetweenPoints[ Point(1,7), Point(5,7)] := '123';
replaces the first 4 chars on line 7 (1-based, so that's index 6 for Lines[6]).

  TextBetweenPoints[ Point(1,7), Point(1,7)] := '123';
Inserts the text at the start of line 7

It marks the text as modified, it's undo-able.
It keeps the caret at it's current position. That means the caret may end up at a different char in the text, if it was at line 7. Because the numerical value for the caret position did not change, but the text was moved.


  TextBetweenPointsEx[ Point(1,7), Point(5,8), scamAdjust] := '123';
replaces line 7, and the 1st 4 chars of line 8. So the text will have one line less.

If the caret was behind the edited text, it will move with the text


  TSynCaretAdjustMode = ( // used in TextBetweenPointsEx
    scamIgnore, // Caret stays at the same numeric values, if text is inserted before caret, the text moves, but the caret stays
    scamAdjust, // Caret moves with text, if text is inserted
    scamEnd,  // move caret to end of inserted text
    scamBegin // move caret to begin of inserted text
  );



ecalogiuri

  • Jr. Member
  • **
  • Posts: 74
Re: SynEdit and Text Manipulation
« Reply #2 on: October 29, 2010, 07:15:39 am »
Thanks Martin_fr  :D :D :D :D

Now all work fine!!!

Enzo.

 

TinyPortal © 2005-2018