Sublime Forum

Input method support

#7

Any response?
This problem is really concern most of the chinese, japanese, korean sublime text users.

0 Likes

#8

vietnam sublime text users too.
any news?

0 Likes

#9

just tried today, still not work (2.2216)

please check #2 hint for how to fix it. Most gtk im module implementation don’t send keyboard event if widget don’t have focus.

0 Likes

#10

Since user “csslayer” gives so many hints how to solve this problem, I’m wondering why this couldn’t be fixed yet.
It’s really an important issue for most CJK users.

0 Likes

#11

Still not solved.

build 2217 with fcitx…
it seems that it can not call the fcitx by the shortcut with Ctrl-Space. but change the fcitx’s shortcut from C-S to another. Problem remains…

0 Likes

#12

input methods(seems all 3rd party or system intergrated ) can’t follow cursor position in microsoft windows 7 and xp.
Jon, please consider fix this problem, every cjk user depend on input methods

0 Likes

#13

Still not works in CJK with ibus :frowning:
I hope this can be solved as soon as possible.

By the way, there is a package named “InputHelper” which can temporarily solve this issue. (Though it’s not quite convenient)

0 Likes

#14

I’m a sublime text2 user from China, it works fine in my windows, but in my fedora i can’t input any Chinese words :astonished: , it’s important for CJK user, please fix it.

0 Likes

#15

VIM is awesome! I’m not going to buy a Sublime until this bug has been fixed.

0 Likes

#16

This is a dirty fix but at least works. cursor position update also supported.

Use LD_PRELOAD to reimplement gtk_im_context_set_client_window and set im focus in.
use “gdk_region_get_clipbox” to catch the caret position. (It’s really difficult to find which function can catch the position…)

Here I made a assumption that the caret width is always 2, since it is 2.

the height is the “font glyph height”.

1, save below code to sublime_imfix.c

/*
sublime-imfix.c
Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
By Cjacker Huang <jianzhong.huang at i-soft.com.cn>

gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC
LD_PRELOAD=./libsublime-imfix.so sublime_text
*/
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
typedef GdkSegment GdkRegionBox;

struct _GdkRegion
{
  long size;
  long numRects;
  GdkRegionBox *rects;
  GdkRegionBox extents;
};

GtkIMContext *local_context;

void
gdk_region_get_clipbox (const GdkRegion *region,
            GdkRectangle    *rectangle)
{
  g_return_if_fail (region != NULL);
  g_return_if_fail (rectangle != NULL);

  rectangle->x = region->extents.x1;
  rectangle->y = region->extents.y1;
  rectangle->width = region->extents.x2 - region->extents.x1;
  rectangle->height = region->extents.y2 - region->extents.y1;
  GdkRectangle rect;
  rect.x = rectangle->x;
  rect.y = rectangle->y;
  rect.width = 0;
  rect.height = rectangle->height; 
  //The caret width is 2; 
  //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
  if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {
        gtk_im_context_set_cursor_location(local_context, rectangle);
  }
}

//this is needed, for example, if you input something in file dialog and return back the edit area
//context will lost, so here we set it again.

static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)
{
    XEvent *xev = (XEvent *)xevent;
    if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {
       GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window");
       if(GDK_IS_WINDOW(win))
         gtk_im_context_set_client_window(im_context, win);
    }
    return GDK_FILTER_CONTINUE;
}

void gtk_im_context_set_client_window (GtkIMContext *context,
          GdkWindow    *window)
{
  GtkIMContextClass *klass;
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
  if (klass->set_client_window)
    klass->set_client_window (context, window);

  if(!GDK_IS_WINDOW (window))
    return;
  g_object_set_data(G_OBJECT(context),"window",window);
  int width = gdk_window_get_width(window);
  int height = gdk_window_get_height(window);
  if(width != 0 && height !=0) {
    gtk_im_context_focus_in(context);
    local_context = context;
  }
  gdk_window_add_filter (window, event_filter, context); 
}

2, compile a shared library.

gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC

3, LD_PRELOAD it

LD_PRELOAD=./libsublime-imfix.so sublime_text
0 Likes

#17

.

0 Likes

#18

[quote=“cjacker”]This is a dirty fix but at least works. cursor location update still not works, since I really can not find a proper way to get the current caret loation relative to
GdkWidow, it seems sublime use a customized GtkWidget? I am not sure.

[/quote]

I’ve tested this in Archlinux with sublime version 2.0.1-2, It works quite well.

Thanks for your excellent job!!

0 Likes

#19

I’ve tested this in Archlinux with sublime version 2.0.1-2, It works quite well.

Thanks for your excellent job!![/quote]

original post had been updated to support cursor location update, please try it.

0 Likes

#20

Followed all of cjacker’s steps but they didn’t seem to work for me. No errors or anything, I just still don’t get anything from the IME. Even if I turn it on manurally, when I type the characters are still English, not the Japanese characters from the IME.

0 Likes

#21

[quote=“cjacker”]This is a dirty fix but at least works. cursor position update also supported.

Use LD_PRELOAD to reimplement gtk_im_context_set_client_window and set im focus in.
use “gdk_region_get_clipbox” to catch the caret position. (It’s really difficult to find which function can catch the position…)

[/quote]

I’ve tried your method and got the following result:

$ gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC $ LD_PRELOAD=./libsublime-imfix.so sublime-text ERROR: ld.so: object './libsublime-imfix.so' from LD_PRELOAD cannot be preloaded: ignored.

$ uname -ai Linux tonytonyjan-Latitude-6430U 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Is there any message I can give you?

0 Likes

#22

[quote=“cjacker”]This is a dirty fix but at least works. cursor position update also supported.

Use LD_PRELOAD to reimplement gtk_im_context_set_client_window and set im focus in.
use “gdk_region_get_clipbox” to catch the caret position. (It’s really difficult to find which function can catch the position…)
[/code][/quote]

I tried this on Ubuntu 12.04, it works but only work for FCITX not ibus.
I sure get cursor location update, but there still is some problem (actually a big one) - backspace will erase the text before cursor, not character in IME.

So, I guess I just went back to ibus since it makes me feel better :smile: Anyway, great work.

Another question: is it possible to bring this cursor location update feature to Windows version of sublime?
IME works better on Windows version of sublime, the only problem is cursor location update. If you can fix that, it will be really great.

Thanks dude, that works perfect!

0 Likes

#23

For Sublime Text 2, there was a nice plugin for supporting input method.
github.com/chikatoike/IMESuppor … DME_en.org
Now that Sublime Text 3 has threaded plugin system, the plugin no longer works properly, at least in my environment.
Because the plugin hooks the input, there are some side effects like BracketHighlighter becomes unworkable.
Please support the input method correctly, especially with Sublime Text 3 for Windows.

0 Likes

#24

I wasn’t able to use my compose key at all on Arch Linux running KDE with xim in ST2, I tried scim but it didn’t supposed custom compose keys from ~/.XCompose, but I was able to fix this for Linux by changing to scim-uim

To enable this for all GTK apps, put this into your ~/.xprofile after installing scim-uim, and then restart X:

GTK_IM_MODULE=uim-scim
Note that there are other ways to do this that make this work for all users on the computer and whatnot.
To run it just for ST2, or test it out without restarting, run this in your preferred console, set it as a bash alias, etc:

export GTK_IM_MODULE=uim-scim subl
Compose, and ~/.XCompose should now work.

0 Likes

#25

Sublime text used to be my favorite. Now due to this problem I’ve had to switch editors. So upsettting.

0 Likes

#26

I’ve fixed this problem: whitequark.org/blog/2014/04/14/x … lime-text/

0 Likes