Skip to content

Commit 40bc099

Browse files
Merge pull request #2936 from continuedev/pe/jb-osr-bugfixes
bugfix: OSR copy/paste bugs
2 parents f534820 + 87cfdce commit 40bc099

File tree

6 files changed

+56
-44
lines changed

6 files changed

+56
-44
lines changed

core/protocol/ideWebview.ts

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
3737
insertAtCursor: [{ text: string }, void];
3838
copyText: [{ text: string }, void];
3939
"jetbrains/editorInsetHeight": [{ height: number }, void];
40+
"jetbrains/isOSREnabled": [undefined, void];
4041
"vscode/openMoveRightMarkdown": [undefined, void];
4142
setGitHubAuthToken: [{ token: string }, void];
4243
acceptDiff: [{ filepath: string }, void];
@@ -103,6 +104,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
103104
setTheme: [{ theme: any }, void];
104105
setColors: [{ [key: string]: string }, void];
105106
"jetbrains/editorInsetRefresh": [undefined, void];
107+
"jetbrains/isOSREnabled": [boolean, void];
106108
addApiKey: [undefined, void];
107109
setupLocalConfig: [undefined, void];
108110
incrementFtc: [undefined, void];

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/ToolTipComponent.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class ToolTipComponent(editor: Editor, x: Int, y: Int) :
8888
val componentHorizontalPadding = 4
8989
val buttonMargin = 4
9090

91-
addToChatButton = StyledButton("Chat (${cmdCtrlChar}J)")
92-
editButton = StyledButton("Edit (${cmdCtrlChar}I)")
91+
addToChatButton = StyledButton("Chat (${cmdCtrlChar}+J)")
92+
editButton = StyledButton("Edit (${cmdCtrlChar}+I)")
9393

