From 4404a659e02b082bfa4ce77497957481c3e91de1 Mon Sep 17 00:00:00 2001 From: dmitry Date: Mon, 23 Dec 2019 20:07:57 +0000 Subject: [PATCH] =?UTF-8?q?cocoa:=20changing=20the=20way=20undo=20manager?= =?UTF-8?q?=20is=20allocated.=20Changing=20handling=20of=20the=20text=20as?= =?UTF-8?q?signment=20to=20a=20memo.=20Patch=20by=20Zo=C3=AB=20Peterson.?= =?UTF-8?q?=20bug=20#36073?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: trunk@62438 - --- lcl/interfaces/cocoa/cocoatextedits.pas | 21 ++++++++------------- lcl/interfaces/cocoa/cocoautils.pas | 1 + lcl/interfaces/cocoa/cocoawsstdctrls.pas | 17 +++++------------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoatextedits.pas b/lcl/interfaces/cocoa/cocoatextedits.pas index 5b1eb11edf..15516da1c9 100644 --- a/lcl/interfaces/cocoa/cocoatextedits.pas +++ b/lcl/interfaces/cocoa/cocoatextedits.pas @@ -124,7 +124,6 @@ type procedure dealloc; override; function acceptsFirstResponder: LCLObjCBoolean; override; - function undoManager: NSUndoManager; override; function lclGetCallback: ICommonCallback; override; procedure lclClearCallback; override; procedure resetCursorRects; override; @@ -153,6 +152,7 @@ type // delegate methods procedure textDidChange(notification: NSNotification); message 'textDidChange:'; procedure lclExpectedKeys(var wantTabs, wantArrows, wantReturn, wantAll: Boolean); override; + function undoManagerForTextView(view: NSTextView): NSUndoManager; message 'undoManagerForTextView:'; end; { TCococaFieldEditorExt } @@ -1037,18 +1037,6 @@ begin Result := NSViewCanFocus(Self); end; -function TCocoaTextView.undoManager: NSUndoManager; -begin - if allowsUndo then - begin - if not Assigned(FUndoManager) then - FUndoManager := NSUndoManager.alloc.init; - Result := FUndoManager; - end - else - Result := nil; -end; - function TCocoaTextView.lclGetCallback: ICommonCallback; begin Result := callback; @@ -1187,6 +1175,13 @@ begin wantAll := true; end; +function TCocoaTextView.undoManagerForTextView(view: NSTextView): NSUndoManager; +begin + if not Assigned(FUndoManager) then + FUndoManager := NSUndoManager.alloc.init; + Result := FUndoManager; +end; + { TCocoaSecureTextField } function TCocoaSecureTextField.acceptsFirstResponder: LCLObjCBoolean; diff --git a/lcl/interfaces/cocoa/cocoautils.pas b/lcl/interfaces/cocoa/cocoautils.pas index 1f2899ce30..81ece9ecdc 100644 --- a/lcl/interfaces/cocoa/cocoautils.pas +++ b/lcl/interfaces/cocoa/cocoautils.pas @@ -618,6 +618,7 @@ begin ns := NSStringUTF8(s); text.setString(ns); ns.release; + text.undoManager.removeAllActions; end; end; diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pas b/lcl/interfaces/cocoa/cocoawsstdctrls.pas index a7ef94bec3..b408055a99 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pas @@ -1173,12 +1173,8 @@ begin end; procedure TCocoaMemoStrings.SetTextStr(const Value: string); -var - ns: NSString; begin - ns := NSStringUtf8(LineBreaksToUnix(Value)); - FTextView.setString(ns); - ns.release; + SetNSText(FTextView, LineBreaksToUnix(Value)); FTextView.textDidChange(nil); end; @@ -1301,6 +1297,8 @@ begin FTextView.insertText( NSString.stringWithUTF8String( LFSTR )); if not ro then FTextView.setEditable(ro); + + FTextView.undoManager.removeAllActions; end; procedure TCocoaMemoStrings.LoadFromFile(const FileName: string); @@ -1471,9 +1469,7 @@ begin txt.callback := lcl; txt.setDelegate(txt); - ns := NSStringUtf8(AParams.Caption); - txt.setString(ns); - ns.release; + SetNSText(txt, AParams.Caption); scr.callback := txt.callback; @@ -1684,13 +1680,10 @@ end; class procedure TCocoaWSCustomMemo.SetText(const AWinControl:TWinControl;const AText:String); var txt: TCocoaTextView; - ns: NSString; begin txt := GetTextView(AWinControl); if not Assigned(txt) then Exit; - ns := NSStringUtf8(LineBreaksToUnix(AText)); - txt.setString(ns); - ns.release; + SetNSText(txt, LineBreaksToUnix(AText)); end; class function TCocoaWSCustomMemo.GetText(const AWinControl: TWinControl; var AText: String): Boolean;