本文整理汇总了TypeScript中codemirror.defineOption函数的典型用法代码示例。如果您正苦于以下问题:TypeScript defineOption函数的具体用法?TypeScript defineOption怎么用?TypeScript defineOption使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defineOption函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: showTooltip
//.........这里部分代码省略.........
if (options instanceof Function)
return {
getTextHover : options
};
if (!options || options === true)
options = {};
if (!options.getTextHover)
options.getTextHover = cm.getHelper(CodeMirror.Pos(0, 0), "textHover");
if (!options.getTextHover)
throw new Error("Required option 'getTextHover' missing (text-hover addon)");
return options;
}
function onMouseOverWithDelay(cm, e) {
var state = cm.state.textHover, delay = state.options.delay;
clearTimeout(state.timeout);
if (e.srcElement) {
// hack for IE, because e.srcElement failed when it is used in the tiemout function
var newE = {srcElement: e.srcElement, clientX : e.clientX, clientY: e.clientY};
e = newE;
}
state.timeout = setTimeout(function() {onMouseOver(cm, e);}, delay);
}
function onMouseOver(cm, e) {
var node = e.target || e.srcElement;
if (node) {
var state = cm.state.textHover, data = getTokenAndPosAt(cm, e);
var result = Promise.resolve(state.options.getTextHover(cm, data, e));
// Add to queue
PromiseQueue.push(result);
// BAS hide any previous
if (hidePreviousToolTip) {
hidePreviousToolTip();
hidePreviousToolTip = null;
}
result.then((content) => {
// If not the last in the queue ... the results don't matter
if (PromiseQueue[PromiseQueue.length - 1] !== result){
PromiseQueue = PromiseQueue.filter(p => p != result);
return;
}
PromiseQueue = PromiseQueue.filter(p => p != result);
if (content) {
node.className += HOVER_CLASS;
if (typeof content == 'function') {
content(showTooltipFor, data, e, node, state, cm);
}
else {
showTooltipFor(e, content, node, state, cm);
}
}
});
}
}
function optionHandler(cm, val, old) {
if (old && old != CodeMirror.Init) {
CodeMirror.off(cm.getWrapperElement(), "mouseover",
cm.state.textHover.onMouseOver);
delete cm.state.textHover;
}
if (val) {
var state = cm.state.textHover = new TextHoverState(cm, parseOptions(cm,
val));
CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
}
}
// When the mouseover fires, the cursor might not actually be over
// the character itself yet. These pairs of x,y offsets are used to
// probe a few nearby points when no suitable marked range is found.
var nearby = [ 0, 0, 0, 5, 0, -5, 5, 0, -5, 0 ];
function getTokenAndPosAt(cm, e) {
var node = e.target || e.srcElement, text = node.innerText
|| node.textContent;
for ( var i = 0; i < nearby.length; i += 2) {
var pos = cm.coordsChar({
left : e.clientX + nearby[i],
top : e.clientY + nearby[i + 1]
});
var token = cm.getTokenAt(pos);
if (token && token.string === text) {
return {
token : token,
pos : pos
};
}
}
}
CodeMirror.defineOption("textHover", false, optionHandler); // deprecated
})();
示例2: innerMode
declare module "codemirror" {
function innerMode(mode: any, state: any): any;
}
CodeMirror.defineOption("leanSymbols", false, function(cm, val, old) {
if (old) {
cm.removeKeyMap("leanSymbols");
cm.off("mousedown", lean_symbols);
cm.off("blur", lean_symbols);
}
if (!val) {
return;
}
const map = {
name: "leanSymbols",
Enter: lean_symbols,
Space: lean_symbols,
Tab: lean_symbols,
Right: lean_symbols,
Up: lean_symbols,
Down: lean_symbols,
"\\": lean_symbols
};
cm.on("mousedown", lean_symbols);
cm.on("blur", lean_symbols);
cm.addKeyMap(map);
});
/*
interface Position {
line: number;
示例3: innerMode
// This is how to add a new missing declaration via "augmentation":
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
declare module "codemirror" {
function innerMode(mode: any, state: any): any;
}
import { splitlines } from "smc-util/misc2";
CodeMirror.defineOption("autoCloseLatex", false, function(cm, val, old) {
if (old) {
cm.removeKeyMap("autoCloseLatex");
}
if (!val) {
return;
}
const map = {
name: "autoCloseLatex",
Enter: function(cm) {
return auto_close_latex(cm);
}
};
cm.addKeyMap(map);
});
interface Position {
line: number;
ch: number;
}
interface Selection {
head: Position;
示例4: require
} from 'src/shared/constants/codeMirrorModes'
import 'codemirror/addon/hint/show-hint'
/* tslint:disable */
const CodeMirror = require('codemirror')
CodeMirror.defineOption('placeholder', '', function(cm, val, old) {
var prev = old && old != CodeMirror.Init
if (val && !prev) {
cm.on('blur', onBlur)
cm.on('change', onChange)
cm.on('swapDoc', onChange)
onChange(cm)
} else if (!val && prev) {
cm.off('blur', onBlur)
cm.off('change', onChange)
cm.off('swapDoc', onChange)
clearPlaceholder(cm)
var wrapper = cm.getWrapperElement()
wrapper.className = wrapper.className.replace(' CodeMirror-empty', '')
}
if (val && !cm.hasFocus()) onBlur(cm)
})
CodeMirror.defineSimpleMode = function(name, states) {
CodeMirror.defineMode(name, function(config) {
return CodeMirror.simpleMode(config, states)
})
}
示例5: function
* START COPY PASTE
*/
var defaults = {
pairs: "()[]{}''\"\"",
triples: "",
explode: "[]{}"
};
var Pos = CodeMirror.Pos;
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
if (old && old != (CodeMirror as any).Init) {
cm.removeKeyMap(keyMap);
cm.state.closeBrackets = null;
}
if (val) {
cm.state.closeBrackets = val;
cm.addKeyMap(keyMap);
}
});
function getOption(conf, name) {
if (name == "pairs" && typeof conf == "string") return conf;
if (typeof conf == "object" && conf[name] != null) return conf[name];
return defaults[name];
}
var bind = defaults.pairs + "`";
var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
for (var i = 0; i < bind.length; i++)
keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i));
示例6: require
} from 'src/shared/constants/codeMirrorModes'
import 'codemirror/addon/hint/show-hint'
/* tslint:disable */
const CodeMirror = require('codemirror')
CodeMirror.defineOption("placeholder", "", function (cm, val, old) {
var prev = old && old != CodeMirror.Init;
if (val && !prev) {
cm.on("blur", onBlur);
cm.on("change", onChange);
cm.on("swapDoc", onChange);
onChange(cm);
} else if (!val && prev) {
cm.off("blur", onBlur);
cm.off("change", onChange);
cm.off("swapDoc", onChange);
clearPlaceholder(cm);
var wrapper = cm.getWrapperElement();
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
}
if (val && !cm.hasFocus()) onBlur(cm);
});
CodeMirror.defineSimpleMode = function(name, states) {
CodeMirror.defineMode(name, function(config) {
return CodeMirror.simpleMode(config, states)
})
}