[修正] Firemonkey Windows & macOS 平台下 Edit & Memo 中文输入后会取消原选取文字的 BUG

问题:Firemonkey Windows & macOS 平台下 Edit & Memo 中文输入后会取消原选取文字的 BUG

适用版本:Delphi 10.1.2 & 10.2.1

修正后效果:

 

修正代码:

请将 FMX.Edit.Style.pas 复制到自己的工程目录下,再修改如下代码: (10.2.2 已修正此问题)

procedure TStyledEdit.IMEStateUpdated;
var
  CombinedText: string;
begin
  CombinedText := FTextService.CombinedText;
  FTextLayout.Text := CombinedText;
  SetCaretPosition(GetOriginCaretPosition);
  Model.SetTextWithoutValidation(CombinedText);
  if FPrompt <> nil then
    FPrompt.Visible := CombinedText.IsEmpty;
{+++>}{$IF Defined(IOS) or Defined(ANDROID)} // 加入此行, 修正中文输入后会取消原选取文字的 BUG by Aone (2017.11.17)
  if Model.SelLength > 0 then
  begin
    Model.DisableNotify;
    try
      Model.SelLength := 0;
    finally
      Model.EnableNotify;
    end;
    UpdateSelectionPointPositions;
  end;
{+++>}{$ENDIF} // 加入此行, 修正中文输入后会取消原选取文字的 BUG by Aone (2017.11.17)
  LinkObserversValueModified(Self.Observers);
  DoChangeTracking;
  DoTyping;
end;

请将 FMX.Memo.Style.pas 复制到自己的工程目录下,再修改如下代码:(10.2.2 未已修正此问题)

procedure TStyledMemo.IMEStateUpdated;

...略...

    SelectionChanged := FSelected or (FSelStart <> LCaret) or (FSelEnd <> LCaret);
    CaretPosition := LCaret;
{+++>}{$IF Defined(IOS) or Defined(ANDROID)} // 加入此行, 修正中文输入后会取消原选取文字的 BUG by Aone (2017.11.17)
    FSelStart := LCaret;
    FSelected := False;
    FSelEnd := FSelStart;
    UpdateSelectionInModel;
{+++>}{$ENDIF} // 加入此行, 修正中文输入后会取消原选取文字的 BUG by Aone (2017.11.17)

    if SelectionChanged then
      UpdateSelectionPointPositions;
    if TextChanged then
      LinkObserversValueModified(Self.Observers);
  end;
end;
原文地址:https://www.cnblogs.com/onechen/p/7852813.html