suren-atoyan / monaco-react

Monaco Editor for React - use the monaco-editor in any React application without needing to use webpack (or rollup/parcel/etc) configuration files / plugins

Home Page:https://monaco-react.surenatoyan.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When clicking inside the editor, the selected text is offset from the actual cursor position.

deineryao opened this issue · comments

This is a page with nested iframes, and the Monaco Editor is embedded within one of the iframes. When clicking at position A inside the editor, the cursor actually moves to position B, and the corresponding text at position B is also highlighted. Based on my deduction, the offset distance is exactly equal to the size of the page occupied by the external elements outside the iframe. When I remove elements outside the iframe, such as elements on the left and top, and then click inside the editor, the focus is normal.

The version of @monaco-editor/react is ^3.8.3.

企业微信截图_0ce42ddb-9a99-4d7a-bd98-2ea7b46eefc9

@deineryao could you please try to update to the latest version?

@deineryao could you please try to update to the latest version?

I have tried, but the project is quite old and contains various dependencies. Upgrading it would introduce various issues that render the project unusable. Is there any other alternative solution available?

try to use loader-config to load a different version of monaco-editor. Like:

import { loader } from '@monaco-editor/react';

loader.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.41.0/min/vs' } }); // try different versions

The issue seems to be related to microsoft/monaco-editor.

I had the same question in my programme. And I solved this by updating the version of monaco-editor like this:

import { loader } from '@monaco-editor/react';

loader.config({
  'vs/nls': {
    availableLanguages: {
      '*': 'zh-cn',
    },
  },
  paths: {
    vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs',
  },
});

Maybe this would help.