How to use the codemirror.Pos function in codemirror

To help you get started, we’ve selected a few codemirror examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql / graphiql / src / codemirror / hint / graphql-hint.js View on Github external
function hintList(editor, options, cursor, token, list) {
  var hints = filterAndSortList(list, normalizeText(token.string));
  if (!hints) {
    return;
  }

  var tokenStart = token.type === null ? token.end :
    /\w/.test(token.string[0]) ? token.start :
    token.start + 1;

  var results = {
    list: hints,
    from: CodeMirror.Pos(cursor.line, tokenStart),
    to: CodeMirror.Pos(cursor.line, token.end),
  };

  // GraphiQL displays the custom typeahead which appends information to the
  // end of the UI.
  if (options.displayInfo) {
    var wrapper;
    var information;

    // When a hint result is selected, we touch the UI.
    CodeMirror.on(results, 'select', (ctx, el) => {
      // Only the first time (usually when the hint UI is first displayed)
      // do we create the wrapping node.
      if (!wrapper) {
        // Wrap the existing hint UI, so we have a place to put information.
        var hintsUl = el.parentNode;
        var container = hintsUl.parentNode;
github taskcluster / taskcluster-tools / src / components / CodeEditor / yaml-lint.js View on Github external
CodeMirror.registerHelper('lint', 'yaml', text => {
  const found = [];

  try {
    safeLoad(text);
  } catch (e) {
    const loc = e.mark;

    found.push({
      from: CodeMirror.Pos(loc.line, loc.column),
      to: CodeMirror.Pos(loc.line, loc.column),
      message: e.message
    });
  }

  return found;
});
github witheve / Eve / src / ide.ts View on Github external
this.cm.operation(() => {
      let lastLine = doc.lastLine();
      let pos = CodeMirror.Pos(lastLine + 1, 0);
      if(doc.getLine(lastLine) !== "") {
        let cursor = doc.getCursor();
        doc.replaceRange("\n", pos, pos, "+normalize");
        doc.setCursor(cursor);
      }
    });
github hortonworks / streamline / webservice / src / main / resources / app / scripts / containers / Streams / TestRunComponents / TestSinkNodeModel.jsx View on Github external
parser.parseError = function(str, hash) {
    var loc = hash.loc;
    found.push({
      from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
      to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
      message: str
    });
  };
  try {
github buildkite / frontend / app / components / pipeline / YAMLEditor / index.js View on Github external
function getHints(cm) {
  let cursor = cm.getCursor();
  let start = cursor.ch, end = cursor.ch;

  return {
    list: [ "command", "block", "wait", "trigger" ],
    from: CodeMirror.Pos(cursor.line, start),
    to: CodeMirror.Pos(cursor.line, end)
  };
}
github mathieudutour / kayero / src / js / code-mirror-linter.js View on Github external
function getPos (error, from) {
  let line = error.line - 2
  let ch = (from ? error.column : error.column + 1) - 2
  if (error.node && error.node.loc) {
    line = (from ? error.node.loc.start.line - 1 : error.node.loc.end.line - 1) - 1
    ch = (from ? error.node.loc.start.column : error.node.loc.end.column) - 2
  }
  return CodeMirror.Pos(line, ch)
}
github graphql / graphiql / src / codemirror / lint / json-lint.js View on Github external
function getLocation(source, position) {
  var line = 0;
  var column = position;
  var lineRegexp = /\r\n|[\n\r]/g;
  var match;
  while ((match = lineRegexp.exec(source)) && match.index < position) {
    line += 1;
    column = position - (match.index + match[0].length);
  }
  return CodeMirror.Pos(line, column);
}
github jupyter / nbdime / nbdime-web / src / common / mergeview.ts View on Github external
function collapseSingle(cm: CodeMirror.Editor, from: number, to: number): {mark: CodeMirror.TextMarker, clear: () => void} {
  cm.addLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
  let widget = document.createElement('span');
  widget.className = 'CodeMirror-merge-collapsed-widget';
  widget.title = 'Identical text collapsed. Click to expand.';
  let mark = cm.getDoc().markText(
    CodeMirror.Pos(from, 0), CodeMirror.Pos(to - 1),
    {
      inclusiveLeft: true,
      inclusiveRight: true,
      replacedWith: widget,
      clearOnEnter: true
    }
  );
  function clear() {
    mark.clear();
    cm.removeLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
  }
  CodeMirror.on(widget, 'click', clear);
  return {mark: mark, clear: clear};
}
github jupyter / nbdime / packages / nbdime / src / common / mergeview.ts View on Github external
function collapseSingle(cm: CodeMirror.Editor, from: number, to: number): {mark: CodeMirror.TextMarker, clear: () => void} {
  cm.addLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
  let widget = document.createElement('span');
  widget.className = 'CodeMirror-merge-collapsed-widget';
  widget.title = 'Identical text collapsed. Click to expand.';
  let mark = cm.getDoc().markText(
    CodeMirror.Pos(from, 0), CodeMirror.Pos(to - 1),
    {
      inclusiveLeft: true,
      inclusiveRight: true,
      replacedWith: widget,
      clearOnEnter: true
    }
  );
  function clear() {
    mark.clear();
    cm.removeLineClass(from, 'wrap', 'CodeMirror-merge-collapsed-line');
  }
  CodeMirror.on(widget, 'click', clear);
  return {mark: mark, clear: clear};
}
github syndesisio / syndesis / app / ui-react / packages / ui / src / Shared / TextEditor / freemarker-mode-lint.ts View on Github external
try {
      const parser: FreemarkerParser = new FreemarkerParser();
      const result: any = parser.parse(text);

      if (result.ast && result.ast.errors) {
        for (const error of result.ast.errors) {
          const startLine =
            error.loc.start.line > 0 ? error.loc.start.line - 1 : 0;
          const startCol =
            error.loc.start.column > 0 ? error.loc.start.column - 1 : 0;
          const endLine = error.loc.end.line > 0 ? error.loc.end.line - 1 : 0;
          const endCol =
            error.loc.end.column > 0 ? error.loc.end.column - 1 : 0;

          errors.push({
            from: CodeMirror.Pos(startLine, startCol),
            message: error.message,
            severity: 'error',
            to: CodeMirror.Pos(endLine, endCol),
          });
        }
      }

      let totalSymbols = 0;
      for (const token of result.tokens) {
        if (token.type === 'Interpolation') {
          totalSymbols++;
        }
      }

      if (totalSymbols === 0) {
        const msg = 'linter-no-symbols';