microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
39.18k stars 3.52k forks source link

[Bug] Problem using Monaco 'wordWrapColumn', editor scrolls outside of view #3587

Open jogibear9988 opened 1 year ago

jogibear9988 commented 1 year ago

Edit by @hediet See https://github.com/microsoft/monaco-editor/issues/3587#issuecomment-1441530602 for playground lik.


Reproducible in vscode.dev or in VS Code Desktop?

Reproducible in the monaco editor playground?

Additional info

I don't know if the cause is using it in a Webcomponent, or some other setting. Also it only is broken in Chrome (and derivates). It works in Safari and Firefox. I also don't know if it is a Monaco Error, a error of me or a Chrome Bug. Maybe someone can help where we need to look (for example who is responsible for this scrolling). I already also created a Chrome Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1416178

Reproduction Steps

Much more simple example is now below: https://github.com/microsoft/monaco-editor/issues/3587#issuecomment-1441530602

has nothing to do with webcomponents nor my designer. It's a problem when "wordWrapColumn" is set and the line is to long.

1.) Go to (the link is only so big, it contains the content of the designer): https://node-projects.github.io/web-component-designer-demo/index.html?html=%3Cdiv%20style=%22box-sizing:border-box;pointer-events:none;display:grid;position:relative;width:1500px;height:900px;background:rgb(255,%20255,%20255);%22%3E%20%3Cdiv%20style=%22box-sizing:border-box;pointer-events:none;display:inline-block;width:1500px;height:712px;position:relative;grid-area:1%20/%201%20/%20auto%20/%20auto;justify-self:stretch;align-self:stretch;margin:0px%200px%20188px%200px;%22%3E%20%3Cdiv%20style=%22box-sizing:border-box;pointer-events:none;display:inline-block;width:1408px;height:104px;position:absolute;left:50px;top:572px;%22%3E%20%3Cdiv%20style=%22box-sizing:border-box;pointer-events:none;display:inline-block;width:148px;height:417px;position:absolute;left:187px;top:-156.500015px;background:rgb(224,%2031,%2031);%22%3E%3C/div%3E%20%3C/div%3E%20%3C/div%3E%20%3C/div%3E 2.) Switch to Code 3.) Go to the End of Line 4 4.) Enterer some characters

See also this Video: https://watch.screencastify.com/v/tnSRGDiFCvSDwALTzio4

Actual (Problematic) Behavior

Editor is moved outside of the screen via Scroll Left

Expected Behavior

Editor should work as expected

Additional Context

No response

jogibear9988 commented 1 year ago

Hopefully someone can help me, to find the root of that problem. Maybe look at the chrome Bug, I already tried to change all the scroll methods, so the debugger is hit, but this did not happen.

hediet commented 1 year ago

I can verify the bug, but without a reproducible sample we cannot help you unfortunately.

Please try to recreate the bug in the monaco editor playground.

jogibear9988 commented 1 year ago

How should i recreate in Playground? Maybe it is related if the Monaco Editor is wrapped in a webcomponent?

hediet commented 1 year ago

You can also use web components in the playground, like this for example:

