Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(suggester): fix keydown 'enter' affect the default logic of newli… #190

Merged
merged 1 commit into from
Apr 7, 2022
Merged
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
56 changes: 37 additions & 19 deletions src/core/hooks/Suggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,44 @@ class SuggesterPanel {
keyAction = false;
});

this.editor.editor.setOption('extraKeys', {
Up() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Pass.toString();
}
},
Down() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Pass.toString();
}
},
Enter() {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Pass.toString();
}
},
const extraKeys = this.editor.editor.getOption('extraKeys');
const decorateKeys = ['Up', 'Down', 'Enter'];
decorateKeys.forEach((key) => {
if (typeof extraKeys[key] === 'function') {
const proxyTarget = extraKeys[key];
extraKeys[key] = (codemirror) => {
if (suggesterPanel.cursorMove) {
const res = proxyTarget.call(codemirror, codemirror);

if (res) {
return res;
}
// logic to decide whether to move up or not
return Pass.toString();
}
};
} else if (!extraKeys[key]) {
extraKeys[key] = () => {
if (suggesterPanel.cursorMove) {
// logic to decide whether to move up or not
return Pass.toString();
}
};
} else if (typeof extraKeys[key] === 'string') {
const command = extraKeys[key];
extraKeys[key] = (codemirror) => {
if (suggesterPanel.cursorMove) {
this.editor.editor.execCommand(command);

// logic to decide whether to move up or not
// return Pass.toString();
}
};
}
});

this.editor.editor.setOption('extraKeys', extraKeys);

this.editor.editor.on('scroll', (codemirror, evt) => {
if (!this.searchCache) {
return;
Expand Down Expand Up @@ -413,6 +430,7 @@ class SuggesterPanel {

nextElement.classList.add('cherry-suggester-panel__item--selected');
} else if (keyCode === 13) {
evt.stopPropagation();
this.cursorMove = false;
this.pasteSelectResult(this.findSelectedItemIndex());
codemirror.focus();
Expand Down