mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
Merge pull request #265 from webzard-io/auto-complete
impl #225 trigger auto-complete when typing
This commit is contained in:
commit
f68207c91c
@ -22,7 +22,12 @@ function installTern(cm: CodeMirror.Editor) {
|
||||
const t = new CodeMirror.TernServer({ defs: [ecma as unknown as Def] });
|
||||
cm.on('cursorActivity', cm => t.updateArgHints(cm));
|
||||
cm.on('change', (_instance, change) => {
|
||||
if (change.text.length === 1 && change.text[0] === '.') {
|
||||
if (
|
||||
// change happened
|
||||
change.text.length + (change.removed?.length || 0) > 0 &&
|
||||
// not changed by auto-complete
|
||||
change.origin !== 'complete'
|
||||
) {
|
||||
t.complete(cm);
|
||||
}
|
||||
});
|
||||
@ -69,6 +74,9 @@ export const ExpressionEditor: React.FC<{
|
||||
},
|
||||
theme: 'ayu-mirage',
|
||||
viewportMargin: Infinity,
|
||||
hintOptions: {
|
||||
completeSingle: false,
|
||||
},
|
||||
});
|
||||
const t = installTern(cm.current);
|
||||
tServer.current = t.server;
|
||||
@ -93,5 +101,14 @@ export const ExpressionEditor: React.FC<{
|
||||
}
|
||||
}, [defs]);
|
||||
|
||||
return <Box css={style} ref={wrapperEl} height="100%" width="100%" />;
|
||||
return (
|
||||
<Box
|
||||
css={style}
|
||||
ref={wrapperEl}
|
||||
height="100%"
|
||||
width="100%"
|
||||
borderRadius="2"
|
||||
overflow="hidden"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user