obsidian#Modifier TypeScript Examples

The following examples show how to use obsidian#Modifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: misc.ts    From alx-folder-note with MIT License 6 votes vote down vote up
isModifier = (evt: MouseEvent, pref: Modifier): boolean => {
  const { altKey, metaKey, ctrlKey, shiftKey } = evt;
  switch (pref) {
    case "Mod":
      return Platform.isMacOS ? metaKey : ctrlKey;
    case "Ctrl":
      return ctrlKey;
    case "Meta":
      return metaKey;
    case "Shift":
      return shiftKey;
    case "Alt":
      return altKey;
    default:
      assertNever(pref);
  }
}
Example #2
Source File: settings.ts    From alx-folder-note with MIT License 6 votes vote down vote up
setModifier = () => {
    new Setting(this.containerEl)
      .setName("Modifier for New Note")
      .setDesc("Choose a modifier to click folders with to create folder notes")
      .addDropdown((dropDown) => {
        type NoShift = Exclude<Modifier, "Shift">;
        const windowsOpts: Record<NoShift, string> = {
          Mod: "Ctrl (Cmd in macOS)",
          Ctrl: "Ctrl (Ctrl in macOS)",
          Meta: "⊞ Win",
          // Shift: "Shift",
          Alt: "Alt",
        };
        const macOSOpts: Record<NoShift, string> = {
          Mod: "⌘ Cmd (Ctrl in Windows)",
          Ctrl: "⌃ Control",
          Meta: "⌘ Cmd (Win in Windows)",
          // Shift: "⇧ Shift",
          Alt: "⌥ Option",
        };

        const options = Platform.isMacOS ? macOSOpts : windowsOpts;

        dropDown
          .addOptions(options)
          .setValue(this.plugin.settings.modifierForNewNote)
          .onChange(async (value: string) => {
            this.plugin.settings.modifierForNewNote = value as NoShift;
            await this.plugin.saveSettings();
          });
      });
  };