Skip to content

Commit

Permalink
Merge pull request #214 from vim-skk/feat-abolish_usepopup
Browse files Browse the repository at this point in the history
feat!: abolish `usePopup` option
  • Loading branch information
kuuote authored Dec 17, 2024
2 parents 8f4f54a + be4d3a6 commit b86773f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 69 deletions.
31 changes: 30 additions & 1 deletion autoload/skkeleton/popup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,37 @@ function! skkeleton#popup#open(candidates) abort
autocmd skkeleton-internal User skkeleton-handled ++once call s:open(s:candidates)
endfunction

function! s:open_cmdline(candidates)
let top = &lines + 1 - max([1, &cmdheight]) - len(a:candidates)
if has('nvim')
let buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(buf, 0, -1, v:true, a:candidates)
let opts = {
\ 'relative': 'editor',
\ 'width': max(map(copy(a:candidates), 'strwidth(v:val)')),
\ 'height': len(a:candidates),
\ 'col': getcmdscreenpos(),
\ 'row': top,
\ 'style': 'minimal'
\ }
let win = nvim_open_win(buf, 0, opts)
redraw
call add(s:windows, win)
else
let id = popup_create(a:candidates, {
\ 'line': top,
\ 'col': getcmdscreenpos(),
\ })
call add(s:windows, id)
endif
endfunction

function! s:open(candidates) abort
autocmd skkeleton-internal User skkeleton-handled ++once call skkeleton#popup#close()
if mode() == 'c'
call s:open_cmdline(a:candidates)
return
endif
let spos = screenpos(0, line('.'), col('.'))
" Note: Neovimではecho areaにfloatwinを被せるのが許可されておらず、ずれるため
" offset付けることで弾く
Expand Down Expand Up @@ -33,7 +63,6 @@ function! s:open(candidates) abort
\ })
call add(s:windows, id)
endif
autocmd skkeleton-internal User skkeleton-handled ++once call skkeleton#popup#close()
endfunction

function! skkeleton#popup#close() abort
Expand Down
2 changes: 0 additions & 2 deletions denops/skkeleton/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const config: Omit<ConfigOptions, "globalDictionaries"> & {
skkServerReqEnc: "euc-jp",
skkServerResEnc: "euc-jp",
sources: ["skk_dictionary"],
usePopup: true,
userDictionary: "~/.skkeleton",
};

Expand Down Expand Up @@ -116,7 +115,6 @@ const validators: Validators = {
useGoogleJapaneseInput: () => {
throw '`useGoogleJapaneseInput` is removed. Please use `sources` with "google_japanese_input"';
},
usePopup: (x) => ensure(x, is.Boolean),
useSkkServer: () => {
throw '`useSkkServer` is removed. Please use `sources` with "skk_server"';
},
Expand Down
63 changes: 2 additions & 61 deletions denops/skkeleton/function/henkan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { currentLibrary } from "../store.ts";
import { handleKey } from "../keymap.ts";
import { keyToNotation } from "../notation.ts";
import { getOkuriStr } from "../okuri.ts";
import { HenkanState, initializeState } from "../state.ts";
import { HenkanState } from "../state.ts";
import { kakutei } from "./common.ts";
import { acceptResult, henkanPoint, kakuteiFeed } from "./input.ts";
import { registerWord } from "./dictionary.ts";
Expand Down Expand Up @@ -76,11 +76,7 @@ export async function henkanForward(context: Context) {
}
}
if (state.candidateIndex >= config.showCandidatesCount) {
if (config.usePopup && context.vimMode === "i") {
await showCandidates(context.denops!, state);
} else {
await selectCandidates(context);
}
await showCandidates(context.denops!, state);
}
}

Expand All @@ -106,61 +102,6 @@ export async function henkanBackward(context: Context) {
}
}

async function selectCandidates(context: Context) {
const state = context.state as HenkanState;
const denops = context.denops!;
const count = config.showCandidatesCount;
const keys = config.selectCandidateKeys;
let index = 0;
while (index >= 0) {
const start = count + index * keys.length;
if (start >= state.candidates.length) {
if (await registerWord(context)) {
return;
}
}
const candidates = state.candidates.slice(start, start + keys.length);
const msg = candidates.map((c, i) =>
`${keys[i]}: ${modifyCandidate(c, state.affix)}`
).join(" ");
let keyCode: number;
try {
keyCode = await denops.call("skkeleton#getchar", msg) as number;
} catch (e: unknown) {
// Note: Ctrl-C is interrupt
// Manually convert to key code
if (String(e).match(/[Ii]nterrput/)) {
keyCode = 3;
} else {
throw e;
}
}
// Cancel select by <C-c> or <C-g> or <Esc>
if (keyCode == 3 || keyCode == 7 || keyCode == 27) {
if (config.immediatelyCancel) {
initializeState(context.state);
}
return;
}
const key = String.fromCharCode(keyCode);
if (key === " ") {
index += 1;
} else if (key === "x") {
index -= 1;
} else {
const candIndex = keys.indexOf(key);
if (candIndex !== -1) {
if (start + candIndex < state.candidates.length) {
state.candidateIndex = start + candIndex;
await kakutei(context);
return;
}
}
}
}
state.candidateIndex = config.showCandidatesCount - 1;
}

async function showCandidates(denops: Denops, state: HenkanState) {
const idx = state.candidateIndex;
const candidates = state.candidates.slice(idx, idx + 7);
Expand Down
1 change: 0 additions & 1 deletion denops/skkeleton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export type ConfigOptions = {
skkServerResEnc: Encoding;
sources: string[];
useGoogleJapaneseInput?: never;
usePopup: boolean;
useSkkServer?: never;
userDictionary: string;
};
7 changes: 3 additions & 4 deletions doc/skkeleton.jax
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,6 @@ sources *skkeleton-config-sources*
Note: ネットワーク接続環境が必要です。
Note: パフォーマンスの問題により補完には対応しません。

usePopup *skkeleton-config-usePopup*
(デフォルト v:true)
このオプションを有効にすると、変換候補がポップアップ表示されます。

useSkkServer *skkeleton-config-useSkkServer*
(デフォルト v:false)
辞書サーバー機能を有効にします。
Expand Down Expand Up @@ -567,6 +563,9 @@ skkeletonは|:lmap|を使用しなくなりました。カーソルの色を動
==============================================================================
COMPATIBILITY *skkeleton-compatibility*

2024-12-17~
- "usePopup" オプションを廃止し、cmdline含め常にpopupを表示するようにした

2024-07-27~
- denops v7を前提とするように
- ddcのfilterを廃止(sourceでフィルタリングしているため)
Expand Down

0 comments on commit b86773f

Please sign in to comment.