You are reading a single comment by @neshanjo and its replies. Click here to read the full conversation.
  •   function formatCode() {
        var code = Espruino.Core.EditorJavaScript.getCode()­;
        var cursor = Espruino.Core.EditorJavaScript.getCodeMi­rror().getCursor();
        code = prettier.format(code, {
          parser: "babel",
          plugins: prettierPlugins,
          tabWidth: parseInt(Espruino.Config.TAB_SIZE),
          useTabs: Espruino.Config.INDENTATION_TYPE == "tabs",
          semi: true,
          singleQuote: true
        });
        Espruino.Core.EditorJavaScript.setCode(c­ode);
        Espruino.Core.EditorJavaScript.getCodeMi­rror().setCursor(cursor);
      }
    

    get/setCursor principally seems to do the trick, however, it changes the scrolling position. The line with the cursor becomes the last line in the editor window. You can try this by e.g. using large app code like https://github.com/espruino/BangleApps/b­lob/master/apps/trex/trex.js
    Any ideas how to fix this?

About

Avatar for neshanjo @neshanjo started