Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
Merge pull request #241 from Pomax/bug919636
Browse files Browse the repository at this point in the history
tell codemirror where an error is, if the cursor is at 0/0
  • Loading branch information
Pomax committed Oct 1, 2013
2 parents 0b8ce16 + 81d88c4 commit 56a8f6c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions public/friendlycode/js/fc/ui/parsing-codemirror.js
Expand Up @@ -12,11 +12,27 @@ define([
function reparse() {
var sourceCode = codeMirror.getValue();
var result = givenOptions.parse(sourceCode);
var curPos = codeMirror.getCursor();

// Errors cannot occur based on user input while the cursor
// sits on line 0, column 0, as any kind of typing will move
// the cursor to a non-zero position.
if (result.error && curPos.line === 0 && curPos.ch === 0) {
// If we see an error on 0/0, the error is actually somewhere
// else in the document, and we need to move the cursor to
// the end of the erroneous code first.
var index = result.error.closeTag.end,
pos = codeMirror.posFromIndex(index);
codeMirror.setCursor(pos);
}

// handle (possible) errors
CodeMirror.signal(codeMirror, "reparse", {
error: result.error,
sourceCode: sourceCode,
document: result.document
});

// Cursor activity would've been fired before us, so call it again
// to make sure it displays the right context-sensitive help based
// on the new state of the document.
Expand Down

0 comments on commit 56a8f6c

Please sign in to comment.