本文整理汇总了TypeScript中codemirror.Pos函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Pos函数的具体用法?TypeScript Pos怎么用?TypeScript Pos使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pos函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: leanHint
async function leanHint(
cm: CodeMirror.Editor
): Promise<{ list: CMCompletion[]; from: any; to: any } | void> {
var cur = cm.getDoc().getCursor(),
token = cm.getTokenAt(cur);
const set: any = {};
const list: CMCompletion[] = [];
function include(words: string[]): void {
for (let word of words) {
if (!set[word]) {
set[word] = true;
list.push({ text: word, displayText: `â ${word}` });
}
}
}
// First start with list of completions coming from
// the syntax highlighting mode.
let t = (CodeMirror as any).hint.anyword(cm);
if (t != null && t.list != null) {
include(t.list);
}
// We have to also do this, since the above misses words that haven't already been highlighted!
t = (CodeMirror as any).hint.fromList(cm, { words: completions });
if (t != null && t.list != null) {
include(t.list);
}
list.sort();
// completions coming from backend LEAN server.
if ((cm as any).cocalc_actions !== undefined) {
const actions: Actions = (cm as any).cocalc_actions;
const resp: Completion[] = await actions.complete(cur.line, cur.ch);
// First show those that match token.string, then show the rest.
for (let i = 0; i < resp.length; i++) {
const { text, type } = resp[i];
const displayText = `⣠${text} : ${type}`;
list.push({ text, displayText });
}
}
return {
list,
from: CodeMirror.Pos(cur.line, token.start),
to: CodeMirror.Pos(cur.line, token.end)
};
}
示例2: _showSyms
function _showSyms(symbols: ISymbol[]) {
let syms = symbols.map(sym => {
return sym.name;
});
let startOffset = 1; // Default: place sym one space after any previous value.
if (tokenString.trim()) {
// We should partial match.
startOffset = tokenString.lastIndexOf("(") + 1; // From the last start of a function
let postFnStr = tokenString.substring(startOffset);
if (postFnStr) {
syms = _filterByToken(tokenString, syms);
}
}
return {
list: syms.sort(),
from: Pos(cur.line, start + startOffset),
to: Pos(cur.line, end)
};
}
示例3: raw2Pos
function raw2Pos(raws: DiffRangeRaw[], text: string): DiffRangePos[] {
// Find all newline's indices in text
let adIdx: number[] = [];
let i = -1;
while (-1 !== (i = text.indexOf('\n', i + 1))) {
adIdx.push(i);
}
let result: DiffRangePos[] = [];
// Find line numbers from raw index
for (let r of raws) {
// First `from` position:
let line = findLineNumber(adIdx, r.from);
let lineStartIdx = line > 0 ? adIdx[line - 1] + 1 : 0;
let from = CodeMirror.Pos(line, r.from - lineStartIdx);
// Then `to` position:
line = findLineNumber(adIdx, r.to - 1); // `to` is non-inclusive
lineStartIdx = line > 0 ? adIdx[line - 1] + 1 : 0;
let to = CodeMirror.Pos(line, r.to - lineStartIdx);
// Finally chunking hints:
let startsOnNewLine = valueIn(r.from, adIdx);
let endsOnNewline = valueIn(r.to - 1, adIdx); // non-inclusive
let firstLineNew = from.ch === 0 && (
from.line !== to.line || endsOnNewline || r.to === text.length);
let chunkFirstLine = (
firstLineNew ||
!startsOnNewLine ||
(
// Neither preceding nor following character is a newline
!valueIn(r.from - 1, adIdx) &&
!valueIn(r.to, adIdx)
)
);
let pos = new DiffRangePos(from, to, chunkFirstLine, endsOnNewline);
pos.source = r.source;
result.push(pos);
}
return result;
}
示例4: parseOptions
function parseOptions(cm, options) {
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;
}
示例5:
const matchListToken = (pos: any, cm: CodeMirrorEditor) => {
/* Get some info about the current state */
const eolState = cm.getStateAfter(pos.line);
const inList = eolState.list !== false;
const inQuote = eolState.quote !== 0;
/* Get the line from the start to where the cursor currently is */
const lineStart = (cm as any).getRange(CodeMirror.Pos(pos.line, 0), pos);
/* Matches the beginning of the list line with the list token RE */
const match = listTokenRegExp.exec(lineStart);
/**
* Not being in a list, or being in a list but not right after the list
* token, are both not considered a match.
*/
return !((!inList && !inQuote) || !match);
};
示例6: getChunks
/**
* Uses Chunk.inOrig/inEdit to determine diff entry overlap.
*/
getChunks(): Chunk[] {
var chunks: Chunk[] = [];
var startEdit = 0, startOrig = 0, editOffset = 0;
var edit = CodeMirror.Pos(0, 0), orig = CodeMirror.Pos(0, 0);
let ia = 0, id = 0;
let current: Chunk = null;
let isAddition: boolean = null;
let range: DiffRangePos = null;
for (;;) {
// Figure out which element to take next
if (ia < this.additions.length) {
if (id < this.deletions.length) {
let ra = this.additions[ia], rd = this.deletions[id];
if (ra.from.line < rd.from.line - editOffset ||
(ra.from.line == rd.from.line - editOffset &&
ra.from.ch <= rd.from.ch)) {
// TODO: Character editOffset should also be used
isAddition = true;
} else {
isAddition = false;
}
} else {
// No more deletions
isAddition = true;
}
} else if (id < this.deletions.length) {
// No more additions
isAddition = false;
} else {
if (current) { chunks.push(current); }
break;
}
if (isAddition) {
range = this.additions[ia++];
} else {
range = this.deletions[id++];
}
let linediff = range.to.line - range.from.line;
if (range.endsOnNewline) {
linediff += 1;
}
let firstLineNew = range.from.ch === 0 && linediff > 0;
let startOffset = range.chunkStartLine ? 0 : 1;
let endOffset =
range.chunkStartLine && range.endsOnNewline && firstLineNew ?
0 : 1;
if (current) {
if (isAddition) {
if (current.inOrig(range.from.line)) {
current.origTo = Math.max(current.origTo,
range.to.line + 1);
} else {
// No overlap with chunk, start new one
chunks.push(current);
current = null;
}
} else {
if (current.inEdit(range.from.line)) {
current.editTo = Math.max(current.editTo,
range.to.line + 1);
} else {
// No overlap with chunk, start new one
chunks.push(current);
current = null;
}
}
}
if (!current) {
if (isAddition) {
startOrig = range.from.line;
startEdit = startOrig + editOffset;
current = new Chunk(
startEdit + startOffset,
startEdit + endOffset,
startOrig + startOffset,
startOrig + endOffset + linediff
);
} else {
startEdit = range.from.line;
startOrig = startEdit - editOffset;
current = new Chunk(
startEdit + startOffset,
startEdit + endOffset + linediff,
startOrig + startOffset,
startOrig + endOffset
);
}
}
editOffset += isAddition ? -linediff : linediff;
}
return chunks;
}
示例7: registerHelper
registerHelper("hint", "mips-pp64", function(cm: any) {
const cur = cm.getCursor();
const token = cm.getTokenAt(cur);
const tokenString = token.string;
const start = token.start;
const end = cur.ch;
const line = cm.getLine(cur.line);
// console.log(cur, token, start, end, line);
if (line[0] === ".") {
let directives = [
"ascii",
"asciiz",
"align",
"byte",
"definelabel",
"else",
"elseif",
"endif",
"fill",
"float",
"halfword",
"if",
// "org", would break events
// "orga", would break events
"skip",
"word",
];
return {
list: directives,
from: Pos(cur.line, 1),
to: Pos(cur.line, end)
};
}
const supportedGames = getActiveEditorSupportedGames();
function getSymbols(games: Game[], type?: any) {
if (!games.length)
return [];
if (games.length === 1)
return getSymbolsForGame(games[0], type);
// Take the intersection of the supported games' symbols.
let result = getSymbolsForGame(games[0], type);
for (let i = 0; i < games.length - 1; i++) {
const nextSymbols = getSymbolsForGame(games[i + 1], type);
result = intersection(result, nextSymbols, (a, b) => {
return a.name === b.name;
});
}
return result;
}
const directJumps = /^(j|jal)\s+/i;
if (directJumps.test(line)) {
let syms = getSymbols(supportedGames, "code");
return _showSyms(syms);
}
const beyondOpcode = /^\w+\s+/;
if (beyondOpcode.test(line)) {
let syms = getSymbols(supportedGames);
return _showSyms(syms);
}
function _showSyms(symbols: ISymbol[]) {
let syms = symbols.map(sym => {
return sym.name;
});
let startOffset = 1; // Default: place sym one space after any previous value.
if (tokenString.trim()) {
// We should partial match.
startOffset = tokenString.lastIndexOf("(") + 1; // From the last start of a function
let postFnStr = tokenString.substring(startOffset);
if (postFnStr) {
syms = _filterByToken(tokenString, syms);
}
}
return {
list: syms.sort(),
from: Pos(cur.line, start + startOffset),
to: Pos(cur.line, end)
};
}
function _filterByToken(tokenString: string, values: string[]) {
return values.filter(value => {
return value.startsWith(tokenString);
});
}
});