null checks p4
This commit is contained in:
parent
c7ed2aa62e
commit
877f1cf812
6 changed files with 107 additions and 49 deletions
20
gui/src/components/mainInput/FillerExtension.tsx
Normal file
20
gui/src/components/mainInput/FillerExtension.tsx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { Node } from "@tiptap/core";
|
||||
|
||||
export const MockExtension = Node.create({
|
||||
name: "mockExtension",
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
enabled: false,
|
||||
};
|
||||
},
|
||||
addCommands() {
|
||||
return {};
|
||||
},
|
||||
addKeyboardShortcuts() {
|
||||
return {};
|
||||
},
|
||||
addProseMirrorPlugins() {
|
||||
return [];
|
||||
},
|
||||
});
|
||||
|
|
@ -311,7 +311,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
useEffect(() => setSelectedIndex(0), [allItems]);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
onKeyDown: ({ event }) => {
|
||||
onKeyDown: ({ event }: { event: KeyboardEvent }) => {
|
||||
if (event.key === "ArrowUp") {
|
||||
upHandler();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@ import Paragraph from "@tiptap/extension-paragraph";
|
|||
import Placeholder from "@tiptap/extension-placeholder";
|
||||
import Text from "@tiptap/extension-text";
|
||||
import { Plugin } from "@tiptap/pm/state";
|
||||
import { Editor, EditorContent, JSONContent, useEditor } from "@tiptap/react";
|
||||
import {
|
||||
AnyExtension,
|
||||
Editor,
|
||||
EditorContent,
|
||||
JSONContent,
|
||||
useEditor,
|
||||
} from "@tiptap/react";
|
||||
import { ContextProviderDescription, InputModifiers } from "core";
|
||||
import { rifWithContentsToContextItem } from "core/commands/util";
|
||||
import { modelSupportsImages } from "core/llm/autodetect";
|
||||
|
|
@ -71,6 +77,7 @@ import {
|
|||
handleVSCMetaKeyIssues,
|
||||
} from "./handleMetaKeyIssues";
|
||||
import { ComboBoxItem } from "./types";
|
||||
import { MockExtension } from "./FillerExtension";
|
||||
|
||||
const InputBoxDiv = styled.div<{ border?: string }>`
|
||||
resize: none;
|
||||
|
|
@ -301,7 +308,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
const { prevRef, nextRef, addRef } = useInputHistory(props.historyKey);
|
||||
|
||||
const editor: Editor = useEditor({
|
||||
const editor: Editor | null = useEditor({
|
||||
extensions: [
|
||||
Document,
|
||||
History,
|
||||
|
|
@ -392,6 +399,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
if (isStreamingRef.current) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
"Shift-Enter": () =>
|
||||
this.editor.commands.first(({ commands }) => [
|
||||
|
|
@ -417,6 +425,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
}, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
Escape: () => {
|
||||
if (inDropdownRef.current || !isInEditModeRef.current) {
|
||||
|
|
@ -449,6 +458,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
}, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
};
|
||||
},
|
||||
|
|
@ -530,7 +540,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
return props.node.attrs.label;
|
||||
},
|
||||
})
|
||||
: undefined,
|
||||
: MockExtension,
|
||||
CodeBlockExtension,
|
||||
],
|
||||
editorProps: {
|
||||
|
|
@ -562,6 +572,9 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
const placeholder = getPlaceholderText(
|
||||
props.placeholder,
|
||||
historyLengthRef.current,
|
||||
|
|
@ -576,9 +589,9 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
useEffect(() => {
|
||||
if (props.isMainInput) {
|
||||
editor.commands.clearContent(true);
|
||||
editor?.commands.clearContent(true);
|
||||
}
|
||||
}, [isInEditMode, props.isMainInput]);
|
||||
}, [editor, isInEditMode, props.isMainInput]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editor) {
|
||||
|
|
@ -615,6 +628,10 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
* with those key actions.
|
||||
*/
|
||||
const handleKeyDown = async (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
setActiveKey(e.key);
|
||||
|
||||
if (!editorFocusedRef?.current || !isMetaEquivalentKeyPressed(e)) return;
|
||||
|
|
@ -632,6 +649,9 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
const onEnterRef = useUpdatingRef(
|
||||
(modifiers: InputModifiers) => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
if (isStreaming || isEditModeAndNoCodeToEdit) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -659,7 +679,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
* commands are redundant, especially the ones inside
|
||||
* useTimeout.
|
||||
*/
|
||||
editor.commands.focus();
|
||||
editor?.commands.focus();
|
||||
}
|
||||
}, [props.isMainInput, editor]);
|
||||
|
||||
|
|
@ -679,7 +699,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
return;
|
||||
}
|
||||
queueMicrotask(() => {
|
||||
editor.commands.setContent(mainInputContentTrigger);
|
||||
editor?.commands.setContent(mainInputContentTrigger);
|
||||
});
|
||||
dispatch(setMainEditorContentTrigger(undefined));
|
||||
}, [editor, props.isMainInput, mainInputContentTrigger]);
|
||||
|
|
@ -852,7 +872,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
useWebviewListener(
|
||||
"isContinueInputFocused",
|
||||
async () => {
|
||||
return props.isMainInput && editorFocusedRef.current;
|
||||
return props.isMainInput && !!editorFocusedRef.current;
|
||||
},
|
||||
[editorFocusedRef, props.isMainInput],
|
||||
!props.isMainInput,
|
||||
|
|
@ -902,6 +922,9 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
const insertCharacterWithWhitespace = useCallback(
|
||||
(char: string) => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
const text = editor.getText();
|
||||
if (!text.endsWith(char)) {
|
||||
if (text.length > 0 && !text.endsWith(" ")) {
|
||||
|
|
@ -921,7 +944,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
onKeyUp={handleKeyUp}
|
||||
className="cursor-text"
|
||||
onClick={() => {
|
||||
editor && editor.commands.focus();
|
||||
editor?.commands.focus();
|
||||
}}
|
||||
onDragOver={(event) => {
|
||||
event.preventDefault();
|
||||
|
|
@ -941,6 +964,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
}}
|
||||
onDrop={(event) => {
|
||||
if (
|
||||
!defaultModel ||
|
||||
!modelSupportsImages(
|
||||
defaultModel.provider,
|
||||
defaultModel.model,
|
||||
|
|
@ -952,11 +976,17 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
}
|
||||
setShowDragOverMsg(false);
|
||||
let file = event.dataTransfer.files[0];
|
||||
handleImageFile(file).then(([img, dataUrl]) => {
|
||||
const { schema } = editor.state;
|
||||
const node = schema.nodes.image.create({ src: dataUrl });
|
||||
const tr = editor.state.tr.insert(0, node);
|
||||
editor.view.dispatch(tr);
|
||||
handleImageFile(file).then((result) => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
const [_, dataUrl] = result;
|
||||
const { schema } = editor.state;
|
||||
const node = schema.nodes.image.create({ src: dataUrl });
|
||||
const tr = editor.state.tr.insert(0, node);
|
||||
editor.view.dispatch(tr);
|
||||
}
|
||||
});
|
||||
event.preventDefault();
|
||||
}}
|
||||
|
|
@ -977,13 +1007,19 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
onAddSlashCommand={() => insertCharacterWithWhitespace("/")}
|
||||
onEnter={onEnterRef.current}
|
||||
onImageFileSelected={(file) => {
|
||||
handleImageFile(file).then(([img, dataUrl]) => {
|
||||
const { schema } = editor.state;
|
||||
const node = schema.nodes.image.create({ src: dataUrl });
|
||||
editor.commands.command(({ tr }) => {
|
||||
tr.insert(0, node);
|
||||
return true;
|
||||
});
|
||||
handleImageFile(file).then((result) => {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
const [_, dataUrl] = result;
|
||||
const { schema } = editor.state;
|
||||
const node = schema.nodes.image.create({ src: dataUrl });
|
||||
editor.commands.command(({ tr }) => {
|
||||
tr.insert(0, node);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
disabled={isStreaming}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
vscListActiveBackground,
|
||||
vscListActiveForeground,
|
||||
} from "..";
|
||||
import { providers } from "../../pages/AddNewModel/configs/providers";
|
||||
import { DisplayInfo } from "../../pages/AddNewModel/configs/models";
|
||||
|
||||
export const StyledListbox = styled(Listbox)`
|
||||
background-color: ${vscBackground};
|
||||
|
|
@ -98,11 +98,6 @@ export const StyledListboxOption = styled(Listbox.Option)<{
|
|||
}
|
||||
`;
|
||||
|
||||
interface DisplayInfo {
|
||||
title: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
interface ModelSelectionListboxProps {
|
||||
selectedProvider: DisplayInfo;
|
||||
setSelectedProvider: Dispatch<SetStateAction<DisplayInfo>>;
|
||||
|
|
|
|||
|
|
@ -119,10 +119,12 @@ function useSetup() {
|
|||
if (isJetBrains()) {
|
||||
// Save theme colors to local storage for immediate loading in JetBrains
|
||||
ideMessenger.request("jetbrains/getColors", undefined).then((result) => {
|
||||
Object.keys(result).forEach((key) => {
|
||||
document.body.style.setProperty(key, result[key]);
|
||||
document.documentElement.style.setProperty(key, result[key]);
|
||||
});
|
||||
if (result.status === "success") {
|
||||
Object.entries(result.content).forEach(([key, value]) => {
|
||||
document.body.style.setProperty(key, value);
|
||||
document.documentElement.style.setProperty(key, value);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Tell JetBrains the webview is ready
|
||||
|
|
|
|||
|
|
@ -122,22 +122,24 @@ function AddNewModel() {
|
|||
</div>
|
||||
|
||||
<GridDiv>
|
||||
{Object.entries(providers).map(([providerName, modelInfo], i) => (
|
||||
<ModelCard
|
||||
key={`${providerName}-${i}`}
|
||||
title={modelInfo.title}
|
||||
description={modelInfo.description}
|
||||
tags={modelInfo.tags}
|
||||
icon={modelInfo.icon}
|
||||
refUrl={`https://docs.continue.dev/reference/Model%20Providers/${
|
||||
modelInfo.refPage || modelInfo.provider.toLowerCase()
|
||||
}`}
|
||||
onClick={(e) => {
|
||||
console.log(`/addModel/provider/${providerName}`);
|
||||
navigate(`/addModel/provider/${providerName}`);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
{Object.entries(providers).map(([providerName, modelInfo], i) =>
|
||||
modelInfo ? (
|
||||
<ModelCard
|
||||
key={`${providerName}-${i}`}
|
||||
title={modelInfo.title}
|
||||
description={modelInfo.description}
|
||||
tags={modelInfo.tags}
|
||||
icon={modelInfo.icon}
|
||||
refUrl={`https://docs.continue.dev/reference/Model%20Providers/${
|
||||
modelInfo.refPage || modelInfo.provider.toLowerCase()
|
||||
}`}
|
||||
onClick={(e) => {
|
||||
console.log(`/addModel/provider/${providerName}`);
|
||||
navigate(`/addModel/provider/${providerName}`);
|
||||
}}
|
||||
/>
|
||||
) : null,
|
||||
)}
|
||||
</GridDiv>
|
||||
</>
|
||||
) : (
|
||||
|
|
@ -176,6 +178,9 @@ function AddNewModel() {
|
|||
dimensions={config.dimensions}
|
||||
providerOptions={config.providerOptions}
|
||||
onClick={(e, dimensionChoices, selectedProvider) => {
|
||||
if (!selectedProvider) {
|
||||
return;
|
||||
}
|
||||
const model = {
|
||||
...config.params,
|
||||
..._.merge(
|
||||
|
|
@ -187,7 +192,7 @@ function AddNewModel() {
|
|||
};
|
||||
}) || []),
|
||||
),
|
||||
provider: providers[selectedProvider].provider,
|
||||
provider: providers[selectedProvider]?.provider,
|
||||
};
|
||||
ideMessenger.post("config/addModel", { model });
|
||||
dispatch(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue