秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  278 随笔 :: 0 文章 :: 308 评论 :: 20万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
虽然之前修复了lazarus的代码编辑、synedit控件和cudatex在linux下不能输入中文的bug,但存在使用搜狗输入法输入词组时只能输入第一个字的问题,原以为是synEdit控件引起的,对lazarus进行debug,终于找到问题所在的位置,最后发现在gtk2widgetset的gtk_commit_cb处理时添加1行代码就能解决这个Bug。
步骤如下:
1、打开/lazarus/lcl/interfaces/gtk2/gtk2widgetset.inc
2、找到第236行procedure gtk_commit_cb ({%H-}context: PGtkIMContext; const Str: Pgchar;
添加1行红字代码,
3、重新编译lazarus
编译后lazarus、SynEdit控件及cudatex(也要重新编译cudatex,可以在windows、linux和macos运行,很不错的编辑器)就可以完美兼容系统自带的输入法和搜狗输入法。
复制代码

procedure
gtk_commit_cb ({%H-}context: PGtkIMContext; const Str: Pgchar; {%H-}Data: Pointer); cdecl; {$IFDEF WITH_GTK2_IM} var control:TWinControl; i:Integer; {$ENDIF} begin {$IFDEF WITH_GTK2_IM} //DebugLn(['gtk_commit_cb ',dbgstr(Str),'="',Str,'"']); { fix double normal character input } if not im_context_use then im_context_string:=Str // key at non-composition else im_context_string_commit:=Str; // key at composition { commit composition string, not key } if (im_context_widget<>nil) then begin im_context_skipdelete:=True; Control:=TWinControl(GetNearestLCLObject(im_context_widget)); SendMessage(control.Handle,LM_IM_COMPOSITION,GTK_IM_FLAG_COMMIT,LPARAM(pchar(im_context_string_commit))); im_context_string_commit:=''; end; {$ELSE} im_context_string:=Str; {$ENDIF} end;
复制代码

原来的方法在(fpc trunk)时编译出错,现修改为(紫色字代码):

复制代码
procedure gtk_commit_cb ({%H-}context: PGtkIMContext; const Str: Pgchar;
  {%H-}Data: Pointer); cdecl;
{$IFDEF WITH_GTK2_IM}
var
  control:TWinControl;
  i:Integer;
{$ENDIF}
begin
  {$IFDEF WITH_GTK2_IM}
  //DebugLn(['gtk_commit_cb ',dbgstr(Str),'="',Str,'"']);
  { fix double normal character input }
  if (ord(ansichar(str[0]))>127) or (length(str)>1) then im_context_use:=true;
  if not im_context_use then
    im_context_string:=Str // key at non-composition
  else
    im_context_string_commit:=Str; // key at composition
//  { commit composition string, not key }
  if (im_context_widget<>nil) then
  begin
    im_context_skipdelete:=True;
    Control:=TWinControl(GetNearestLCLObject(im_context_widget));
    SendMessage(control.Handle,LM_IM_COMPOSITION,GTK_IM_FLAG_COMMIT,LPARAM(pchar(im_context_string_commit)));
    im_context_string_commit:='';
  end;
{$ELSE}
  im_context_string:=Str;
  {$ENDIF}
end;
复制代码
posted on   秋·风  阅读(577)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
历史上的今天:
2020-01-30 QF中间件
点击右上角即可分享
微信分享提示