Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix okuri-ari entry dictionary edit #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions libskk/context.vala
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,19 @@ namespace Skk {
}
}

void start_dict_edit (string midasi, bool okuri) {
void start_dict_edit (string yomi) {
var state = new State (_dictionaries);
state.typing_rule = typing_rule;
state.midasi = midasi;
state.yomi = yomi;
push_state (state);
update_preedit ();
}

bool end_dict_edit (string text) {
string? midasi;
bool? okuri;
if (leave_dict_edit (out midasi, out okuri)) {
string? output;
if (leave_dict_edit (text, out midasi, out okuri, out output)) {
var candidate = new Candidate (midasi, okuri, text);
if (select_candidate_in_dictionaries (candidate)) {
try {
Expand All @@ -396,33 +397,42 @@ namespace Skk {
}
var state = state_stack.peek_head ();
state.reset ();
state.output.assign (text);
state.output.assign (output);
update_preedit ();
return true;
}
return false;
}

bool leave_dict_edit (out string? midasi, out bool? okuri) {
bool leave_dict_edit (string text, out string? midasi, out bool? okuri, out string? output) {
if (dict_edit_level () > 0) {
var state = state_stack.peek_head ();
midasi = state.midasi;
pop_state ();
state = state_stack.peek_head ();
okuri = state.okuri;
midasi = state.get_midasi ();

if (okuri) {
output = text + state.okuri_rom_kana_converter.output;
} else {
output = text;
}

if (state.candidates.size == 0)
state.cancel_okuri ();
return true;
}
midasi = null;
okuri = false;
output = null;
return false;
}

bool abort_dict_edit () {
string? midasi;
bool? okuri;
if (leave_dict_edit (out midasi, out okuri)) {
string? output;
if (leave_dict_edit ("", out midasi, out okuri, out output)) {
update_preedit ();
return true;
}
Expand Down Expand Up @@ -655,7 +665,7 @@ namespace Skk {
iter.previous ();
state = iter.get ();
builder.append ("▼");
builder.append (state.midasi);
builder.append (state.yomi);
builder.append ("【");
}

Expand Down
50 changes: 26 additions & 24 deletions libskk/state.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace Skk {
internal bool okuri;

// Used by Context for dict edit.
internal string midasi;
internal string yomi;

internal StringBuilder selection = new StringBuilder ();
internal StringBuilder output = new StringBuilder ();
Expand Down Expand Up @@ -368,7 +368,7 @@ namespace Skk {

internal signal bool recursive_edit_abort ();
internal signal bool recursive_edit_end (string text);
internal signal void recursive_edit_start (string midasi, bool okuri);
internal signal void recursive_edit_start (string yomi);

internal UnicodeString? surrounding_text;
internal uint surrounding_end;
Expand Down Expand Up @@ -396,6 +396,28 @@ namespace Skk {
}
return builder.str;
}

internal string get_midasi () {
string midasi;
if (abbrev.len > 0) {
midasi = abbrev.str;
}
else {
StringBuilder builder = new StringBuilder ();
rom_kana_converter.output_nn_if_any ();
builder.append (rom_kana_converter.output);
if (okuri) {
var prefix = Util.get_okurigana_prefix (
Util.get_hiragana (
okuri_rom_kana_converter.output));
if (prefix != null) {
builder.append (prefix);
}
}
midasi = Util.get_hiragana (builder.str);
}
return midasi;
}
}

delegate bool CommandHandler (State state);
Expand Down Expand Up @@ -1039,27 +1061,7 @@ namespace Skk {
}
else if (command == "next-candidate") {
if (state.candidates.cursor_pos < 0) {
string midasi;
bool okuri = false;
if (state.abbrev.len > 0) {
midasi = state.abbrev.str;
}
else {
StringBuilder builder = new StringBuilder ();
state.rom_kana_converter.output_nn_if_any ();
builder.append (state.rom_kana_converter.output);
if (state.okuri) {
var prefix = Util.get_okurigana_prefix (
Util.get_hiragana (
state.okuri_rom_kana_converter.output));
if (prefix != null) {
builder.append (prefix);
okuri = true;
}
}
midasi = Util.get_hiragana (builder.str);
}
state.lookup (midasi, okuri);
state.lookup (state.get_midasi (), state.okuri);
if (state.candidates.size > 0) {
return true;
}
Expand All @@ -1068,7 +1070,7 @@ namespace Skk {
return true;
}
// no more candidates
state.recursive_edit_start (state.get_yomi (), state.okuri);
state.recursive_edit_start (state.get_yomi ());
if (state.candidates.size == 0) {
state.candidates.clear ();
state.handler_type = typeof (StartStateHandler);
Expand Down
5 changes: 5 additions & 0 deletions tests/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ static SkkTransition dict_edit_transitions[] =
/* Pull request#41 */
{ SKK_INPUT_MODE_HIRAGANA, "K a n j i k a t a k a n a k a n j i SPC K a n j i SPC K a t a k a n a q K a n j i SPC C-j", "▼かんじかたかなかんじ【漢字カタカナ漢字】", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "T e s u t o t e s u t o t e s u t o t e s u t o SPC t e s u t o T e s u t o q q T e s u t o q T e s u t o C-q C-q T e s u t o q", "▼てすとてすとてすとてすと【てすとテストてすとテストてすと】", "", SKK_INPUT_MODE_HANKAKU_KATAKANA},
/* Issue#77 */
{ SKK_INPUT_MODE_HIRAGANA, "G u g u R u G u g u q \n", "", "ググる", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "G u g u R u", "▼ググる", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "G u g u R a", "▼ググら", "", SKK_INPUT_MODE_HIRAGANA },

{ 0, NULL }
};

Expand Down