diff --git a/docs/docs/reference.md b/docs/docs/reference.md index 19e8f386e..391273943 100644 --- a/docs/docs/reference.md +++ b/docs/docs/reference.md @@ -421,7 +421,7 @@ Several experimental config parameters are available, as described below: - `fix`: Prompt for fixing code. - `optimize`: Prompt for optimizing code. - `fixGrammar`: Prompt for fixing grammar or spelling. -- `useChromiumForDocsCrawling`: Use chromium to crawl docs instead of default lighter-weight tool that can't render sites. Downloads and installs Chromium to `~/.continue/.utils`. +- `useChromiumForDocsCrawling`: Use Chromium to crawl docs locally. Useful if the default Cheerio crawler fails on sites that require JavaScript rendering. Downloads and installs Chromium to `~/.continue/.utils`.. Example diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ConfigJsonSchemaProviderFactory.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ConfigJsonSchemaProviderFactory.kt index c303b26fb..2056d216e 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ConfigJsonSchemaProviderFactory.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ConfigJsonSchemaProviderFactory.kt @@ -22,7 +22,7 @@ class ConfigJsonSchemaProviderFactory : JsonSchemaProviderFactory { class ConfigJsonSchemaFileProvider : JsonSchemaFileProvider { override fun isAvailable(file: VirtualFile): Boolean { - return path.endsWith("/.continue/config.json") + return file.path.endsWith("/.continue/config.json") } override fun getName(): String { diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinueExtensionSettingsService.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinueExtensionSettingsService.kt index f73ba509c..a8019e361 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinueExtensionSettingsService.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/ContinueExtensionSettingsService.kt @@ -2,6 +2,7 @@ package com.github.continuedev.continueintellijextension.services import com.github.continuedev.continueintellijextension.constants.getConfigJsPath import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath +import com.intellij.openapi.application.ApplicationInfo import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.* import com.intellij.openapi.options.Configurable @@ -28,6 +29,7 @@ class ContinueSettingsComponent : DumbAware { val userToken: JTextField = JTextField() val enableTabAutocomplete: JCheckBox = JCheckBox("Enable Tab Autocomplete") val enableContinueTeamsBeta: JCheckBox = JCheckBox("Enable Continue for Teams Beta") + val enableOSR: JCheckBox = JCheckBox("Enable Off-Screen Rendering") val displayEditorTooltip: JCheckBox = JCheckBox("Display Editor Tooltip") init { @@ -56,6 +58,8 @@ class ContinueSettingsComponent : DumbAware { constraints.gridy++ panel.add(enableContinueTeamsBeta, constraints) constraints.gridy++ + panel.add(enableOSR, constraints) + constraints.gridy++ panel.add(displayEditorTooltip, constraints) constraints.gridy++ @@ -87,6 +91,7 @@ open class ContinueExtensionSettings : PersistentStateComponent= minBuildNumber +} \ No newline at end of file diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 03d4f4715..7891a02dc 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -5,6 +5,7 @@ import com.github.continuedev.continueintellijextension.constants.MessageTypes import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath import com.github.continuedev.continueintellijextension.`continue`.* import com.github.continuedev.continueintellijextension.factories.CustomSchemeHandlerFactory +import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings import com.github.continuedev.continueintellijextension.services.ContinuePluginService import com.google.gson.Gson import com.google.gson.JsonObject @@ -78,7 +79,8 @@ class ContinueBrowser(val project: Project, url: String) { val browser: JBCefBrowser init { - this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(shouldRenderOffScreen()).build() + val enableOSR = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR + this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(enableOSR).build() browser.jbCefClient.setProperty( @@ -274,34 +276,4 @@ class ContinueBrowser(val project: Project, url: String) { return """window.postMessage($jsonData, "*");""" } - /** - * This function checks if the pluginSinceBuild is greater than or equal to 233, which corresponds - * to IntelliJ platform version 2023.3 and later. - * - * Setting `setOffScreenRendering` to `false` causes a number of issues such as a white screen flash when loading - * the GUI and the inability to set `cursor: pointer`. However, setting `setOffScreenRendering` to `true` on - * platform versions prior to 2023.3.4 causes larger issues such as an inability to type input for certain langauges, - * e.g. Korean. - * - * References: - * 1. https://youtrack.jetbrains.com/issue/IDEA-347828/JCEF-white-flash-when-tool-window-show#focus=Comments-27-9334070.0-0 - * This issue mentions that white screen flash problems were resolved in platformVersion 2023.3.4. - * 2. https://www.jetbrains.com/idea/download/other.html - * This documentation shows mappings from platformVersion to branchNumber. - * - * We use the branchNumber (e.g., 233) instead of the full version number (e.g., 2023.3.4) because - * it's a simple integer without dot notation, making it easier to compare. - */ - private fun shouldRenderOffScreen(): Boolean { - // With the 0.0.77 release, non-Mac users have been reporting issues with paste functionality - // in the browser. Disabling OSR for all non-Mac users for now. - if (!SystemInfo.isMac) { - return false - } - - val minBuildNumber = 233 - val applicationInfo = ApplicationInfo.getInstance() - val currentBuildNumber = applicationInfo.build.baselineVersion - return currentBuildNumber >= minBuildNumber - } } diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 3aa9906a2..f18bdbb6a 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -3320,6 +3320,11 @@ "default": "If there are any grammar or spelling mistakes in this writing, fix them. Do not make other large changes to the writing." } } + }, + "useChromiumForDocsCrawling": { + "type": "boolean", + "description": "Use Chromium to crawl docs locally. Useful if the default Cheerio crawler fails on sites that require JavaScript rendering. Downloads and installs Chromium to `~/.continue/.utils`.", + "default": false } } } diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index f801aa348..bf6530dcf 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -50,9 +50,11 @@ import { getFontSize, isJetBrains, isMetaEquivalentKeyPressed, - isWebEnvironment, } from "../../util"; -import { handleMetaKeyPressJetBrains } from "../../util/handleMetaKeyPressJetBrains"; +import { + handleJetBrainsMetaKeyPress, + handleMetaKeyPress, +} from "./handleMetaKeyPress"; import { CodeBlockExtension } from "./CodeBlockExtension"; import { SlashCommand } from "./CommandsExtension"; import InputToolbar, { ToolbarOptions } from "./InputToolbar"; @@ -78,6 +80,7 @@ const InputBoxDiv = styled.div<{ border?: string }>` props.border ? props.border : `0.5px solid ${vscInputBorder}`}; outline: none; font-size: ${getFontSize()}px; + &:focus { outline: none; @@ -561,7 +564,7 @@ function TipTapEditor(props: TipTapEditorProps) { /** * This handles various issues with meta key actions - * - In JetBrains, when using "off screen rendering", there is a bug where using the meta key to + * - In JetBrains, when using OSR in JCEF, there is a bug where using the meta key to * highlight code using arrow keys is not working * - In VS Code, while working with .ipynb files there is a problem where copy/paste/cut will affect * the actual notebook cells, even when performing them in our GUI @@ -571,77 +574,33 @@ function TipTapEditor(props: TipTapEditorProps) { setActiveKey(e.key); - if (isMetaEquivalentKeyPressed(e)) { - const { key, code } = e; - const isWebEnv = isWebEnvironment(); - const text = editor.state.doc.textBetween( - editor.state.selection.from, - editor.state.selection.to, - ); - - if (isJetBrains()) { - if (code === "KeyJ") { - e.stopPropagation(); - e.preventDefault(); - setIgnoreHighlightedCode(true); - setTimeout(() => { - setIgnoreHighlightedCode(false); - }, 100); - } - - if (isMetaEquivalentKeyPressed(e)) { - e.stopPropagation(); - e.preventDefault(); - handleMetaKeyPressJetBrains(e, text, editor.commands.setContent); - } - } else { - if (code === "KeyL") { - e.stopPropagation(); - e.preventDefault(); - setIgnoreHighlightedCode(true); - setTimeout(() => { - setIgnoreHighlightedCode(false); - }, 100); - return; - } - - switch (key) { - case "x": - e.stopPropagation(); - e.preventDefault(); - if (isWebEnv) { - await navigator.clipboard.writeText(text); - editor.commands.deleteSelection(); - } else { - document.execCommand("cut"); - } - break; - case "c": - e.stopPropagation(); - e.preventDefault(); - if (isWebEnv) { - await navigator.clipboard.writeText(text); - } else { - document.execCommand("copy"); - } - break; - case "v": - e.stopPropagation(); - e.preventDefault(); - if (isWebEnv) { - const clipboardText = await navigator.clipboard.readText(); - editor.commands.insertContent(clipboardText); - } else { - document.execCommand("paste"); - } - break; - } - } - } else if (e.key === "Escape") { + if (e.key === "Escape") { e.stopPropagation(); e.preventDefault(); ideMessenger.post("focusEditor", undefined); + return; } + + if (!isMetaEquivalentKeyPressed(e)) { + return; + } + + if (isJetBrains()) { + if (e.code === "KeyJ") { + setTemporaryIgnoreHighlightedCode(); + } else { + handleJetBrainsMetaKeyPress(e, editor); + } + } + + await handleMetaKeyPress(e, editor); + }; + + const setTemporaryIgnoreHighlightedCode = () => { + setIgnoreHighlightedCode(true); + setTimeout(() => { + setIgnoreHighlightedCode(false); + }, 100); }; const handleKeyUp = () => { diff --git a/gui/src/components/mainInput/handleMetaKeyPress.ts b/gui/src/components/mainInput/handleMetaKeyPress.ts new file mode 100644 index 000000000..4fee2b646 --- /dev/null +++ b/gui/src/components/mainInput/handleMetaKeyPress.ts @@ -0,0 +1,110 @@ +import { KeyboardEvent } from "react"; +import { isWebEnvironment } from "../../util"; +import { Editor } from "@tiptap/react"; + +const isWebEnv = isWebEnvironment(); + +export const handleJetBrainsMetaKeyPress = ( + e: KeyboardEvent, + editor: Editor, +) => { + const selection = window.getSelection(); + + const handlers: Record void> = { + Backspace: () => handleJetBrainsMetaBackspace(editor), + ArrowLeft: () => + selection.modify( + e.shiftKey ? "extend" : "move", + "backward", + "lineboundary", + ), + ArrowRight: () => + selection.modify( + e.shiftKey ? "extend" : "move", + "forward", + "lineboundary", + ), + ArrowDown: () => + selection.modify( + e.shiftKey ? "extend" : "move", + "forward", + "documentboundary", + ), + ArrowUp: () => { + selection.modify( + e.shiftKey ? "extend" : "move", + "backward", + "documentboundary", + ); + }, + }; + + if (e.key in handlers) { + e.stopPropagation(); + e.preventDefault(); + handlers[e.key](); + } +}; + +export const handleMetaKeyPress = async (e: KeyboardEvent, editor: Editor) => { + const text = editor.state.doc.textBetween( + editor.state.selection.from, + editor.state.selection.to, + ); + + const handlers: Record Promise> = { + x: () => handleCutOperation(text, editor), + c: () => handleCopyOperation(text), + v: () => handlePasteOperation(editor), + }; + + if (e.key in handlers) { + e.stopPropagation(); + e.preventDefault(); + await handlers[e.key](); + } +}; + +export const handleJetBrainsMetaBackspace = (editor: Editor) => { + const { doc } = editor.state; + + for (let i = doc.content.childCount - 1; i >= 0; i--) { + const node = doc.content.child(i); + + if (node.type.name !== "codeBlock") { + editor.commands.deleteNode(node.type.name); + } + } + + // Add an empty string so the user can keep typing + editor.commands.createParagraphNear(); +}; + +export const handleCutOperation = async (text: string, editor: Editor) => { + const selection = window.getSelection(); + selection.deleteFromDocument(); + + if (isWebEnv) { + await navigator.clipboard.writeText(text); + editor.commands.deleteSelection(); + } else { + document.execCommand("cut"); + } +}; + +export const handleCopyOperation = async (text: string) => { + if (isWebEnv) { + await navigator.clipboard.writeText(text); + } else { + document.execCommand("copy"); + } +}; + +export const handlePasteOperation = async (editor: Editor) => { + if (isWebEnv) { + const clipboardText = await navigator.clipboard.readText(); + editor.commands.insertContent(clipboardText); + } else { + document.execCommand("paste"); + } +}; diff --git a/gui/src/util/handleMetaKeyPressJetBrains.ts b/gui/src/util/handleMetaKeyPressJetBrains.ts deleted file mode 100644 index 70740262c..000000000 --- a/gui/src/util/handleMetaKeyPressJetBrains.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { KeyboardEvent } from "react"; -import { getPlatform } from "."; - -export const handleMetaKeyPressJetBrains = ( - e: KeyboardEvent, - text: string, - setText: (text: string) => void, -) => { - const { selectionStart, selectionEnd } = e.target as HTMLTextAreaElement; - - if (e.key === "Backspace") { - handleMetaBackspace(e, text, setText, selectionStart, selectionEnd); - } - - if (getPlatform() === "mac") { - if (e.key === "ArrowLeft") { - handleMacArrowLeftKey(e); - } else if (e.key === "ArrowRight") { - handleMacArrowRightKey(e); - } - } -}; - -const handleMetaBackspace = ( - e: KeyboardEvent, - text: string, - setText: (text: string) => void, - start: number, - end: number, -) => { - const target = e.target as HTMLTextAreaElement; - let newStart = start; - - if (start !== end) { - setText(text.slice(0, start) + text.slice(end)); - } else { - newStart = - getPlatform() === "mac" - ? text.lastIndexOf("\n", start - 1) + 1 - : text.slice(0, start).trimEnd().lastIndexOf(" ") + 1; - setText(text.slice(0, newStart) + text.slice(start)); - } - - target.setSelectionRange(newStart, newStart); -}; - -const handleMacArrowLeftKey = (e: KeyboardEvent) => { - const target = e.target as HTMLDivElement; - const selection = window.getSelection(); - - const range = document.createRange(); - - if (e.shiftKey) { - selection.modify("extend", "backward", "character"); - } else { - range.setStart(target.firstChild, 0); - range.setEnd(target.firstChild, 0); - - selection.removeAllRanges(); - selection.addRange(range); - } -}; - -const handleMacArrowRightKey = (e: KeyboardEvent) => { - const selection = window.getSelection(); - const range = document.createRange(); - const target = e.target as HTMLDivElement; - - if (e.shiftKey) { - selection.modify("extend", "forward", "character"); - } else { - range.selectNodeContents(target); - range.collapse(false); - selection.removeAllRanges(); - selection.addRange(range); - } -};