From ee6e282f2b5443a86fd1d7671ad9d1a64a70a9be Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sun, 27 Nov 2016 08:52:35 +0100 Subject: [PATCH] refact full text replacement --- src/ce_dfmt.pas | 5 +---- src/ce_synmemo.pas | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/ce_dfmt.pas b/src/ce_dfmt.pas index 481d9e9f..3536126d 100644 --- a/src/ce_dfmt.pas +++ b/src/ce_dfmt.pas @@ -305,10 +305,7 @@ begin try str := TStringList.Create; processOutputToStrings(prc,str); - fDoc.ClearAll; - fDoc.InsertTextAtCaret(str.Text); - fDoc.SelStart:= high(integer); - fDoc.ExecuteCommand(ecDeleteLastChar, #0, nil); + fDoc.replaceUndoableContent(str.strictText); except fDoc.Lines.Assign(fBackup); end; diff --git a/src/ce_synmemo.pas b/src/ce_synmemo.pas index 776b1fd4..95f0c11e 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -268,6 +268,7 @@ type procedure nextProtectionGroup; procedure sortLines; function implementMain: THasMain; + procedure replaceUndoableContent(const value: string); // property IdentifierMatchOptions: TIdentifierMatchOptions read fMatchOpts write setMatchOpts; property Identifier: string read fIdentifier; @@ -2288,10 +2289,28 @@ begin end; end; +procedure TCESynMemo.replaceUndoableContent(const value: string); +var + b: TPoint; + e: TPoint; + p: TPoint; +begin + p := CaretXY; + b := point(1,1); + e := Point(length(Lines[lines.Count-1])+1,lines.Count); + TextBetweenPoints[b,e] := value; + CaretXY := p; + EnsureCursorPosVisible; + fModified := true; +end; + procedure TCESynMemo.checkFileDate; var newDate: double; str: TStringList; + txt: string; + b,e: TPoint; + p: TPoint; begin if fFilename = fTempFileName then exit; if fDisableFileDateCheck then exit; @@ -2307,11 +2326,7 @@ begin str := TStringList.Create; try str.LoadFromFile(fFilename); - ClearAll; - InsertTextAtCaret(str.Text); - SelStart:= high(integer); - ExecuteCommand(ecDeleteLastChar, #0, nil); - fModified := true; + replaceUndoableContent(str.strictText); finally str.Free; end; @@ -2361,9 +2376,7 @@ begin //lst[i] := lne; end} end; - lne := lst.Text; - setLength(lne, lne.length - lst.LineBreak.length); - clipboard.asText := lne; + clipboard.asText := lst.strictText; finally lst.free; end;