Skip to content

Commit

Permalink
feat: support language sync in iframe editor (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
HashCookie authored Dec 15, 2024
1 parent b84d05b commit 0840e42
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/components/ModelEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ModelEditor = () => {
const editorRef = useRef<EditorView | null>(null);
const cursorPosRef = useRef<{ from: number; to: number } | null>(null);
const sidePanelChatRef = useRef<{ openDrawer: (message: string) => void } | null>(null);
const { t, lang, theme } = useLang();
const { t, lang, theme, setLang } = useLang();
const textClass = clsx(theme === 'dark' ? 'text-gray-200' : 'text-gray-800');

const openDrawerWithMessage = (message: string) => {
Expand Down Expand Up @@ -55,6 +55,9 @@ export const ModelEditor = () => {
if (event.data.modelText) {
setModelText(event.data.modelText);
}
if (event.data.language) {
setLang(event.data.language);
}
} else if (event.data.type === 'getModelText') {
window.parent.postMessage({
type: 'modelUpdate',
Expand All @@ -64,8 +67,12 @@ export const ModelEditor = () => {
if (event.data.modelText) {
setModelText(event.data.modelText);
}
} else if (event.data.type === 'updateLanguage') {
if (event.data.language) {
setLang(event.data.language);
}
}
}, [modelText]);
}, [modelText, setLang]);

useEffect(() => {
window.addEventListener('message', handleMessage);
Expand Down

0 comments on commit 0840e42

Please sign in to comment.