From 30e08f59159f13bed64166e78c7be2ea63f9a233 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 2 Aug 2009 16:41:14 +0200 Subject: minor unit path fix in extrafpc.cfg file Signed-off-by: Graeme Geldenhuys --- prototypes/textedit/extrafpc.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prototypes') diff --git a/prototypes/textedit/extrafpc.cfg b/prototypes/textedit/extrafpc.cfg index 775d592f..2799d91e 100644 --- a/prototypes/textedit/extrafpc.cfg +++ b/prototypes/textedit/extrafpc.cfg @@ -1,5 +1,5 @@ -FUunits --Fu../../../lib/$fpctarget +-Fu../../lib/$fpctarget -Xs -XX -CX -- cgit v1.2.3-70-g09d2 From 985974a2161b6a0ee07a88191c2bb05e43691848 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 2 Aug 2009 16:41:56 +0200 Subject: minor code comments for textedit component. Signed-off-by: Graeme Geldenhuys --- prototypes/textedit/fpg_textedit.pas | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'prototypes') diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index 78b91083..6e2c8094 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -76,7 +76,10 @@ type FVisLines: Integer; FVisCols: Integer; StartNo, EndNo, StartOffs, EndOffs: Integer; - FSelStartNo, FSelEndNo, FSelStartOffs, FSelEndOffs: Integer; + // Selection start and end line number + FSelStartNo, FSelEndNo: Integer; + // Selection start and end column + FSelStartOffs, FSelEndOffs: Integer; FTabWidth: Integer; HPos, VPos, XSize, YSize: Integer; FMaxScrollH: Integer; -- cgit v1.2.3-70-g09d2 From e8934beb4bf217324b2397fb062f2bb6e53ce0f2 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 2 Aug 2009 16:45:09 +0200 Subject: Right key navigation support added to TfpgTextEdit. Left and Right navigation works in TextEdit component. Ctrl+[Left|Right] navigation for word jumping also works. Signed-off-by: Graeme Geldenhuys --- prototypes/textedit/fpg_textedit.pas | 128 +++++++++++++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 4 deletions(-) (limited to 'prototypes') diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index 6e2c8094..5c51d630 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -172,6 +172,41 @@ implementation uses fpg_dialogs{, fpg_constants}, fpg_stringutils, fpg_utils; + +function GetNextWord(SLine: TfpgString; var PosX: Integer): Boolean; +const + ValidChars = ['a'..'z', 'A'..'Z', '0'..'9', '#']; +var + I, RetX: Integer; + FindNext: Boolean; + c: TfpgChar; +begin + Result := False; + if PosX > UTF8Length(SLine) then Exit; + FindNext := False; + RetX := 0; + for I := PosX to UTF8Length(SLine) do + begin + c := fpgCharAt(SLine, I); + { TODO -cUnicode Error : We need to fix c[i] usage. Also improve ValidChars definition. } + if not FindNext and not (c[1] in ValidChars) then + begin + FindNext := True; + Continue; + end; + if FindNext and (c[1] in ValidChars) then + begin + RetX := I; + Result := True; + Break; + end; + end; + if RetX < 1 then + Result := False; + PosX := RetX; +end; + + { TfpgGutter } procedure TfpgGutter.SetDigits(const AValue: Integer); @@ -580,8 +615,42 @@ procedure TfpgBaseTextEdit.KeyboardCaretNav(const ShiftState: TShiftState; const end; end; + procedure CtrlKeyRightKey; + var + S: TfpgString; + I: Integer; + NotFindIt: Boolean; + begin + if CaretPos.Y <= pred(FLines.Count) then + begin + NotFindIt := True; + while NotFindIt do + begin + S := FLines[CaretPos.Y]; + I := CaretPos.X; + if GetNextWord(S, I) then + begin + CaretPos.X := I - 1; + NotFindIt := False; + end + else + begin + CaretPos.Y := CaretPos.Y + 1; + CaretPos.X := 1; + end; + if CaretPos.Y > pred(FLines.Count) then + begin + NotFindIt := False; + CaretPos.X := 0; + end; + end; + end + else + CaretPos.X := 0; + end; + begin - writeln('>> KeyboardCaretNav'); + writeln('DEBUG: TfpgBaseTextEdit.KeyboardCaretNav >>'); case AKeyCode of keyLeft: begin @@ -649,7 +718,8 @@ begin CtrlKeyLeftKey else FSelEndOffs := CaretPos.X; - end else + end + else begin FSelEndNo := CaretPos.Y; if ssCtrl in ShiftState then @@ -663,7 +733,8 @@ begin FSelEndOffs := Length(FLines[FSelEndNo]) - 1; CaretPos.X := FSelEndOffs; end; - end else + end + else begin FSelEndOffs := 0; CaretPos.X := 0; @@ -691,6 +762,55 @@ begin keyRight: begin + writeln('DEBUG: TfpgBaseTextEdit.KeyboardCaretNav >>> keyRight'); + CaretPos.X := CaretPos.X + 1; + if CaretPos.X > FMaxScrollH then + begin + FMaxScrollH := FMaxScrollH + 2; + UpdateScrollBars; + end; +// if CaretPos.x <= pred(FLines.Count) then +// begin +// GliphY := (CaretPos.x - FTopLine) * FChrH; +// DrawLine(Canvas, CaretPos.x, GliphY); +// end; + if ssShift in ShiftState then + begin + if not FSelected then + begin + FSelected := True; + FSelStartNo := CaretPos.Y; + FSelStartOffs := CaretPos.X - 1; + if ssCtrl in ShiftState then + CtrlKeyRightKey; + FSelEndNo := CaretPos.Y; + FSelEndOffs := CaretPos.X; + end + else + begin + if ssCtrl in ShiftState then + CtrlKeyRightKey; + FSelEndNo := CaretPos.Y; + FSelEndOffs := CaretPos.X; + end; + FSelected := (FSelStartNo <> FSelEndNo) or (FSelStartOffs <> FSelEndOffs); +// DrawVisible; + Exit; + end; + if FSelected then + begin + FSelected := False; +// DrawVisible; +// DrawCaret(CaretPos.Y, CaretPos.X, True); + end; + if ssCtrl in ShiftState then + begin + CtrlKeyRightKey; +// DrawVisible; + end; +// DrawCaret(CaretPos.Y, CaretPos.X, True); + FSelStartNo := CaretPos.Y; + FSelStartOffs := CaretPos.X; end; keyUp: @@ -713,7 +833,7 @@ begin begin end; end; - writeln('<< KeyboardCaretNav'); + writeln('DEBUG: TfpgBaseTextEdit.KeyboardCaretNav <<'); end; procedure TfpgBaseTextEdit.InitMemoObjects; -- cgit v1.2.3-70-g09d2 From 6eb02628545797e6249038b895f55fe4322bddda Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 2 Aug 2009 16:55:20 +0200 Subject: Fix compiler settings so project compiles from Lazarus IDE. Signed-off-by: Graeme Geldenhuys --- prototypes/textedit/demo_textedit.lpi | 7 ------- 1 file changed, 7 deletions(-) (limited to 'prototypes') diff --git a/prototypes/textedit/demo_textedit.lpi b/prototypes/textedit/demo_textedit.lpi index 6b541e19..11639711 100644 --- a/prototypes/textedit/demo_textedit.lpi +++ b/prototypes/textedit/demo_textedit.lpi @@ -67,13 +67,6 @@ - - - - - - - -- cgit v1.2.3-70-g09d2 From 5270e94548b95aab52f6d4d7466f83760706afb8 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 2 Aug 2009 17:04:25 +0200 Subject: Code cleanup in KeyboardCaretNav method. Removed all unused code from method. Signed-off-by: Graeme Geldenhuys --- prototypes/textedit/fpg_textedit.pas | 37 ------------------------------------ 1 file changed, 37 deletions(-) (limited to 'prototypes') diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index 5c51d630..9fe33bcb 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -661,10 +661,6 @@ begin begin if CaretPos.Y <= pred(FLines.Count) then begin - writeln('********'); - //GliphY := (CaretPos.Y - FTopLine) * FChrH; - //DrawLine(Canvas, CaretPos.Y, GliphY); - //DrawCaret(CaretPos.X, CaretPos.Y + 1, False); if (ssCtrl in ShiftState) and (CaretPos.Y > 0) then begin CaretPos.Y := CaretPos.Y - 1; @@ -673,36 +669,18 @@ begin begin FSelEndNo := CaretPos.Y; FSelEndOffs := CaretPos.X; -// DrawVisible; end; Exit; end; end; CaretPos.Y := CaretPos.Y - 1; CaretPos.X := Length(FLines[CaretPos.Y]); - //if not FSelected then - //begin - //GliphY := (CaretPos.Y - FTopLine) * FChrH; - //DrawLine(Canvas, CaretPos.X, GliphY); - //end else - //DrawVisible; end else begin CaretPos.X := 0; - //GliphY := (CaretPos.Y - FTopLine) * FChrH; - //if not FSelected then - //DrawLine(Canvas, CaretPos.Y, GliphY) - //else - //DrawVisible; end; end; - //else - //begin - //GliphY := (CaretPos.Y - FTopLine) * FChrH; - //DrawLine(Canvas, CaretPos.Y, GliphY); - //DrawCaret(CaretPos.X, CaretPos.Y, True); - //end; if ssShift in ShiftState then begin if not FSelected then @@ -741,20 +719,15 @@ begin end; end; FSelected := (FSelStartNo <> FSelEndNo) or (FSelStartOffs <> FSelEndOffs); - //DrawVisible; Exit; end; if FSelected then begin FSelected := False; - //DrawVisible; - //DrawCaret(CaretPos.X, CaretPos.Y, True); end; if ssCtrl in ShiftState then begin CtrlKeyLeftKey; - //DrawVisible; - //DrawCaret(CaretPos.X, CaretPos.Y, True); end; FSelStartNo := CaretPos.Y; FSelStartOffs := CaretPos.X; @@ -769,11 +742,6 @@ begin FMaxScrollH := FMaxScrollH + 2; UpdateScrollBars; end; -// if CaretPos.x <= pred(FLines.Count) then -// begin -// GliphY := (CaretPos.x - FTopLine) * FChrH; -// DrawLine(Canvas, CaretPos.x, GliphY); -// end; if ssShift in ShiftState then begin if not FSelected then @@ -794,21 +762,16 @@ begin FSelEndOffs := CaretPos.X; end; FSelected := (FSelStartNo <> FSelEndNo) or (FSelStartOffs <> FSelEndOffs); -// DrawVisible; Exit; end; if FSelected then begin FSelected := False; -// DrawVisible; -// DrawCaret(CaretPos.Y, CaretPos.X, True); end; if ssCtrl in ShiftState then begin CtrlKeyRightKey; -// DrawVisible; end; -// DrawCaret(CaretPos.Y, CaretPos.X, True); FSelStartNo := CaretPos.Y; FSelStartOffs := CaretPos.X; end; -- cgit v1.2.3-70-g09d2 From f0b97fa0cd4b5a2a9112000e56339bfe1327518e Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 2 Aug 2009 23:32:08 +0200 Subject: Fix Ctrl+RightArrow skipping a line When you Ctrl+RightArrow to jump words, when it reached the end of a line, it skipped a line and actually jumped two lines down. Also when the caret landed in the new line it was at position 1 of the line and not at the true beginning of the line position 0. Signed-off-by: Graeme Geldenhuys --- prototypes/textedit/fpg_textedit.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'prototypes') diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index 9fe33bcb..fcc14626 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -636,7 +636,8 @@ procedure TfpgBaseTextEdit.KeyboardCaretNav(const ShiftState: TShiftState; const else begin CaretPos.Y := CaretPos.Y + 1; - CaretPos.X := 1; + CaretPos.X := 0; + NotFindIt := False; end; if CaretPos.Y > pred(FLines.Count) then begin -- cgit v1.2.3-70-g09d2 From 424a32b9f5087ec42dc778797d71782e4f5ca5b4 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 2 Aug 2009 23:32:49 +0200 Subject: Implements Up Arrow key navigation in TextEdit component. Signed-off-by: Graeme Geldenhuys --- prototypes/textedit/fpg_textedit.pas | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'prototypes') diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index fcc14626..d076f056 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -779,6 +779,42 @@ begin keyUp: begin + if CaretPos.x = 0 then Exit; + if not (ssShift in ShiftState) and not (ssCtrl in ShiftState) then + begin + CaretPos.Y := CaretPos.Y - 1; + if FSelected then + begin + FSelected := False; + Exit; + end; + FSelStartNo := CaretPos.Y; + Exit; + end; + if (ssCtrl in ShiftState) and not (ssShift in ShiftState) then + begin + CaretPos.Y := CaretPos.Y - 1; + UpdateScrollBars; + FSelStartNo := CaretPos.Y; + Exit; + end; + if not (ssCtrl in ShiftState) and (ssShift in ShiftState) then + begin + CaretPos.Y := CaretPos.Y - 1; + if not FSelected then + begin + FSelStartNo := CaretPos.Y + 1; + FSelStartOffs := CaretPos.X; + FSelEndNo := CaretPos.X; + FSelEndOffs := CaretPos.X; + FSelected := True; + end else + begin + FSelEndNo := CaretPos.Y; + FSelEndOffs := CaretPos.X; + FSelected := (FSelStartNo <> FSelEndNo) or (FSelStartOffs <> FSelEndOffs); + end; + end; end; keyDown: -- cgit v1.2.3-70-g09d2