當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript codemirror.Mode類代碼示例

本文整理匯總了TypeScript中@jupyterlab/codemirror.Mode的典型用法代碼示例。如果您正苦於以下問題:TypeScript Mode類的具體用法?TypeScript Mode怎麽用?TypeScript Mode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Mode類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

 isToggled: args => {
   let widget = tracker.currentWidget;
   if (!widget) {
     return false;
   }
   let mime = widget.model.mimeType;
   let spec = Mode.findByMIME(mime);
   let name = spec && spec.name;
   return args['name'] === name;
 }
開發者ID:7125messi,項目名稱:jupyterlab,代碼行數:10,代碼來源:index.ts

示例2: cb

 Mode.ensure(lang).then(spec => {
   let el = document.createElement('div');
   if (!spec) {
     console.log(`No CodeMirror mode: ${lang}`);
     return cb(null, code);
   }
   try {
     Mode.run(code, spec.mime, el);
     return cb(null, el.innerHTML);
   } catch (err) {
     console.log(`Failed to highlight ${lang} code`, err);
     return cb(err, code);
   }
 }).catch(err => {
開發者ID:cameronoelsen,項目名稱:jupyterlab,代碼行數:14,代碼來源:renderers.ts

示例3: activateEditorCommands


//.........這裏部分代碼省略.........
      }
      let editor = widget.content.editor as CodeMirrorEditor;
      editor.execCommand('find');
    },
    isEnabled
  });

  commands.addCommand(CommandIDs.findAndReplace, {
    label: 'Find and Replace...',
    execute: () => {
      let widget = tracker.currentWidget;
      if (!widget) {
        return;
      }
      let editor = widget.content.editor as CodeMirrorEditor;
      editor.execCommand('replace');
    },
    isEnabled
  });

  commands.addCommand(CommandIDs.goToLine, {
    label: 'Go to Line...',
    execute: () => {
      let widget = tracker.currentWidget;
      if (!widget) {
        return;
      }
      let editor = widget.content.editor as CodeMirrorEditor;
      editor.execCommand('jumpToLine');
    },
    isEnabled
  });

  commands.addCommand(CommandIDs.changeMode, {
    label: args => args['name'] as string,
    execute: args => {
      let name = args['name'] as string;
      let widget = tracker.currentWidget;
      if (name && widget) {
        let spec = Mode.findByName(name);
        if (spec) {
          widget.content.model.mimeType = spec.mime;
        }
      }
    },
    isEnabled,
    isToggled: args => {
      let widget = tracker.currentWidget;
      if (!widget) {
        return false;
      }
      let mime = widget.content.model.mimeType;
      let spec = Mode.findByMIME(mime);
      let name = spec && spec.name;
      return args['name'] === name;
    }
  });

  Mode.getModeInfo()
    .sort((a, b) => {
      let aName = a.name || '';
      let bName = b.name || '';
      return aName.localeCompare(bName);
    })
    .forEach(spec => {
      // Avoid mode name with a curse word.
開發者ID:afshin,項目名稱:jupyterlab,代碼行數:67,代碼來源:index.ts

示例4: it

 it('should default to plain text', async () => {
   let spec = await Mode.ensure('this is not a mode');
   expect(spec.name).to.equal('Plain Text');
 });
開發者ID:afshin,項目名稱:jupyterlab,代碼行數:4,代碼來源:mode.spec.ts

示例5: createMenu

  /**
   * Create a menu for the editor.
   */
  function createMenu(): Menu {
    const menu = new Menu({ commands });
    const themeMenu = new Menu({ commands });
    const keyMapMenu = new Menu({ commands });
    const modeMenu = new Menu({ commands });
    const tabMenu = new Menu({ commands });

    menu.title.label = 'Editor';
    themeMenu.title.label = 'Theme';
    keyMapMenu.title.label = 'Key Map';
    modeMenu.title.label = 'Language';
    tabMenu.title.label = 'Tabs';

    commands.addCommand(CommandIDs.changeTheme, {
      label: args => args['theme'] as string,
      execute: args => {
        const key = 'theme';
        const value = theme = args['theme'] as string || theme;

        updateTracker();
        return settingRegistry.set(id, key, value).catch((reason: Error) => {
          console.error(`Failed to set ${id}:${key} - ${reason.message}`);
        });
      },
      isEnabled: hasWidget,
      isToggled: args => args['theme'] === theme
    });

    commands.addCommand(CommandIDs.changeKeyMap, {
      label: args => {
        let title = args['keyMap'] as string;
        return title === 'sublime' ? 'Sublime Text' : title;
      },
      execute: args => {
        const key = 'keyMap';
        const value = keyMap = args['keyMap'] as string || keyMap;

        updateTracker();
        return settingRegistry.set(id, key, value).catch((reason: Error) => {
          console.error(`Failed to set ${id}:${key} - ${reason.message}`);
        });
      },
      isEnabled: hasWidget,
      isToggled: args => args['keyMap'] === keyMap
    });

    commands.addCommand(CommandIDs.find, {
      label: 'Find',
      execute: () => {
        let widget = tracker.currentWidget;
        if (!widget) {
          return;
        }
        let editor = widget.editor as CodeMirrorEditor;
        editor.execCommand('find');
      },
      isEnabled: hasWidget
    });

    commands.addCommand(CommandIDs.findAndReplace, {
      label: 'Find & Replace',
      execute: () => {
        let widget = tracker.currentWidget;
        if (!widget) {
          return;
        }
        let editor = widget.editor as CodeMirrorEditor;
        editor.execCommand('replace');
      },
      isEnabled: hasWidget
    });

    commands.addCommand(CommandIDs.changeMode, {
      label: args => args['name'] as string,
      execute: args => {
        let name = args['name'] as string;
        let widget = tracker.currentWidget;
        if (name && widget) {
          let spec = Mode.findByName(name);
          if (spec) {
            widget.model.mimeType = spec.mime;
          }
        }
      },
      isEnabled: hasWidget,
      isToggled: args => {
        let widget = tracker.currentWidget;
        if (!widget) {
          return false;
        }
        let mime = widget.model.mimeType;
        let spec = Mode.findByMIME(mime);
        let name = spec && spec.name;
        return args['name'] === name;
      }
    });

//.........這裏部分代碼省略.........
開發者ID:cameronoelsen,項目名稱:jupyterlab,代碼行數:101,代碼來源:index.ts


注:本文中的@jupyterlab/codemirror.Mode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。