Recent

Author Topic: Changing the whole of lines without lost undo history  (Read 3571 times)

Zaher

  • Hero Member
  • *****
  • Posts: 679
    • parmaja.org
Changing the whole of lines without lost undo history
« on: July 27, 2016, 04:22:37 pm »
I need to change and fix tabs/spaces of SynEdit text (When saving it) for Python language before running it.
But i lost the caret positions and Undo history, how can change the lines.text as part of editing?
Code: [Select]
    SynEdit.BeginUpdate(False);
    saveTopLine := SynEdit.TopLine;
    saveLeftChar := SynEdit.LeftChar;
    saveXY := SynEdit.CaretXY;
    SynEdit.Lines.Text := ConvertIndents(SynEdit.Lines.Text, SynEdit.TabWidth, Tendency.IndentMode); <-- here i lost undo history
    SynEdit.TopLine := saveTopLine;
    SynEdit.LeftChar := saveLeftChar;
    SynEdit.CaretXY := saveXY;
    SynEdit.EndUpdate;
orginal code

Thanks in advance.
« Last Edit: July 27, 2016, 04:33:10 pm by Zaher »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Changing the whole of lines without lost undo history
« Reply #1 on: July 27, 2016, 06:17:41 pm »
You can not. Not with SynEdit.Lines.

You can read from SynEdit.Lines. But for writing you will have to use TextBetweenPoints (there are several other with similar names)

Code: Pascal  [Select][+][-]
  1. SynEdit.TextBetweenPoints(Point(1,y), Point(length(SynEdit.Lines[y-1]),y)] := 'foobar';
  2.  
'
I think lines[] is zero based, but TextBetweenPoints is 1 based, pleas double check.

Of course that will add all your changes to the undo list (you can use BeginUndoBlock, EndUndoBlock, to make it just on undo.

The way undo info is stored, it requires that all undo info is present. If you make changes to the text, and that would not be part of the undo, then the position of all other undo blocks would be wrong. Thats why all actions must be part of the undo.

--------------
You can use TextBetweenPoints to replace the entire text, instead line by line.
But that will add a copy of the entire old text to the undo info.

Zaher

  • Hero Member
  • *****
  • Posts: 679
    • parmaja.org
Re: Changing the whole of lines without lost undo history
« Reply #2 on: July 27, 2016, 08:04:27 pm »
Ok, I will change the behavior, I will save it after fix tabs/spaces but without changing on synedit contents, And will take your advice if user want to fix it in the content manually, I will add it as tool.

Zaher

  • Hero Member
  • *****
  • Posts: 679
    • parmaja.org
Re: Changing the whole of lines without lost undo history
« Reply #3 on: July 27, 2016, 10:06:03 pm »
Yes TextBetweenPoints works fine too, Thank you.

 

TinyPortal © 2005-2018