本文整理汇总了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;
}
示例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 => {
示例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.
示例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');
});
示例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;
}
});
//.........这里部分代码省略.........