From f4c91d131ca81c91e3bb806bcbe65a744275b63b Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 3 Jun 2024 07:48:47 -0700 Subject: [PATCH] Don't send request on completion (Fixes #27) --- src-web/components/core/Editor/Editor.tsx | 37 +++++++++++--------- src-web/components/core/Editor/extensions.ts | 8 ++--- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src-web/components/core/Editor/Editor.tsx b/src-web/components/core/Editor/Editor.tsx index 79ac8d34..bfb889f2 100644 --- a/src-web/components/core/Editor/Editor.tsx +++ b/src-web/components/core/Editor/Editor.tsx @@ -331,21 +331,7 @@ function getExtensions({ undefined; return [ - // NOTE: These *must* be anonymous functions so the references update properly - EditorView.domEventHandlers({ - focus: () => { - onFocus.current?.(); - }, - blur: () => { - onBlur.current?.(); - }, - keydown: (e) => { - onKeyDown.current?.(e); - }, - paste: (e) => { - onPaste.current?.(e.clipboardData?.getData('text/plain') ?? ''); - }, - }), + ...baseExtensions, // Must be first tooltips({ parent }), keymap.of(singleLine ? defaultKeymap.filter((k) => k.key !== 'Enter') : defaultKeymap), ...(singleLine ? [singleLineExt()] : []), @@ -354,14 +340,31 @@ function getExtensions({ ? [EditorState.readOnly.of(true), EditorView.contentAttributes.of({ tabindex: '-1' })] : []), - // Handle onChange + // ------------------------ // + // Things that must be last // + // ------------------------ // + EditorView.updateListener.of((update) => { if (onChange && update.docChanged) { onChange.current?.(update.state.doc.toString()); } }), - ...baseExtensions, + EditorView.domEventHandlers({ + focus: () => { + onFocus.current?.(); + }, + blur: () => { + onBlur.current?.(); + }, + keydown: (e, cm) => { + console.log('KEY DOWN', e, cm); + onKeyDown.current?.(e); + }, + paste: (e) => { + onPaste.current?.(e.clipboardData?.getData('text/plain') ?? ''); + }, + }), ]; } diff --git a/src-web/components/core/Editor/extensions.ts b/src-web/components/core/Editor/extensions.ts index 47c13e4b..7cab4610 100644 --- a/src-web/components/core/Editor/extensions.ts +++ b/src-web/components/core/Editor/extensions.ts @@ -39,7 +39,7 @@ import { text } from './text/extension'; import { twig } from './twig/extension'; import { url } from './url/extension'; -export const myHighlightStyle = HighlightStyle.define([ +export const syntaxHighlightStyle = HighlightStyle.define([ { tag: [t.documentMeta, t.blockComment, t.lineComment, t.docComment, t.comment], color: 'var(--fg-subtler)', @@ -61,7 +61,7 @@ export const myHighlightStyle = HighlightStyle.define([ { tag: [t.atom, t.meta, t.operator, t.bool, t.null, t.keyword], color: 'var(--fg-danger)' }, ]); -const myTheme = EditorView.theme({}, { dark: true }); +const syntaxTheme = EditorView.theme({}, { dark: true }); const syntaxExtensions: Record = { 'application/graphql': graphqlLanguageSupport(), @@ -108,8 +108,8 @@ export const baseExtensions = [ return (a.boost ?? 0) - (b.boost ?? 0); }, }), - syntaxHighlighting(myHighlightStyle), - myTheme, + syntaxHighlighting(syntaxHighlightStyle), + syntaxTheme, EditorState.allowMultipleSelections.of(true), ];