問題:Firemonkey Windows & macOS 平臺下 Edit & Memo 中文輸入後會取消原選取文字的 BUG 適用版本:Delphi 10.1.2 & 10.2.1 修正後效果: 修正代碼: 請將 FMX.Edit.Style.pas 複製到自己的工程目錄下,再修改如下代碼: 請 ...
問題:Firemonkey Windows & macOS 平臺下 Edit & Memo 中文輸入後會取消原選取文字的 BUG
適用版本:Delphi 10.1.2 & 10.2.1
修正後效果:
修正代碼:
請將 FMX.Edit.Style.pas 複製到自己的工程目錄下,再修改如下代碼:
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 複製到自己的工程目錄下,再修改如下代碼:
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;