虽然之前修复了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运行,很不错的编辑器)就可以完美兼容系统自带的输入法和搜狗输入法。
步骤如下:
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;
标签:
lazarus/fpc中文支持
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
2020-01-30 QF中间件