https://microsoft.github.io/monaco-editor/playground.html?source=v0.36.0-dev.20230221#XQAAAALkCgAAAAAAAABBqQkHQ5NjdzsN4D33cvEw80Z87XjZjkxLiv9MahPMRa66pPlEjWRsNcWveUYtoWGqjAGH3KnqY9fQHhosK9Ms-4aZwk3rSFi1ixBGJsFV4T4eGzHBpkBlNJxCnhg5BWDyOUxqYWTvDdJG9XehUGYLGfFUMa4S7WhMRsGWidxaWoCvththKlEF602t6uo2Uk14cN07J9quwbWXKTd42pUakn9B6dwxG5scFtqPohcmqJWYCuPIempmwL8JktFut04Sc2kP-NVIEk9hf3WgJiWhNerF0-ingTVz4fVpCuMRV01M6gItZEWDnqshI4vyOeW4bb-5mR_v35Ql49hbeiVei6C6WCmdgZa-sQ4WQRMlh3ZcYB0CeOUXcYa1cJ09JZWqfRX6_YWG0Gf5SmrGiM3dPVdJZTwBMB2qHpmWY3in4zMgo14M3eZCd--Ed_KQSyiM61lZxCC9-hAqtzgdO9I7b-kchQUkkoJE3x2N1dlYJSLQnxTKEerA2IdnhF-5gnyo2kO1acxOTQGPz9iLmQln7jKboCcO23Qc-eMEP3Ul3GpZ4jnsuCSbXwUpAvK2tF1lrPfNGUZS9WE3sjjQwiD2wL4mOA8olRyTQVuKBouReIVa8KWHaHqXI6Qcpj50lyDz1XBmPjZnXnVCKqzgkxsfgMwbj_61rj0WD7UnsXSpz6uslqMQf7eHniy3b9AD7t41IGT2XR3mK8kbodHV92gWNuoHId7lbq7iQyRU386BwuCyiPEjhSb6NZVsLr-Ka_P6MYSnGwVSzrdyiBSoMTQUpAaeEruij9_Ds7MUzTbIOa4F-ECKmTeIph7497Yj3hbp0y-OxbHfhU_L2bpYw_8MovzJgXJo5A5Bb4cGAig2wTAJGVtdf7QaOMB7Y2xo3c92lZnkNnaZzuxU_qhunqu9PDYvqZOFSstPgos1uSdXuVxy1z86b3FoG6viRHQ5AD3tQeH1z-2lE3l7bhx6IXeMTU9JOIDl74lzR7KOXnjBGBdNog4mP2nosrPeejwQwoi9Gs2Qh0Fg2vhhxI-c2y6Ji3g2wmjYl1R6eulLmLIH9Txmp1RkxFxYYtaWV8PF1SDAoqHZrPZZJLbhBHEy2gF7dhzroNFx9dSbISwoHDVfUpY0YSfWUqnfFNu0wVtojaiiv0xVjzD0I8pyL9iaUHyL-rd3UQTaXyN0hy1YgUjgIhK72nMDei9jfu6xQP1VM7-GmAskjjbgZPGeDZy3OIQmxYhEV3__9zw_tQ

jogibear9988 commented 1 year ago

@hediet got it reproduced in monaco playground:

only click in line 4 and it will scroll

https://microsoft.github.io/monaco-editor/playground.html?source=v0.36.0-dev.20230223#XQAAAALXDQAAAAAAAABBqQkHQ5NjdYX3AXhNewrSKZslyM_G2I4bTkHQYW1lB1MplP_B-iGH6S_hAKEQYDCGeVLBbiLOVOAth4exIuI9h-Ns6ao7jNlU0Gr79ecXwsA86mR8U2CnxDf7leW3ZDXDm-bjXCQtmMMIVymXIFkHrT0W3_FLpZ9ih6AeqOUh3Eco9f9AQGrtI9LmRPFtOGqs8kKRDKg0m6rLrfJYjacWmR-mt90zKJAfk-PeSUtHmuokep3BBJRm8HQDyAK1S56TqNTD8KFZBuM8XQOojSeFcGn4KAKFfuAu5fMb_DYwPiJkXjsH6gyitp9julM0nfXIlixAL8vhfjZQWflYEEwx3GkOcAEspWXtzqVXfP9z5UoEofg0xzaiyG5trX1BuzJygArVk1El8ocJ0vnztpJ2-KMMj1pVRUUJuHwd48ZZVKyMu3Y9bpmNV7R2tl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rqoGmSvlwB1G8H_A2gWlhYvFv2uTILQ4btftSLyC5kmFL8vKaDwWHzhm7v5zWXHs90jYCexLLcC3NV-EM_8lUt2vQVzM5Nqi46WWPLS9aOep9cvRBZGYD7eciG_tG-c0MV7pj_8kx2DWTM4bbvujuFxy1Wscx2tsDs7C2kbhOpw5goUFDq_KI3iTh-o_8IycJqg-az4H3VPZ8Jh4-XTAJF8eWjej6zDzEgYyyrdIX-c9t-

