From a85bda5f5d2962cefe5752bfa588e7e1de4ffe9e Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 25 Sep 2016 21:50:51 +0000 Subject: [PATCH] fpspreadsheet: Restore old cell content if ESC is pressed in the TsCellEdit. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5213 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/fpspreadsheetctrls.pas | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/fpspreadsheet/fpspreadsheetctrls.pas b/components/fpspreadsheet/fpspreadsheetctrls.pas index d46ffff5d..2108ed4cc 100644 --- a/components/fpspreadsheet/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/fpspreadsheetctrls.pas @@ -233,11 +233,13 @@ type private FWorkbookSource: TsWorkbookSource; FShowHTMLText: Boolean; + FOldText: String; function GetSelectedCell: PCell; function GetWorkbook: TsWorkbook; function GetWorksheet: TsWorksheet; procedure SetWorkbookSource(AValue: TsWorkbookSource); protected + procedure KeyDown(var Key : Word; Shift : TShiftState); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure ShowCell(ACell: PCell); virtual; public @@ -1854,6 +1856,23 @@ begin Result := nil; end; +{@@ ---------------------------------------------------------------------------- + Inherited KeyDown method. Overridden here in order to be able to restore the + old cell content if ESC is pressed. +-------------------------------------------------------------------------------} +procedure TsCellEdit.KeyDown(var Key: Word; Shift : TShiftState); +var + selpos: Integer; +begin + if Key = VK_ESCAPE then begin + selpos := SelStart; + Lines.Text := FOldText; + SelStart := selpos; + exit; + end; + inherited; +end; + {@@ ---------------------------------------------------------------------------- Notification message received from the WorkbookSource telling which item of the spreadsheet has changed. @@ -1962,6 +1981,7 @@ begin end; end else Clear; + FOldText := Lines.Text; end;