74 lines
2.5 KiB
Diff
74 lines
2.5 KiB
Diff
|
From 6bec9368e23e2637e81b7b6b56b02a88d5f2bbda Mon Sep 17 00:00:00 2001
|
||
|
From: Daiki Ueno <ueno@unixuser.org>
|
||
|
Date: Wed, 15 Sep 2010 12:21:35 +0900
|
||
|
Subject: [PATCH] Support surrounding-text commands.
|
||
|
|
||
|
---
|
||
|
src/engine.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++---
|
||
|
1 files changed, 48 insertions(+), 3 deletions(-)
|
||
|
|
||
|
diff --git a/src/engine.c b/src/engine.c
|
||
|
index 260a806..73d6ef2 100644
|
||
|
--- a/src/engine.c
|
||
|
+++ b/src/engine.c
|
||
|
@@ -812,8 +812,53 @@ ibus_m17n_engine_callback (MInputContext *context,
|
||
|
}
|
||
|
else if (command == Minput_reset) {
|
||
|
}
|
||
|
- else if (command == Minput_get_surrounding_text) {
|
||
|
- }
|
||
|
- else if (command == Minput_delete_surrounding_text) {
|
||
|
+ else if (command == Minput_get_surrounding_text &&
|
||
|
+ (((IBusEngine *) m17n)->client_capabilities &
|
||
|
+ IBUS_CAP_SURROUNDING_TEXT) != 0) {
|
||
|
+ IBusText *text;
|
||
|
+ guint cursor_pos, nchars, nbytes;
|
||
|
+ MText *mt, *surround;
|
||
|
+ int len, pos;
|
||
|
+
|
||
|
+ ibus_engine_get_surrounding_text ((IBusEngine *) m17n,
|
||
|
+ &text,
|
||
|
+ &cursor_pos);
|
||
|
+ nchars = ibus_text_get_length (text);
|
||
|
+ nbytes = g_utf8_offset_to_pointer (text->text, nchars) - text->text;
|
||
|
+ mt = mconv_decode_buffer (Mcoding_utf_8, text->text, nbytes);
|
||
|
+ g_object_unref (text);
|
||
|
+
|
||
|
+ len = (long) mplist_value (m17n->context->plist);
|
||
|
+ if (len < 0) {
|
||
|
+ pos = cursor_pos + len;
|
||
|
+ if (pos < 0)
|
||
|
+ pos = 0;
|
||
|
+ surround = mtext_duplicate (mt, pos, cursor_pos);
|
||
|
+ }
|
||
|
+ else if (len > 0) {
|
||
|
+ pos = cursor_pos + len;
|
||
|
+ if (pos > nchars)
|
||
|
+ pos = nchars;
|
||
|
+ surround = mtext_duplicate (mt, cursor_pos, pos);
|
||
|
+ }
|
||
|
+ else {
|
||
|
+ surround = mtext ();
|
||
|
+ }
|
||
|
+ m17n_object_unref (mt);
|
||
|
+ mplist_set (m17n->context->plist, Mtext, surround);
|
||
|
+ m17n_object_unref (surround);
|
||
|
+ }
|
||
|
+ else if (command == Minput_delete_surrounding_text &&
|
||
|
+ (((IBusEngine *) m17n)->client_capabilities &
|
||
|
+ IBUS_CAP_SURROUNDING_TEXT) != 0) {
|
||
|
+ int len;
|
||
|
+
|
||
|
+ len = (long) mplist_value (m17n->context->plist);
|
||
|
+ if (len < 0)
|
||
|
+ ibus_engine_delete_surrounding_text ((IBusEngine *) m17n,
|
||
|
+ len, -len);
|
||
|
+ else if (len > 0)
|
||
|
+ ibus_engine_delete_surrounding_text ((IBusEngine *) m17n,
|
||
|
+ 0, len);
|
||
|
}
|
||
|
}
|
||
|
--
|
||
|
1.7.2.3
|
||
|
|