jogibear9988 commented 1 year ago

If I remove the " wordWrap: 'wordWrapColumn'," it does work

jogibear9988 commented 1 year ago

Simplified sample once more:

And it works if I remove the wordWrap: 'wordWrapColumn'," from monaco, but I still don't know if it is a monaco or chrome issue

This sample works in Firefox, but also not in Safari.

Click in Line 4 (this already does not work in Chrome) In safari you need to enter some characters in the end of line 4 to cause the issue

https://microsoft.github.io/monaco-editor/playground.html?source=v0.36.0-dev.20230223#XQAAAAKbBwAAAAAAAABBqQkHQ5NjdYX3AXhNewrSKZslyM_G2I4bTkHQYW1lB1MplP_B-iGH6S_hAKEQYDCGeVLBbiLOVOAth4exIuI9h-Ns6ao7jNlU0Gr79ecXwsA86mR8U2CnxDf7leW3ZDXDm-bjXCQtmMMIVymXIFkHrT0W3_FLpZ9ih6AeqOUh3Eco9f9AQGrtI9LmRPFtOGqs8jMxl-KTde0KkgLnu5nd_mDMR87RY4JZFkWqO0C8SQvYUQtSrv2cXFsvxAZwUzA3Y9SHmREjGC4ujGDDzoLFUTkfO31D4yMkPml-oc_Je1ZrcmIHTDHA3f-IKpNG3Wcwczy64dDZ4uNku7VK7C4MfnHa4WJsffes67jnn29HI5p6eUD0Ku8pBW7_8InHZJGM_a-rdH4SNMwQsaNG2ECTtAU2tJhr0QPhOCjKFlSvI1-B1EowZfaDrGDu0I8ePfOXfMDyVoCNEbTmTnsd5-yK3TDagpphixjYMeO6R0p2Y-HmTTXlHsr_R_h81LfYJ0bkmDifG2IR9xqJ7XWflN7848sbyxSN_teZWnbklVwqldvecgA1i5avEVWMf7xkahQOOZAufZLqkikkWdqPxiUpglWyV9iLt8mdssSnrulGkw0WpFkWSTpDilkYG0S7wm3LSL-Vs6cmfisYMKy1gUD5Iuvwm7YjgU3oNDKQg8JYMs-KzQ_aAzf9enUPhvx6GocupjyByM0hhnNfUXHLS87PhYdAr2D7WQdI3xyVbSnJpY0Yj8U0ycECAzOe489lR1vzeL70LKZNKE8eI70rYY3i3zpUF-3xp6KRj1kZ5aTEp1Hr5xStRdqDYZGPcqqB1SSu-pzHy8xfLJ33Gjb81NkmV50c74ezMVDdjAPJc2eTyC4KMUzyY7fuBmjGA2AezzGryQYVMx_s75qzyYht7ZhrzAasPEcpftu_loplhp4ZdXWx9Ckydudl4JktcWG9D-tj9NFVSe0DZi_ijj9U1x2QDeTCuJ8KgFtVoGZNOYvg4qhNPzJcDFa4hHQJaBwRwMngU6fvAUUxEY0hRyTFUPL7WYm8sHIPRqZh0Jh3xTM4XpUfnjRw-fnvZjBfuMN22K5SkTWFT4x3rX90j0WvuGlCq_sMBpg

jogibear9988 commented 1 year ago

Has nothing to do with webcomponents, also breaks in this sample:

You only need to klick into the created monaco editor. With Safari it only breaks if you enter some characters at the end of line 4. With Firefox it works.

