Merge pull request #2820 from continuedev/pe/jb-osr-bugfixes

fix(jb): disable OSR for non-mac users
This commit is contained in:
Patrick Erichsen 2024-11-05 20:56:00 -08:00 • committed by GitHub
commit d1431252d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 72 additions and 80 deletions

View file

@ -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

View file

@ -568,12 +568,18 @@ 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<HTMLDivElement>) => {
if (!editor || !editorFocusedRef.current) return;
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 +587,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 +624,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 +698,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,
],

View file

@ -81,9 +81,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();