Skip to content

Commit

Permalink
fix(developer): use richedit in debug memo to support Egyptian cartou…
Browse files Browse the repository at this point in the history
…ches

RichEdit allows text selection one character past end-of-string, so we
need to cater for that as well in passing text ranges to the character
grid.

Fixes: #12454
  • Loading branch information
mcdurdin committed Sep 24, 2024
1 parent ba5d448 commit 25ea6a7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(*
Name: KeymanDeveloperDebuggerMemo
Copyright: Copyright (C) 2003-2017 SIL International.
Documentation:
Description:
Documentation:
Description:
Create Date: 8 Jun 2012
Modified Date: 8 Jun 2012
Authors: mcdurdin
Related Files:
Dependencies:
Related Files:
Dependencies:
Bugs:
Todo:
Notes:
Bugs:
Todo:
Notes:
History: 08 Jun 2012 - mcdurdin - I3323 - V9.0 - Extract debug-related code TPlus-Memo into subclass
*)
unit KeymanDeveloperDebuggerMemo; // I3323
Expand All @@ -24,6 +24,7 @@ interface
Winapi.Messages,
Winapi.Windows,
Vcl.Controls,
Vcl.ComCtrls,
Vcl.StdCtrls;

type
Expand All @@ -34,7 +35,7 @@ TMemoSelection = record
Anchor: Integer;
end;

TKeymanDeveloperDebuggerMemo = class(TMemo)
TKeymanDeveloperDebuggerMemo = class(TRichEdit)
private
FOnMessage: TKeymanDeveloperDebuggerMessageEvent;
FAllowUnicodeInput: Boolean;
Expand Down Expand Up @@ -77,6 +78,7 @@ constructor TKeymanDeveloperDebuggerMemo.Create(AOwner: TComponent);
begin
FAllowUnicodeInput := True;
inherited Create(AOwner);
PlainText := True;
end;

procedure TKeymanDeveloperDebuggerMemo.CreateHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,22 @@ procedure TfrmLdmlKeyboardDebug.memoSelMove(Sender: TObject);
end;

procedure TfrmLdmlKeyboardDebug.UpdateCharacterGrid; // I4808
var
start, len: Integer;
begin
if csDestroying in ComponentState then
Exit;

TCharacterGridRenderer.Fill(sgChars, memo.Text, FDeadkeys, memo.SelStart,
memo.SelLength, memo.Selection.Anchor, True);
start := memo.SelStart;
len := memo.SelLength;
if start + len > Length(memo.Text) then
begin
// RichEdit has a virtual final character, which is selected when
// pressing Ctrl+A, etc.
len := Length(memo.Text) - start;
end;
TCharacterGridRenderer.Fill(sgChars, memo.Text, FDeadkeys, start, len
memo.Selection.Anchor, True);
TCharacterGridRenderer.Size(sgChars, memo.Font);
end;

Expand Down
13 changes: 12 additions & 1 deletion developer/src/tike/child/UfrmDebug.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,22 @@ procedure TfrmDebug.memoSelMove(Sender: TObject);
end;

procedure TfrmDebug.UpdateCharacterGrid; // I4808
var
start, len: Integer;
begin
if csDestroying in ComponentState then
Exit;

TCharacterGridRenderer.Fill(sgChars, memo.Text, FDeadkeys, memo.SelStart, memo.SelLength, memo.Selection.Anchor);
start := memo.SelStart;
len := memo.SelLength;
if start + len > Length(memo.Text) then
begin
// RichEdit has a virtual final character, which is selected when
// pressing Ctrl+A, etc.
len := Length(memo.Text) - start;
end;

TCharacterGridRenderer.Fill(sgChars, memo.Text, FDeadkeys, start, len, memo.Selection.Anchor);
TCharacterGridRenderer.Size(sgChars, memo.Font);
end;

Expand Down

0 comments on commit 25ea6a7

Please sign in to comment.