Action

toggle editor modes

Posted by @FlohGro, Last update 6 months ago

Toggle the following modes of the Editor With a prompt:
“focus”,“link”,“focus & link”, “arrange”

Steps

  • script

    // toggle modes 
    
    let isFocusEnabled = () => {
      if (editor.focusModeEnabled == true) {
        return true;
      } else {
        return false;
      }
    }
    
    let isLinkEnabled = () => {
      if (editor.linkModeEnabled == true) {
        return true;
      } else {
        return false;
      }
    }
    
    let isTypewriterEnabled = () => {
      if (editor.typewriterScrollingEnabled == true) {
        return true;
      } else {
        return false;
      }
    }
    
    
    let enableFocusMode = () => {
      editor.focusModeEnabled = true;
    }
    
    let disableFocusMode = () => {
      editor.focusModeEnabled = false;
    }
    
    let enableLinkMode = () => {
      editor.linkModeEnabled = true;
    }
    
    let disableLinkMode = () => {
      editor.linkModeEnabled = false;
    }
    
    let enableTypewriterMode = () => {
      editor.typewriterScrollingEnabled = true;
    }
    
    let disableTypewriterMode = () => {
      editor.typewriterScrollingEnabled = false;
    }
    
    let arrangeDraft = () => {
      draft.content = editor.arrange(draft.content);
      draft.update();
    
    }
    
    
    
    var modes2toggle = [];
    
    if (isLinkEnabled() == true) {
      modes2toggle.push("link off");
    } else {
      modes2toggle.push("link on");
      modes2toggle.push("arrange");
    }
    
    if (isFocusEnabled() == true) {
      modes2toggle.push("focus off");
    } else {
      modes2toggle.push("focus on");
    }
    
    if (isTypewriterEnabled() == true) {
      modes2toggle.push("typewriter off");
    } else {
      modes2toggle.push("typewriter on");
    }
    
    if (isLinkEnabled() == true && isFocusEnabled() == true) {
      modes2toggle.push("focus & link off");
    }
    
    if (isLinkEnabled() == false && isFocusEnabled() == false) {
      modes2toggle.push("focus & link on");
    }
    
    if (isTypewriterEnabled() == true && isFocusEnabled() == true) {
      modes2toggle.push("typewriter & focus off");
    }
    
    if (isTypewriterEnabled() == false && isFocusEnabled() == false) {
      modes2toggle.push("typewriter & focus on");
    }
    
    
    
    
    //  if (isLinkEnabled() == false && isFocusEnabled() == true) {
    //   modes2toggle.push("focus off");
    //   modes2toggle.push("link on");
    //   modes2toggle.push("arrange");
    //   modes2toggle.push("typewriter");
    //  }
    
    //  if (isLinkEnabled() == true && isFocusEnabled() == false) {
    //   modes2toggle.push("link off");
    //   modes2toggle.push("focus on");
    //  }
    
    //  if (isLinkEnabled() == false && isFocusEnabled() == false) {
    //   modes2toggle.push("focus & link on");
    //   modes2toggle.push("focus on");
    //   modes2toggle.push("link on");
    //   modes2toggle.push("arrange");
    //   modes2toggle.push("typewriter");
    //  }
    
    
    var p = Prompt.create();
    
    modes2toggle.sort();
    
    for (i in modes2toggle) {
      p.addButton(modes2toggle[i]);
    }
    
    p.title = "switch modes";
    p.title = "select modes to switch";
    
    var didSelect = p.show();
    if (didSelect == true) {
      var sel = p.buttonPressed;
    
      switch (sel) {
        case "focus on":
          enableFocusMode();
          break;
        case "focus off":
          disableFocusMode();
          break;
        case "link on":
          enableLinkMode();
          break;
        case "link off":
          disableLinkMode();
          break;
        case "typewriter on":
          enableTypewriterMode();
          break;
        case "typewriter off":
          disableTypewriterMode();
          break;
        case "arrange":
          arrangeDraft();
          break;
        case "typewriter & focus on":
          enableFocusMode();
          enableTypewriterMode();
          break;
        case "typewriter & focus off":
          disableFocusMode();
          disableTypewriterMode();
          break;
        case "focus & link on":
          enableFocusMode();
          enableLinkMode();
          break;
        case "focus & link off":
          disableFocusMode();
          disableLinkMode();
          break;
      }
    } else {
      app.displayInfoMessage("cancelled toggle modes");
    }

Options

  • After Success Nothing
    Notification None
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.