From 50bd31919a012b5f39e3f6a8ee1e23b98fc40267 Mon Sep 17 00:00:00 2001 From: Test Date: Tue, 5 Nov 2024 20:45:39 -0800 Subject: [PATCH 1/2] disable OSR for non-mac --- .../ContinueExtensionSettingsService.kt | 7 + gui/src/components/mainInput/TipTapEditor.tsx | 137 ++++++++---------- .../mainInput/handleMetaKeyPress.ts | 8 +- 3 files changed, 72 insertions(+), 80 deletions(-) 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 a8019e361..5db34ff29 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 @@ -7,6 +7,7 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.* import com.intellij.openapi.options.Configurable import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.util.SystemInfo import com.intellij.util.concurrency.AppExecutorUtil import com.intellij.util.messages.Topic import kotlinx.serialization.Serializable @@ -270,6 +271,12 @@ class ContinueExtensionConfigurable : Configurable { * 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 diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index bf6530dcf..8d0fd7a32 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -574,6 +574,7 @@ function TipTapEditor(props: TipTapEditorProps) { setActiveKey(e.key); + // Allow users to use the escape key to jump back to the editor if (e.key === "Escape") { e.stopPropagation(); e.preventDefault(); @@ -581,26 +582,14 @@ function TipTapEditor(props: TipTapEditorProps) { return; } - if (!isMetaEquivalentKeyPressed(e)) { - return; - } - - if (isJetBrains()) { - if (e.code === "KeyJ") { - setTemporaryIgnoreHighlightedCode(); - } else { + // Handle meta key issues + if (isMetaEquivalentKeyPressed(e)) { + if (isJetBrains()) { handleJetBrainsMetaKeyPress(e, editor); } + + await handleMetaKeyPress(e, editor); } - - await handleMetaKeyPress(e, editor); - }; - - const setTemporaryIgnoreHighlightedCode = () => { - setIgnoreHighlightedCode(true); - setTimeout(() => { - setIgnoreHighlightedCode(false); - }, 100); }; const handleKeyUp = () => { @@ -630,9 +619,6 @@ function TipTapEditor(props: TipTapEditorProps) { [props.onEnter, editor, props.isMainInput], ); - // This is a mechanism for overriding the IDE keyboard shortcut when inside of the webview - const [ignoreHighlightedCode, setIgnoreHighlightedCode] = useState(false); - // Re-focus main input after done generating useEffect(() => { if (editor && !active && props.isMainInput && document.hasFocus()) { @@ -707,71 +693,68 @@ function TipTapEditor(props: TipTapEditorProps) { if (!props.isMainInput || !editor) { return; } - if (!ignoreHighlightedCode) { - const rif: RangeInFile & { contents: string } = - data.rangeInFileWithContents; - const basename = getBasename(rif.filepath); - const relativePath = getRelativePath( - rif.filepath, - await ideMessenger.ide.getWorkspaceDirs(), - ); - const rangeStr = `(${rif.range.start.line + 1}-${ - rif.range.end.line + 1 - })`; - const item: ContextItemWithId = { - content: rif.contents, - name: `${basename} ${rangeStr}`, - // Description is passed on to the LLM to give more context on file path - description: `${relativePath} ${rangeStr}`, - id: { - providerTitle: "code", - itemId: v4(), - }, - uri: { - type: "file", - value: rif.filepath, - }, - }; - let index = 0; - for (const el of editor.getJSON().content) { - if (el.type === "codeBlock") { - index += 2; - } else { - break; - } + const rif: RangeInFile & { contents: string } = + data.rangeInFileWithContents; + const basename = getBasename(rif.filepath); + const relativePath = getRelativePath( + rif.filepath, + await ideMessenger.ide.getWorkspaceDirs(), + ); + const rangeStr = `(${rif.range.start.line + 1}-${ + rif.range.end.line + 1 + })`; + const item: ContextItemWithId = { + content: rif.contents, + name: `${basename} ${rangeStr}`, + // Description is passed on to the LLM to give more context on file path + description: `${relativePath} ${rangeStr}`, + id: { + providerTitle: "code", + itemId: v4(), + }, + uri: { + type: "file", + value: rif.filepath, + }, + }; + + let index = 0; + for (const el of editor.getJSON().content) { + if (el.type === "codeBlock") { + index += 2; + } else { + break; } - editor - .chain() - .insertContentAt(index, { - type: "codeBlock", - attrs: { - item, - }, - }) - .run(); - - if (data.prompt) { - editor.commands.focus("end"); - editor.commands.insertContent(data.prompt); - } - - if (data.shouldRun) { - onEnterRef.current({ useCodebase: false, noContext: true }); - } - - setTimeout(() => { - editor.commands.blur(); - editor.commands.focus("end"); - }, 20); } - setIgnoreHighlightedCode(false); + editor + .chain() + .insertContentAt(index, { + type: "codeBlock", + attrs: { + item, + }, + }) + .run(); + + if (data.prompt) { + editor.commands.focus("end"); + editor.commands.insertContent(data.prompt); + } + + if (data.shouldRun) { + onEnterRef.current({ useCodebase: false, noContext: true }); + } + + setTimeout(() => { + editor.commands.blur(); + editor.commands.focus("end"); + }, 20); }, [ editor, props.isMainInput, historyLength, - ignoreHighlightedCode, props.isMainInput, onEnterRef.current, ], diff --git a/gui/src/components/mainInput/handleMetaKeyPress.ts b/gui/src/components/mainInput/handleMetaKeyPress.ts index 4fee2b646..3ceb4f773 100644 --- a/gui/src/components/mainInput/handleMetaKeyPress.ts +++ b/gui/src/components/mainInput/handleMetaKeyPress.ts @@ -46,6 +46,11 @@ export const handleJetBrainsMetaKeyPress = ( } }; +// Note that this currently doesn't seem to be working because the key of the events +// are not being registered. For example, when pressing the meta key followed by +// a period, both keys are registered, by pressing meta followed by "x", "c", or "v" +// are not registering. Until this is resolved we can't enable OSR for non +// Mac users. export const handleMetaKeyPress = async (e: KeyboardEvent, editor: Editor) => { const text = editor.state.doc.textBetween( editor.state.selection.from, @@ -81,9 +86,6 @@ export const handleJetBrainsMetaBackspace = (editor: Editor) => { }; export const handleCutOperation = async (text: string, editor: Editor) => { - const selection = window.getSelection(); - selection.deleteFromDocument(); - if (isWebEnv) { await navigator.clipboard.writeText(text); editor.commands.deleteSelection(); From 2b2ca4c782f22af8c5f0a92c3e49565be0493ba6 Mon Sep 17 00:00:00 2001 From: Test Date: Tue, 5 Nov 2024 20:55:13 -0800 Subject: [PATCH 2/2] update comments on OSR --- gui/src/components/mainInput/TipTapEditor.tsx | 5 +++++ gui/src/components/mainInput/handleMetaKeyPress.ts | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 8d0fd7a32..2ef4db920 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -568,6 +568,11 @@ function TipTapEditor(props: TipTapEditorProps) { * 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 + * + * Currently keydown events for a number of keys are not registering if the + * meta/shift key is pressed, for example "x", "c", "v", "z", etc. + * Until this is resolved we can't turn on OSR for non-Mac users due to issues + * with those key actions. */ const handleKeyDown = async (e: KeyboardEvent) => { if (!editor || !editorFocusedRef.current) return; diff --git a/gui/src/components/mainInput/handleMetaKeyPress.ts b/gui/src/components/mainInput/handleMetaKeyPress.ts index 3ceb4f773..fd122350f 100644 --- a/gui/src/components/mainInput/handleMetaKeyPress.ts +++ b/gui/src/components/mainInput/handleMetaKeyPress.ts @@ -46,11 +46,6 @@ export const handleJetBrainsMetaKeyPress = ( } }; -// Note that this currently doesn't seem to be working because the key of the events -// are not being registered. For example, when pressing the meta key followed by -// a period, both keys are registered, by pressing meta followed by "x", "c", or "v" -// are not registering. Until this is resolved we can't enable OSR for non -// Mac users. export const handleMetaKeyPress = async (e: KeyboardEvent, editor: Editor) => { const text = editor.state.doc.textBetween( editor.state.selection.from,