mirror of
https://github.com/mii443/akaza.git
synced 2025-08-22 14:55:31 +00:00
Merge pull request #262 from akaza-im/issue-259
ライブコンバージョンのルックアップテーブル処理を変更 Close #259
This commit is contained in:
@ -11,7 +11,7 @@ use crate::AkazaContext;
|
||||
/**
|
||||
* shortcut key を設定可能な機能。
|
||||
*/
|
||||
pub type IbusAkazaCommand = fn(&mut AkazaContext, *mut IBusEngine);
|
||||
pub type IbusAkazaCommand = fn(&mut AkazaContext, *mut IBusEngine) -> bool;
|
||||
|
||||
pub(crate) fn ibus_akaza_commands_map() -> HashMap<&'static str, IbusAkazaCommand> {
|
||||
let mut function_map: HashMap<&'static str, IbusAkazaCommand> = HashMap::new();
|
||||
@ -21,107 +21,132 @@ pub(crate) fn ibus_akaza_commands_map() -> HashMap<&'static str, IbusAkazaComman
|
||||
|
||||
register("commit_candidate", |context, engine| {
|
||||
context.commit_candidate(engine);
|
||||
true
|
||||
});
|
||||
// 無変換状態では、ひらがなに変換してコミットします
|
||||
register("commit_preedit", |context, engine| {
|
||||
let (_, surface) = context.make_preedit_word();
|
||||
context.commit_string(engine, surface.as_str());
|
||||
true
|
||||
});
|
||||
register("escape", |context, engine| {
|
||||
context.escape(engine);
|
||||
true
|
||||
});
|
||||
register("escape", |context, engine| context.escape(engine));
|
||||
register("page_up", |context, engine| {
|
||||
context.page_up(engine);
|
||||
true
|
||||
});
|
||||
register("page_down", |context, engine| {
|
||||
context.page_down(engine);
|
||||
true
|
||||
});
|
||||
|
||||
register("set_input_mode_hiragana", |context, engine| {
|
||||
context.set_input_mode(engine, &INPUT_MODE_HIRAGANA)
|
||||
context.set_input_mode(engine, &INPUT_MODE_HIRAGANA);
|
||||
true
|
||||
});
|
||||
register("set_input_mode_alnum", |context, engine| {
|
||||
context.set_input_mode(engine, &INPUT_MODE_ALNUM)
|
||||
context.set_input_mode(engine, &INPUT_MODE_ALNUM);
|
||||
true
|
||||
});
|
||||
register("set_input_mode_fullwidth_alnum", |context, engine| {
|
||||
context.set_input_mode(engine, &INPUT_MODE_FULLWIDTH_ALNUM)
|
||||
context.set_input_mode(engine, &INPUT_MODE_FULLWIDTH_ALNUM);
|
||||
true
|
||||
});
|
||||
register("set_input_mode_katakana", |context, engine| {
|
||||
context.set_input_mode(engine, &INPUT_MODE_KATAKANA)
|
||||
context.set_input_mode(engine, &INPUT_MODE_KATAKANA);
|
||||
true
|
||||
});
|
||||
register("set_input_mode_halfwidth_katakana", |context, engine| {
|
||||
context.set_input_mode(engine, &INPUT_MODE_HALFWIDTH_KATAKANA)
|
||||
context.set_input_mode(engine, &INPUT_MODE_HALFWIDTH_KATAKANA);
|
||||
true
|
||||
});
|
||||
|
||||
register("update_candidates", |context, engine| {
|
||||
context.update_candidates(engine)
|
||||
context.update_candidates(engine, true);
|
||||
true
|
||||
});
|
||||
register("erase_character_before_cursor", |context, engine| {
|
||||
context.erase_character_before_cursor(engine)
|
||||
context.erase_character_before_cursor(engine);
|
||||
true
|
||||
});
|
||||
register("cursor_up", |context, engine| {
|
||||
context.cursor_up(engine);
|
||||
true
|
||||
});
|
||||
register("cursor_down", |context, engine| {
|
||||
context.cursor_down(engine);
|
||||
true
|
||||
});
|
||||
register("cursor_right", |context, engine| {
|
||||
context.cursor_right(engine);
|
||||
true
|
||||
});
|
||||
register("cursor_left", |context, engine| {
|
||||
context.cursor_left(engine);
|
||||
true
|
||||
});
|
||||
register("extend_clause_right", |context, engine| {
|
||||
context.extend_clause_right(engine).unwrap();
|
||||
true
|
||||
});
|
||||
register("extend_clause_left", |context, engine| {
|
||||
context.extend_clause_left(engine).unwrap();
|
||||
true
|
||||
});
|
||||
register("convert_to_full_hiragana", |context, engine| {
|
||||
context.convert_to_full_hiragana(engine).unwrap();
|
||||
true
|
||||
});
|
||||
register("convert_to_full_katakana", |context, engine| {
|
||||
context.convert_to_full_katakana(engine).unwrap();
|
||||
true
|
||||
});
|
||||
register("convert_to_half_katakana", |context, engine| {
|
||||
context.convert_to_half_katakana(engine).unwrap();
|
||||
true
|
||||
});
|
||||
register("convert_to_full_romaji", |context, engine| {
|
||||
context.convert_to_full_romaji(engine).unwrap();
|
||||
true
|
||||
});
|
||||
register("convert_to_half_romaji", |context, engine| {
|
||||
context.convert_to_half_romaji(engine).unwrap();
|
||||
true
|
||||
});
|
||||
|
||||
{
|
||||
// TODO コピペがすごい。マクロかうまいなにかでまとめて登録できるようにしたい。
|
||||
register("press_number_1", |context, engine| {
|
||||
context.process_num_key(1, engine);
|
||||
context.process_num_key(1, engine)
|
||||
});
|
||||
register("press_number_2", |context, engine| {
|
||||
context.process_num_key(2, engine);
|
||||
context.process_num_key(2, engine)
|
||||
});
|
||||
register("press_number_3", |context, engine| {
|
||||
context.process_num_key(3, engine);
|
||||
context.process_num_key(3, engine)
|
||||
});
|
||||
register("press_number_4", |context, engine| {
|
||||
context.process_num_key(4, engine);
|
||||
context.process_num_key(4, engine)
|
||||
});
|
||||
register("press_number_5", |context, engine| {
|
||||
context.process_num_key(5, engine);
|
||||
context.process_num_key(5, engine)
|
||||
});
|
||||
register("press_number_6", |context, engine| {
|
||||
context.process_num_key(6, engine);
|
||||
context.process_num_key(6, engine)
|
||||
});
|
||||
register("press_number_7", |context, engine| {
|
||||
context.process_num_key(7, engine);
|
||||
context.process_num_key(7, engine)
|
||||
});
|
||||
register("press_number_8", |context, engine| {
|
||||
context.process_num_key(8, engine);
|
||||
context.process_num_key(8, engine)
|
||||
});
|
||||
register("press_number_9", |context, engine| {
|
||||
context.process_num_key(9, engine);
|
||||
context.process_num_key(9, engine)
|
||||
});
|
||||
register("press_number_0", |context, engine| {
|
||||
context.process_num_key(0, engine);
|
||||
context.process_num_key(0, engine)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ pub struct AkazaContext {
|
||||
lookup_table: IBusLookupTable,
|
||||
prop_controller: PropController,
|
||||
live_conversion: bool,
|
||||
lookup_table_visible: bool,
|
||||
}
|
||||
|
||||
impl AkazaContext {
|
||||
@ -92,6 +93,7 @@ impl AkazaContext {
|
||||
prop_controller: PropController::new(input_mode)?,
|
||||
consonant_suffix_extractor: ConsonantSuffixExtractor::default(),
|
||||
live_conversion: config.live_conversion,
|
||||
lookup_table_visible: false,
|
||||
})
|
||||
}
|
||||
|
||||
@ -130,11 +132,19 @@ impl AkazaContext {
|
||||
}
|
||||
|
||||
impl AkazaContext {
|
||||
pub(crate) fn process_num_key(&mut self, nn: i32, engine: *mut IBusEngine) {
|
||||
pub(crate) fn process_num_key(&mut self, nn: i32, engine: *mut IBusEngine) -> bool {
|
||||
let idx = if nn == 0 { 9 } else { nn - 1 };
|
||||
|
||||
if self.set_lookup_table_cursor_pos_in_current_page(idx) {
|
||||
self.refresh(engine)
|
||||
if self.lookup_table_visible {
|
||||
if self.set_lookup_table_cursor_pos_in_current_page(idx) {
|
||||
self.refresh(engine, true);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
info!("ignore process_num_key. lookup table is not enabled.");
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +220,9 @@ impl AkazaContext {
|
||||
)
|
||||
.cloned()
|
||||
{
|
||||
return self.run_callback_by_name(engine, callback.as_str());
|
||||
if self.run_callback_by_name(engine, callback.as_str()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
match self.current_state.input_mode.prop_name {
|
||||
@ -241,7 +253,7 @@ impl AkazaContext {
|
||||
|
||||
// live conversion mode が true であれば、変換をガンガンかける
|
||||
if self.live_conversion {
|
||||
self.update_candidates(engine);
|
||||
self.update_candidates(engine, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -355,8 +367,7 @@ impl AkazaContext {
|
||||
) -> bool {
|
||||
if let Some(function) = self.command_map.get(function_name) {
|
||||
info!("Calling function '{}'", function_name);
|
||||
function(self, engine);
|
||||
true
|
||||
function(self, engine)
|
||||
} else {
|
||||
error!("Unknown function '{}'", function_name);
|
||||
false
|
||||
@ -401,12 +412,16 @@ impl AkazaContext {
|
||||
self.commit_string(engine, self.current_state.build_string().as_str());
|
||||
}
|
||||
|
||||
pub(crate) fn update_candidates(&mut self, engine: *mut IBusEngine) {
|
||||
self._update_candidates(engine).unwrap();
|
||||
pub(crate) fn update_candidates(&mut self, engine: *mut IBusEngine, show_lookup_table: bool) {
|
||||
self._update_candidates(engine, show_lookup_table).unwrap();
|
||||
self.current_state.clear_state();
|
||||
}
|
||||
|
||||
fn _update_candidates(&mut self, engine: *mut IBusEngine) -> Result<()> {
|
||||
fn _update_candidates(
|
||||
&mut self,
|
||||
engine: *mut IBusEngine,
|
||||
show_lookup_table: bool,
|
||||
) -> Result<()> {
|
||||
if self.current_state.preedit.is_empty() {
|
||||
self.current_state.set_clauses(vec![]);
|
||||
} else {
|
||||
@ -436,7 +451,7 @@ impl AkazaContext {
|
||||
self.current_state.adjust_current_clause();
|
||||
}
|
||||
self.create_lookup_table();
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, show_lookup_table);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -457,7 +472,7 @@ impl AkazaContext {
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh(&mut self, engine: *mut IBusEngine) {
|
||||
fn refresh(&mut self, engine: *mut IBusEngine, show_lookup_table: bool) {
|
||||
unsafe {
|
||||
if self.current_state.clauses.is_empty() {
|
||||
ibus_engine_hide_auxiliary_text(engine);
|
||||
@ -470,14 +485,16 @@ impl AkazaContext {
|
||||
let current_node = &(current_clause[0]);
|
||||
|
||||
// -- auxiliary text(ポップアップしてるやつのほう)
|
||||
let first_candidate = &(current_node.yomi);
|
||||
let auxiliary_text = first_candidate.as_str().to_ibus_text();
|
||||
ibus_text_set_attributes(auxiliary_text, ibus_attr_list_new());
|
||||
ibus_engine_update_auxiliary_text(
|
||||
engine,
|
||||
auxiliary_text,
|
||||
to_gboolean(!self.current_state.preedit.is_empty()),
|
||||
);
|
||||
if show_lookup_table {
|
||||
let first_candidate = &(current_node.yomi);
|
||||
let auxiliary_text = first_candidate.as_str().to_ibus_text();
|
||||
ibus_text_set_attributes(auxiliary_text, ibus_attr_list_new());
|
||||
ibus_engine_update_auxiliary_text(
|
||||
engine,
|
||||
auxiliary_text,
|
||||
to_gboolean(!self.current_state.preedit.is_empty()),
|
||||
);
|
||||
}
|
||||
|
||||
let text = self.current_state.build_string();
|
||||
let preedit_attrs = ibus_attr_list_new();
|
||||
@ -517,8 +534,12 @@ impl AkazaContext {
|
||||
);
|
||||
|
||||
// 候補があれば、選択肢を表示させる。
|
||||
let visible = self.lookup_table.get_number_of_candidates() > 0;
|
||||
self._update_lookup_table(engine, visible);
|
||||
if show_lookup_table {
|
||||
let visible = self.lookup_table.get_number_of_candidates() > 0;
|
||||
self._update_lookup_table(engine, visible);
|
||||
} else {
|
||||
self._update_lookup_table(engine, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -529,6 +550,7 @@ impl AkazaContext {
|
||||
&mut self.lookup_table as *mut _,
|
||||
to_gboolean(visible),
|
||||
);
|
||||
self.lookup_table_visible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,7 +598,7 @@ impl AkazaContext {
|
||||
if self.lookup_table.cursor_up() {
|
||||
self.current_state
|
||||
.select_candidate(self.lookup_table.get_cursor_pos() as usize);
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -585,7 +607,7 @@ impl AkazaContext {
|
||||
if self.lookup_table.cursor_down() {
|
||||
self.current_state
|
||||
.select_candidate(self.lookup_table.get_cursor_pos() as usize);
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,7 +615,7 @@ impl AkazaContext {
|
||||
if self.lookup_table.page_up() {
|
||||
self.current_state
|
||||
.select_candidate(self.lookup_table.get_cursor_pos() as usize);
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, true);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@ -604,7 +626,7 @@ impl AkazaContext {
|
||||
if self.lookup_table.page_up() {
|
||||
self.current_state
|
||||
.select_candidate(self.lookup_table.get_cursor_pos() as usize);
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, true);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@ -622,7 +644,7 @@ impl AkazaContext {
|
||||
|
||||
self.create_lookup_table();
|
||||
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, true);
|
||||
}
|
||||
|
||||
/// 選択する分節を左にずらす。
|
||||
@ -636,20 +658,20 @@ impl AkazaContext {
|
||||
|
||||
self.create_lookup_table();
|
||||
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, true);
|
||||
}
|
||||
|
||||
/// 文節の選択範囲を右方向に広げる
|
||||
pub fn extend_clause_right(&mut self, engine: *mut IBusEngine) -> Result<()> {
|
||||
self.current_state.extend_right();
|
||||
self._update_candidates(engine)?;
|
||||
self._update_candidates(engine, true)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 文節の選択範囲を左方向に広げる
|
||||
pub fn extend_clause_left(&mut self, engine: *mut IBusEngine) -> Result<()> {
|
||||
self.current_state.extend_left();
|
||||
self._update_candidates(engine)?;
|
||||
self._update_candidates(engine, true)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -746,13 +768,13 @@ impl AkazaContext {
|
||||
self.lookup_table.append_candidate(candidate);
|
||||
|
||||
// 表示を更新
|
||||
self.refresh(engine);
|
||||
self.refresh(engine, true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn escape(&mut self, engine: *mut IBusEngine) {
|
||||
trace!("escape: {}", self.current_state.preedit);
|
||||
self.current_state.clear();
|
||||
self.update_candidates(engine)
|
||||
self.update_candidates(engine, false)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user