Skip to content

Commit

Permalink
Fix a few bugs related to "insert as text" command (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadashi-aikawa committed Aug 26, 2023
1 parent 0f85afc commit e030f45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ui/AutoCompleteSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class AutoCompleteSuggest
this.settings.hotkeys["insert as text"].forEach((hk) => {
this.keymapEventHandler.push(
this.scope.register(hk.modifiers, hk.key, (evt) =>
commands.insertAsText(this)
commands.insertAsText(this, evt)
)
);
});
Expand Down
14 changes: 12 additions & 2 deletions src/ui/popup-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ export function select(
}
}

export function insertAsText(popup: AutoCompleteSuggest): CommandReturnType {
if (!popup.context) {
export function insertAsText(
popup: AutoCompleteSuggest,
evt: KeyboardEvent
): CommandReturnType {
if (!popup.context || evt.isComposing) {
return;
}

if (popup.selectionLock) {
popup.close();
return true;
}

const item = popup.suggestions.values[popup.suggestions.selectedItem];
const editor = popup.context.editor;
editor.replaceRange(
Expand All @@ -34,6 +42,8 @@ export function insertAsText(popup: AutoCompleteSuggest): CommandReturnType {
},
popup.context.end
);

return false;
}

export function selectNext(
Expand Down

0 comments on commit e030f45

Please sign in to comment.