Skip to content
Closed
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
54 changes: 49 additions & 5 deletions denops/skkeleton/function/henkan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import { currentLibrary } from "../store.ts";
import { handleKey } from "../keymap.ts";
import { keyToNotation } from "../notation.ts";
import { getOkuriStr } from "../okuri.ts";
import { HenkanState } from "../state.ts";
import { HenkanState, InputState } from "../state.ts";
import { kakutei } from "./common.ts";
import { acceptResult, henkanPoint, kakuteiFeed } from "./input.ts";
import {
acceptResult,
henkanPoint,
kakuteiFeed,
kakuteiKana,
kanaInput,
} from "./input.ts";
import { registerWord } from "./dictionary.ts";

import type { Denops } from "jsr:@denops/std@^7.6.0";
Expand All @@ -17,13 +23,51 @@ export async function henkanFirst(context: Context, key: string) {
return;
}

kakuteiFeed(context);

if (context.state.mode === "direct") {
context.kakutei(key);
// To prevent the infinite recursive call when henkanFirst itself is registered in rom_kana table.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このコメント行が長いのでフォーマットしてください

const char = config.lowercaseMap[key] ?? key.toLowerCase();
const state = context.state as InputState;

const next = state.feed + char;
const found_next = state.table.filter((e) => e[0].startsWith(next));

if (
found_next.length === 1 && found_next[0][0] === next &&
found_next[0][1] === henkanFirst
) {
context.kakutei(next);
return;
} else if (found_next.length === 0 && state.feed) {
const current = state.table.find((e) => e[0] === state.feed);
const found_char = state.table.filter((e) => e[0] === char);
if (current && current[1] === henkanFirst) {
context.kakutei(current[0]);
state.feed = "";
}
if (
found_char.length === 1 && found_char[0][0] === char &&
found_char[0][1] === henkanFirst
) {
if (current) {
if (current[1] !== henkanFirst) {
await acceptResult(context, current[1], next);
}
} else if (config.acceptIllegalResult) {
kakuteiKana(state, context.preEdit, state.feed, "");
} else {
state.feed = "";
}
context.kakutei(char);
return;
}
}

kanaInput(context, key);
return;
}

kakuteiFeed(context);

if (context.state.henkanFeed === "") {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions denops/skkeleton/kana/rom_hira.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { disable } from "../function/disable.ts";
import { henkanFirst } from "../function/henkan.ts";
import { henkanPoint } from "../function/input.ts";
import { abbrev, zenkaku } from "../function/mode.ts";
import { katakana } from "../function/mode.ts";
import type { KanaTable } from "./type.ts";

export const romToHira: KanaTable = [
[" ", henkanFirst],
["!", ["!", ""]],
[",", ["、", ""]],
["-", ["ー", ""]],
Expand Down
2 changes: 2 additions & 0 deletions denops/skkeleton/keymap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { escape } from "./function/disable.ts";
import {
henkanBackward,
henkanFirst,
henkanForward,
henkanInput,
suffix,
Expand All @@ -32,6 +33,7 @@ const input: KeyMap = {
"<cr>": newline,
"<esc>": escape,
"<nl>": kakuteiKey,
"<space>": henkanFirst,
"<c-q>": hankatakana,
">": prefix,
},
Expand Down
2 changes: 1 addition & 1 deletion doc/skkeleton-functions.jax
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ escape *skkeleton-functions-escape*
再びモードに入った際にskkeletonが有効化されます。

henkanFirst *skkeleton-functions-henkanFirst*
(input)!
(input: <Space>)!
変換を開始します。
直接入力モードの場合は何もマッピングされていないように振る舞います。

Expand Down
1 change: 1 addition & 0 deletions doc/skkeleton.jax
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ input:
<CR> : |skkeleton-functions-newline|
<Esc> : |skkeleton-functions-escape|
<NL> : |skkeleton-functions-kakutei|
<Space> : |skkeleton-functions-henkanFirst|
henkan:
<C-g> : |skkeleton-functions-cancel|
<CR> : |skkeleton-functions-newline|
Expand Down
Loading