https://microsoft.github.io/monaco-editor/playground.html?source=v0.36.0-dev.20230223#XQAAAALSAwAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw407USTLdlLqG8408kR6oz8Ayz-6RxBOlazrLF2usiAGPdsdtEEquciiMk1G5Sd0Fc9zUGvG3J5NFhRgKjsIl53PAN3XaYUe0o3P5x6lyLTEji-4ejFqzHWKy30Rk9LEkx9XrccrfkriFj298Luidab5sF_MvuL1LpMVAhAEoj7rVQWisneuszB7rvgkX5pHUCj-qVpjfDlFsl9065e-dChGRX07tpawKcX4jfHbQPZd5dw_-W0EnWw6Peye302JfU_IWUjgdJgq4rK9CE1IfvZZdkSmaP-v8GOCU22zxp5nu4DjkWIrnnnJ5jj5Q8iF66YFhNMzS5XGJiosgxfj1v5vG8vricNKexNC4DTq63m1UoITyVOFLDf4eKWKQmCkokzWFb3GD1ArHI00XJ1TP14CrWbQ6lbC0n9vk_sRwPFQIgy5KOS1c-5buz8kXlUH_cAZFVxIqqTWrM2kPGQVE6HQ4aIgPGxdtUIrdwo9WHd-mmvhlesYXh75qeyfBXf6OWIY

jogibear9988 commented 1 year ago

If you reset the "scrollLeft" of the element with class "overflow-guard", display is correct again

jogibear9988 commented 1 year ago

@hediet Is this enough now to reproduce the bug?

flackr commented 1 year ago

The bug seems to be the following focus call scrolling into view the current cursor location:

setSelectionRange(h, f, S) {
                const p = this.c;
                let m = null;
                const b = N.getShadowRoot(p);
                b ? m = b.activeElement : m = document.activeElement;
                const L = m === p
                  , k = p.selectionStart
                  , I = p.selectionEnd;
                if (L && k === f && I === S) {
                    w.isFirefox && window.parent !== window && p.focus();
                    return
                }
                if (L) {
                    this.setIgnoreSelectionChangeTime("setSelectionRange"),
                    p.setSelectionRange(f, S),
                    w.isFirefox && window.parent !== window && p.focus();
                    return
                }
                try {
                    const M = N.saveParentsScrollTop(p);
                    this.setIgnoreSelectionChangeTime("setSelectionRange"),
                    p.focus(),  // <--- This focus call scrolls the input caret into view
                    p.setSelectionRange(f, S),
                    N.restoreParentsScrollTop(p, M)
                } catch {}
            }

This seems to be because the textarea itself is extremely wide. I was able to fix the bug by applying width: 0 !important to the following textarea:

<textarea data-mprt="6" class="inputarea monaco-mouse-cursor-text" wrap="on" autocorrect="off" autocapitalize="off" autocomplete="off" spellcheck="false" aria-label="Editor content;Press Alt+F1 for Accessibility Options." tabindex="0" role="textbox" aria-roledescription="editor" aria-multiline="true" aria-haspopup="false" aria-autocomplete="both" style="tab-size: 28.9062px; font-family: Menlo, Monaco, &quot;Courier New&quot;, monospace; font-weight: normal; font-size: 12px; font-feature-settings: &quot;liga&quot; 0, &quot;calt&quot; 0; font-variation-settings: normal; line-height: 18px; letter-spacing: 0px; top: 0px; left: 0px; height: 1px; width: 0px !important;"></textarea>

After that, focusing the text area no longer requires scrolling to the right in order to scroll the text caret into view.

hediet commented 1 year ago

@flackr thanks for investigating! Why is this related to wrapping though?

flackr commented 1 year ago

@flackr thanks for investigating! Why is this related to wrapping though?

I'm not sure. I only looked at why chrome was scrolling the textarea in the context of determining whether the scroll was expected. If you make the textarea have a non-zero height maybe you'll be able to see why the wrapping option is changing the position of the focused cursor. It's still possible that there is a bug in the text layout or selection location especially since you're only seeing this issue in chrome.

jogibear9988 commented 1 year ago

as I mentioned here: https://github.com/microsoft/monaco-editor/issues/3587#issuecomment-1441530602 it also happens in safari (in a little bit different way)

flackr commented 1 year ago

Right so the browser difference seem to be resulting from different text wrapping in the height: 0