9494
addToChatButton.addActionListener { e: ActionEvent? ->
9595
focusContinueInput(editor.project)

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import kotlinx.coroutines.*
1818
import org.cef.CefApp
1919
import org.cef.browser.CefBrowser
2020
import org.cef.handler.CefLoadHandlerAdapter
21-
import com.intellij.openapi.application.ApplicationInfo
22-
import com.intellij.openapi.util.SystemInfo
2321

2422
class ContinueBrowser(val project: Project, url: String) {
2523
private val coroutineScope = CoroutineScope(
@@ -79,8 +77,8 @@ class ContinueBrowser(val project: Project, url: String) {
7977
val browser: JBCefBrowser
8078

8179
init {
82-
val enableOSR = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR
83-
this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(enableOSR).build()
80+
val isOSREnabled = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR
81+
this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(isOSREnabled).build()
8482

8583

8684
browser.jbCefClient.setProperty(
@@ -136,6 +134,10 @@ class ContinueBrowser(val project: Project, url: String) {
136134
heightChangeListeners.forEach { it(height) }
137135
}
138136

137+
"jetbrains/isOSREnabled" -> {
138+
sendToWebview( "jetbrains/isOSREnabled", isOSREnabled)
139+
}
140+
139141
"onLoad" -> {
140142
coroutineScope.launch {
141143
// Set the colors to match Intellij theme

gui/src/components/mainInput/TipTapEditor.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ import {
6060
getSlashCommandDropdownOptions,
6161
} from "./getSuggestion";
6262
import {
63-
handleJetBrainsMetaKeyPress,
64-
handleMetaKeyPress,
65-
} from "./handleMetaKeyPress";
63+
handleJetBrainsOSRMetaKeyIssues,
64+
handleVSCMetaKeyIssues,
65+
} from "./handleMetaKeyIssues";
6666
import { ComboBoxItem } from "./types";
67+
import useIsOSREnabled from "../../hooks/useIsOSREnabled";
6768

6869
const InputBoxDiv = styled.div<{ border?: string }>`
6970
resize: none;
@@ -181,6 +182,8 @@ function TipTapEditor(props: TipTapEditorProps) {
181182
const inSubmenuRef = useRef<string | undefined>(undefined);
182183
const inDropdownRef = useRef(false);
183184

185+
const isOSREnabled = useIsOSREnabled();
186+
184187
const enterSubmenu = async (editor: Editor, providerId: string) => {
185188
const contents = editor.getText();
186189
const indexOfAt = contents.lastIndexOf("@");
@@ -551,17 +554,14 @@ function TipTapEditor(props: TipTapEditorProps) {
551554
* with those key actions.
552555
*/
553556
const handleKeyDown = async (e: KeyboardEvent<HTMLDivElement>) => {
554-
if (!editorFocusedRef?.current) return;
555-
556557
setActiveKey(e.key);
557558

558-
// Handle meta key issues
559-
if (isMetaEquivalentKeyPressed(e)) {
560-
if (isJetBrains()) {
561-
handleJetBrainsMetaKeyPress(e, editor);
562-
}
559+
if (!editorFocusedRef?.current || !isMetaEquivalentKeyPressed(e)) return;
563560

564-
await handleMetaKeyPress(e, editor);
561+
if (isOSREnabled) {
562+
handleJetBrainsOSRMetaKeyIssues(e, editor);
563+
} else {
564+
await handleVSCMetaKeyIssues(e, editor);
565565
}
566566
};
567567

gui/src/components/mainInput/handleMetaKeyPress.ts gui/src/components/mainInput/handleMetaKeyIssues.ts

+14-27
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,23 @@ import { isWebEnvironment } from "../../util";
44

55
const isWebEnv = isWebEnvironment();
66

7-
export const handleJetBrainsMetaKeyPress = (
7+
/**
8+
* This handles various keypress issues when OSR is enabled
9+
*/
10+
export const handleJetBrainsOSRMetaKeyIssues = (
811
e: KeyboardEvent,
912
editor: Editor,
1013
) => {
1114
const selection = window.getSelection();
15+
const alter = e.shiftKey ? "extend" : "move";
1216

1317
const handlers: Record<string, () => void> = {
1418
Backspace: () => handleJetBrainsMetaBackspace(editor),
15-
ArrowLeft: () =>
16-
selection.modify(
17-
e.shiftKey ? "extend" : "move",
18-
"backward",
19-
"lineboundary",
20-
),
21-
ArrowRight: () =>
22-
selection.modify(
23-
e.shiftKey ? "extend" : "move",
24-
"forward",
25-
"lineboundary",
26-
),
27-
ArrowDown: () =>
28-
selection.modify(
29-
e.shiftKey ? "extend" : "move",
30-
"forward",
31-
"documentboundary",
32-
),
19+
ArrowLeft: () => selection.modify(alter, "backward", "lineboundary"),
20+
ArrowRight: () => selection.modify(alter, "forward", "lineboundary"),
21+
ArrowDown: () => selection.modify(alter, "forward", "documentboundary"),
3322
ArrowUp: () => {
34-
selection.modify(
35-
e.shiftKey ? "extend" : "move",
36-
"backward",
37-
"documentboundary",
38-
);
23+
selection.modify(alter, "backward", "documentboundary");
3924
},
4025
};
4126

@@ -47,10 +32,12 @@ export const handleJetBrainsMetaKeyPress = (
4732
};
4833

4934
/**
50-
* We use this for VS Code to fix an .ipynb bug
51-
* And we use it in JetBrains when OSR is turned on
35+
* This handles reported issues with cut/copy/paste in .ipynb files in VSC
5236
*/
53-
export const handleMetaKeyPress = async (e: KeyboardEvent, editor: Editor) => {
37+
export const handleVSCMetaKeyIssues = async (
38+
e: KeyboardEvent,
39+
editor: Editor,
40+
) => {
5441
const text = editor.state.doc.textBetween(
5542
editor.state.selection.from,
5643
editor.state.selection.to,

gui/src/hooks/useIsOSREnabled.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useState, useEffect, useContext } from "react";
2+
import { isJetBrains } from "../util";
3+
import { useWebviewListener } from "./useWebviewListener";
4+
import { IdeMessengerContext } from "../context/IdeMessenger";
5+
6+
export default function useIsOSREnabled() {
7+
const [isOSREnabled, setIsOSREnabled] = useState(false);
8+
const ideMessenger = useContext(IdeMessengerContext);
9+
10+
useWebviewListener("jetbrains/isOSREnabled", async (isOSREnabled) => {
11+
setIsOSREnabled(isOSREnabled);
12+
});
13+
14+
useEffect(() => {
15+
if (isJetBrains()) {
16+
ideMessenger.request("jetbrains/isOSREnabled", undefined);
17+
}
18+
}, []);
19+
20+
return isOSREnabled;
21+
}

0 commit comments

Comments
 (0)