Skip to content

Commit

Permalink
Report cursor width when editing input
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Dec 16, 2013
1 parent 1194c9f commit ed0a644
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
9 changes: 9 additions & 0 deletions libkkc/context.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ namespace Kkc {
}
}

/**
* Current cursor width in input string.
*/
public uint input_cursor_width {
get {
return state.input_cursor_width;
}
}

State state;
Gee.Map<Type, StateHandler> handlers =
new HashMap<Type, StateHandler> ();
Expand Down
36 changes: 34 additions & 2 deletions libkkc/state.vala
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,42 @@ namespace Kkc {
internal int input_characters_cursor_pos = -1;

internal int input_cursor_pos {
get {
if (input_characters_cursor_pos >= 0) {
var index = 0;
var offset = 0;
for (; index < input_characters_cursor_pos; index++) {
offset += input_characters[index].output.char_count ();
}
// Hack for Kana typing rule: add the length of
// unfinished Kana input. Suppose the following
// input when moving cursor in the initial state:
//
// F|F|FFFFF (F = finished characters, | = cursor)
//
// If user types a finished character (e.g. A, I):
//
// FX|F|FFFFF
//
// On the other hand, if user types an unfinished
// character (e.g. KA, CHI, which may be followed
// by sonant marks):
//
// F|X|FFFFFF
//
// For consistency, move the cursor by the width
// of the unfisnished character.
offset += rom_kana_converter.pending_output.char_count ();
return offset;
}
return input_characters_cursor_pos;
}
}

internal uint input_cursor_width {
get {
if (input_characters_cursor_pos >= 0)
return input_characters_cursor_pos +
rom_kana_converter.pending_output.char_count ();
return input_characters[input_characters_cursor_pos].output.char_count ();
return input_characters_cursor_pos;
}
}
Expand Down

0 comments on commit ed0a644

Please sign in to comment.