• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript codemirror.Pos函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
  };
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:52,代码来源:tab-completion.ts


示例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)
   };
 }
开发者ID:PartyPlanner64,项目名称:PartyPlanner64,代码行数:19,代码来源:mp-mips-autocomplete.ts


示例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;
}
开发者ID:minrk,项目名称:nbdime,代码行数:40,代码来源:range.ts


示例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;
 }
开发者ID:JeyKeu,项目名称:alm,代码行数:13,代码来源:text-hover.ts


示例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);
    };
开发者ID:suiruiw,项目名称:geeks-diary,代码行数:18,代码来源:note-snippet-code-mirror-editor.ts


示例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;
  }
开发者ID:gahjelle,项目名称:nbdime,代码行数:99,代码来源:diffmodel.ts


示例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);
    });
  }
});
开发者ID:PartyPlanner64,项目名称:PartyPlanner64,代码行数:92,代码来源:mp-mips-autocomplete.ts



注:本文中的codemirror.Pos函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap