From e92a26f6a3c582e0cbc1b09441390bf56220e6b5 Mon Sep 17 00:00:00 2001 From: Taichi Maeda Date: Sun, 28 Apr 2024 21:38:34 +0900 Subject: [PATCH] Rename state field variable for readability --- src/editor/keymap.ts | 16 +++++++++------- src/editor/state.ts | 3 +-- src/editor/view.ts | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/editor/keymap.ts b/src/editor/keymap.ts index 8e23914..32c8caa 100644 --- a/src/editor/keymap.ts +++ b/src/editor/keymap.ts @@ -18,8 +18,8 @@ export function acceptCompletionsOnKeydown( } // If there are no completions displayed, do nothing. - const field = state.field(completionsStateField); - if (field === undefined) { + const completionsState = state.field(completionsStateField); + if (completionsState === undefined) { return false; } @@ -30,7 +30,7 @@ export function acceptCompletionsOnKeydown( // Insert completions to the current cursor position. const head = state.selection.main.head; - const newHead = head + field.completions.length; + const newHead = head + completionsState.completions.length; view.dispatch({ selection: { @@ -41,7 +41,7 @@ export function acceptCompletionsOnKeydown( state.changes({ from: head, to: head, - insert: field.completions, + insert: completionsState.completions, }), ], }); @@ -66,6 +66,8 @@ export function rejectCompletionsOnKeydown( cancel: CompletionsCancel, plugin: Markpilot, ) { + const { settings } = plugin; + function run(view: EditorView) { const { state } = view; @@ -74,8 +76,8 @@ export function rejectCompletionsOnKeydown( } // If there are no completions displayed, do nothing. - const field = state.field(completionsStateField); - if (field === undefined) { + const completionsState = state.field(completionsStateField); + if (completionsState === undefined) { return false; } @@ -86,6 +88,6 @@ export function rejectCompletionsOnKeydown( return true; } - const key = plugin.settings.completions.rejectKey; + const key = settings.completions.rejectKey; return Prec.highest(keymap.of([{ key, run }])); } diff --git a/src/editor/state.ts b/src/editor/state.ts index 2b8ddf8..17d6f1e 100644 --- a/src/editor/state.ts +++ b/src/editor/state.ts @@ -20,8 +20,7 @@ export const completionsStateField = StateField.define< for (const effect of transaction.effects) { if (effect.is(setCompletionsEffect)) { return { completions: effect.value.completions }; - } - if (effect.is(unsetCompletionsEffect)) { + } else if (effect.is(unsetCompletionsEffect)) { return undefined; } } diff --git a/src/editor/view.ts b/src/editor/view.ts index 4c78cf6..3d48c56 100644 --- a/src/editor/view.ts +++ b/src/editor/view.ts @@ -33,14 +33,14 @@ class CompletionsRenderPluginValue implements PluginValue { update(update: ViewUpdate) { const { state } = update; - const field = state.field(completionsStateField); - if (field === undefined) { + const completionsState = state.field(completionsStateField); + if (completionsState === undefined) { this.decorations = Decoration.none; return; } const decoration = Decoration.widget({ - widget: new CompletionsWidget(field.completions), + widget: new CompletionsWidget(completionsState.completions), side: 1, }); this.decorations = Decoration.set([