From 1c254deea5bdbca3737c0f826542bdf7c8f07752 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Thu, 10 Jun 2010 23:55:50 +0200 Subject: TextEdit: Implemented Home and End keyboard navigation. --- prototypes/textedit/demo_textedit.lpr | 2 +- prototypes/textedit/fpg_textedit.pas | 93 +++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/prototypes/textedit/demo_textedit.lpr b/prototypes/textedit/demo_textedit.lpr index da961ce5..06e19d63 100644 --- a/prototypes/textedit/demo_textedit.lpr +++ b/prototypes/textedit/demo_textedit.lpr @@ -289,7 +289,7 @@ begin FontDesc := 'Bitstream Vera Sans Mono-10'; // Lines.Insert(1,'0 Beforje 1 after'); ParentShowHint := True; - OnDrawLine := @TextEditDrawLine; +// OnDrawLine := @TextEditDrawLine; end; btnLoad := TfpgButton.Create(self); diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index bb313717..8346ce3d 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -887,10 +887,103 @@ begin keyHome: begin + if not (ssCtrl in ShiftState) and not (ssShift in ShiftState) then + begin + CaretPos.X := 0; + if FSelected then + begin + FSelected := False; + Exit; + end; + end; + if ssCtrl in ShiftState then + begin + if ssShift in ShiftState then + begin + if not FSelected then + begin + FSelStartNo := CaretPos.Y; + FSelStartOffs := CaretPos.X; + FSelected := True; + end; + CaretPos.Y := 0; + CaretPos.X := 0; + FSelEndNo := 0; + FSelEndOffs := 0; + end + else + begin + CaretPos.Y := 0; + CaretPos.X := 0; + end; + Exit; + end; + if ssShift in ShiftState then + begin + if not FSelected then + begin + FSelStartNo := CaretPos.Y; + FSelStartOffs := CaretPos.X; + FSelected := True; + end; + CaretPos.X := 0; + FSelEndNo := CaretPos.Y; + FSelEndOffs := 0; + if FSelEndNo = FSelStartNo then + FSelected := (FSelStartOffs <> FSelEndOffs); + end; end; keyEnd: begin + if not (ssCtrl in ShiftState) and not (ssShift in ShiftState) then + begin + if CaretPos.Y <= pred(FLines.Count) then + CaretPos.X := Length(FLines[CaretPos.Y]) + else + CaretPos.X := 0; + end; + if ssCtrl in ShiftState then + begin + if ssShift in ShiftState then + begin + if not FSelected then + begin + FSelStartNo := CaretPos.Y; + FSelStartOffs := CaretPos.X; + FSelected := True; + end; + CaretPos.Y := pred(FLines.Count); + CaretPos.X := Length(FLines[CaretPos.Y]); + FSelEndNo := pred(FLines.Count); + FSelEndOffs := Length(FLines[CaretPos.Y]); + end else + begin + CaretPos.Y := pred(FLines.Count); + CaretPos.X := Length(FLines[CaretPos.Y]); + end; + Exit; + end; + if ssShift in ShiftState then + begin + if not FSelected then + begin + FSelStartNo := CaretPos.Y; + if CaretPos.Y <= pred(FLines.Count) then + if CaretPos.X > Length(FLines[CaretPos.Y]) then + CaretPos.X := Length(FLines[CaretPos.Y]); + FSelStartOffs := CaretPos.X; + FSelected := True; + end; + if CaretPos.Y <= pred(FLines.Count) then + CaretPos.X := Length(FLines[CaretPos.Y]) + else + CaretPos.X := 0; + FSelEndNo := CaretPos.Y; + FSelEndOffs := CaretPos.X; + if FSelEndNo = FSelStartNo then + FSelected := (FSelStartOffs <> FSelEndOffs); + end; end; keyPrior, keyNext: -- cgit v1.2.3-70-g09d2