-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Focus is not reset after a model change #194
Comments
Most likely happening because we destroy and recreate the view when a model changes, so the dom node that holds focus gets detached from the DOM and a new You can workaround on your side by restoring focus via |
@alexandrudima yes, i do exactly that, but there is one undesirable effect: if one has already started typing before |
@akosyakov Can you explain in greater detail the order of things, or the shape of your code, how could one start typing before function setModelMaintainFocus(editor, model) {
let isFocused = editor.isFocused();
editor.setModel(model);
if (isFocused) {
editor.focus();
}
} |
@alexandrudima I see, you are right. We create a model just to change an URI and expect that the state of an editor will be preserved, e.g. focus and position of the cursor. But it happens that the cursor is moved to the beginning of an editor after a model change. We could also store a cursor offset and reset it after, similar to focus. |
Yes, the view state is reset when changing models (e.g. cursor position, scroll position, folding state, etc.) because we can't assume that we get 100% the same text as it appears to be in your case. I suggest using |
@alexandrudima will it help with focus either, or we still have to apply the workaround? |
The focus preserving is a valid bug.
The view state gets reset with each |
got it, thx |
Steps to reproduce:
the editor should be focused after a change but it is not
The text was updated successfully, but these errors were encountered: