[修正] 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;
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步