Skip to content
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

[Bug] ExecuteEdits inserts code into folded/collapsed area making it invisible when appending at the end of editor #4819

Open
1 of 2 tasks
ladariha opened this issue Jan 28, 2025 · 0 comments

Comments

@ladariha
Copy link

ladariha commented Jan 28, 2025

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

Editor link: Monaco Playground

Monaco Editor Playground Code

const value = /* set from `myEditor.getModel()`: */ `for(let x = 0; x < 5; x++){
	const demo = () => {
	for(let x = 0; x < 5; x++){
	const demo = () => {
	const obj = {
	}	
	}
}
	}}`;

// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
	value,
	language: "javascript",
	automaticLayout: true,
});

setTimeout(() => {
	const editor = myEditor;
	const editorModel = editor.getModel();
 const lineCount = editorModel.getLineCount();

   const range = new monaco.Range(lineCount + 1, 0, lineCount + 1, 0);

      editor.executeEdits("", [
        {
          range,
          text: `${"\n"}      if (hideEditorLoadingMessage) {
        dispatch(EditorLoadingMessageActionsEnum.SET_MESSAGE, undefined);
      }`,
          forceMoveMarkers: true,
        },
      ]);
    // const selectionRange = new monaco.Range(0, 0, ((editor.getModel()?.getValue() || "").split("\n").length) + 1, 0)
    //   editor.setSelection(selectionRange);
    //   editor.revealLine(editorModel.getLineCount());
    //   editor.focus();
window.alert("Done")
}, 5000)

Reproduction Steps

  1. To reproduce, please use the code set the "JavaScript" part of the playground as provided above
  2. Insert following snippet into the editor instance (right section) - please ignore the "no sense" kind of code :)
for(let x = 0; x < 5; x++){
	const demo = () => {
	for(let x = 0; x < 5; x++){
	const demo = () => {
	const obj = {
	}	
	}
}
	}}
  1. Collapse / fold the 2nd area at line 8 (BEFORE 5s when setTimeout kicks in, before you see modal window) - see attached screenshot for how it should look after this step 3

Image

  1. Let the controlling JS code do the operation declared in setTimeout:
setTimeout(() => {
	const editor = myEditor;
	const editorModel = editor.getModel();
        const lineCount = editorModel.getLineCount();
        const range = new monaco.Range(lineCount + 1, 0, lineCount + 1, 0);

      editor.executeEdits("", [
        {
          range,
          text: `${"\n"}      if (hideEditorLoadingMessage) {
        dispatch(EditorLoadingMessageActionsEnum.SET_MESSAGE, undefined);
      }`,
          forceMoveMarkers: true,
        },
      ]);

window.alert("Done")
}, 5000)

Actual (Problematic) Behavior

As seen from the controlling JS code, I'm appending new line and then some JS code. But because the last folding area is collapsed BEFORE this execution, the appended code is invisible - it is part of the collapsed area and there is no indication to user that something was inserted into the editor. So the editor looks like if nothing has changed.

If I expand the collapsed section, the appended code is visible

Expected Behavior

Newly appended code should be visible even if it is appended after collapsed section

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant