create 'useIsOSREnabled'
This commit is contained in:
parent
6f923244b8
commit
3da4234bd7
5 changed files with 33 additions and 30 deletions
|
|
@ -37,7 +37,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
insertAtCursor: [{ text: string }, void];
|
||||
copyText: [{ text: string }, void];
|
||||
"jetbrains/editorInsetHeight": [{ height: number }, void];
|
||||
"jetbrains/isOSREnabled": [boolean, void];
|
||||
"jetbrains/isOSREnabled": [undefined, void];
|
||||
"vscode/openMoveRightMarkdown": [undefined, void];
|
||||
setGitHubAuthToken: [{ token: string }, void];
|
||||
acceptDiff: [{ filepath: string }, void];
|
||||
|
|
@ -104,6 +104,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
setTheme: [{ theme: any }, void];
|
||||
setColors: [{ [key: string]: string }, void];
|
||||
"jetbrains/editorInsetRefresh": [undefined, void];
|
||||
"jetbrains/isOSREnabled": [boolean, void];
|
||||
addApiKey: [undefined, void];
|
||||
setupLocalConfig: [undefined, void];
|
||||
incrementFtc: [undefined, void];
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class ContinueBrowser(val project: Project, url: String) {
|
|||
}
|
||||
|
||||
"jetbrains/isOSREnabled" -> {
|
||||
respond(isOSREnabled)
|
||||
sendToWebview( "jetbrains/isOSREnabled", isOSREnabled)
|
||||
}
|
||||
|
||||
"onLoad" -> {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ import {
|
|||
handleVSCMetaKeyIssues,
|
||||
} from "./handleMetaKeyIssues";
|
||||
import { ComboBoxItem } from "./types";
|
||||
import useIsOSREnabled from "../../hooks/useIsOSREnabled";
|
||||
|
||||
const InputBoxDiv = styled.div<{ border?: string }>`
|
||||
resize: none;
|
||||
|
|
@ -181,6 +182,8 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
const inSubmenuRef = useRef<string | undefined>(undefined);
|
||||
const inDropdownRef = useRef(false);
|
||||
|
||||
const isOSREnabled = useIsOSREnabled();
|
||||
|
||||
const enterSubmenu = async (editor: Editor, providerId: string) => {
|
||||
const contents = editor.getText();
|
||||
const indexOfAt = contents.lastIndexOf("@");
|
||||
|
|
@ -555,9 +558,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
if (!editorFocusedRef?.current || !isMetaEquivalentKeyPressed(e)) return;
|
||||
|
||||
const isOSREnabled = isJetBrains()
|
||||
? await ideMessenger.request("jetbrains/isOSREnabled", undefined)
|
||||
: false;
|
||||
console.log({ isOSREnabled });
|
||||
|
||||
if (isOSREnabled) {
|
||||
handleJetBrainsOSRMetaKeyIssues(e, editor);
|
||||
|
|
|
|||
|
|
@ -6,41 +6,21 @@ const isWebEnv = isWebEnvironment();
|
|||
|
||||
/**
|
||||
* This handles various keypress issues when OSR is enabled
|
||||
* @param e
|
||||
* @param editor
|
||||
*/
|
||||
export const handleJetBrainsOSRMetaKeyIssues = (
|
||||
e: KeyboardEvent,
|
||||
editor: Editor,
|
||||
) => {
|
||||
const selection = window.getSelection();
|
||||
const alter = e.shiftKey ? "extend" : "move";
|
||||
|
||||
const handlers: Record<string, () => 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",
|
||||
),
|
||||
ArrowLeft: () => selection.modify(alter, "backward", "lineboundary"),
|
||||
ArrowRight: () => selection.modify(alter, "forward", "lineboundary"),
|
||||
ArrowDown: () => selection.modify(alter, "forward", "documentboundary"),
|
||||
ArrowUp: () => {
|
||||
selection.modify(
|
||||
e.shiftKey ? "extend" : "move",
|
||||
"backward",
|
||||
"documentboundary",
|
||||
);
|
||||
selection.modify(alter, "backward", "documentboundary");
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
21
gui/src/hooks/useIsOSREnabled.ts
Normal file
21
gui/src/hooks/useIsOSREnabled.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { useState, useEffect, useContext } from "react";
|
||||
import { isJetBrains } from "../util";
|
||||
import { useWebviewListener } from "./useWebviewListener";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
|
||||
export default function useIsOSREnabled() {
|
||||
const [isOSREnabled, setIsOSREnabled] = useState(false);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
useWebviewListener("jetbrains/isOSREnabled", async (isOSREnabled) => {
|
||||
setIsOSREnabled(isOSREnabled);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (isJetBrains()) {
|
||||
ideMessenger.request("jetbrains/isOSREnabled", undefined);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return isOSREnabled;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue