Skip to content

Commit

Permalink
Rename state field variable for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
taichimaeda committed Apr 28, 2024
1 parent b01011c commit e92a26f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/editor/keymap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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: {
Expand All @@ -41,7 +41,7 @@ export function acceptCompletionsOnKeydown(
state.changes({
from: head,
to: head,
insert: field.completions,
insert: completionsState.completions,
}),
],
});
Expand All @@ -66,6 +66,8 @@ export function rejectCompletionsOnKeydown(
cancel: CompletionsCancel,
plugin: Markpilot,
) {
const { settings } = plugin;

function run(view: EditorView) {
const { state } = view;

Expand All @@ -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;
}

Expand All @@ -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 }]));
}
3 changes: 1 addition & 2 deletions src/editor/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/editor/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit e92a26f

Please sign in to comment.