Action

toggle editor modes

Posted by FlohGro, Last update almost 3 years ago

UPDATES

almost 3 years ago

fixed wrong function name

show all updates...

almost 3 years ago

fixed wrong function name

almost 3 years ago

changed naming and apis from focus to pinning (changes in the latest drafts update)

about 3 years ago

Description update

created by @FlohGro / more on my Blog

toggle editor modes

This action presents a prompt to toggle various modes of the drafts editor. depending on the current active modes the prompt will show different options.

Following modes will be considered:

  • focus
  • link
  • arrange
  • typewriter

[Configuration]

no configuration needed

[Usage]

This action is most efficient if you assign a keyboard shortcut to it and / or add it to the action bar above your keyboard. If you want to change any mode of the edito just press the button / keyboard shortcut and select the modes you want in the prompt.


If you find this useful and want to support me you can

Buy Me A Coffee

Steps

  • script

    // toggle modes 
    
    let isPinningEnabled = () => {
      if (editor.pinningEnabled == 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 enablePinningMode = () => {
      editor.pinningEnabled = true;
    }
    
    let disablePinningMode = () => {
      editor.pinningEnabled = 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 (isPinningEnabled() == true) {
      modes2toggle.push("pinning off");
    } else {
      modes2toggle.push("pinning on");
    }
    
    if (isTypewriterEnabled() == true) {
      modes2toggle.push("typewriter off");
    } else {
      modes2toggle.push("typewriter on");
    }
    
    if (isLinkEnabled() == true && isPinningEnabled() == true) {
      modes2toggle.push("pinning & link off");
    }
    
    if (isLinkEnabled() == false && isPinningEnabled() == false) {
      modes2toggle.push("pinning & link on");
    }
    
    if (isTypewriterEnabled() == true && isPinningEnabled() == true) {
      modes2toggle.push("typewriter & pinning off");
    }
    
    if (isTypewriterEnabled() == false && isPinningEnabled() == false) {
      modes2toggle.push("typewriter & pinning on");
    }
    
    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 "pinning on":
          enablePinningMode();
          break;
        case "pinning off":
          disablePinningMode();
          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 & pinning on":
          enablePinningMode();
          enableTypewriterMode();
          break;
        case "typewriter & pinning off":
          disablePinningMode();
          disableTypewriterMode();
          break;
        case "pinning & link on":
          enablePinningMode();
          enableLinkMode();
          break;
        case "pinning & link off":
          disablePinningMode();
          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.