Permalink
Browse files

updating the cursor properly

  • Loading branch information...
1 parent 522859e commit 8cab588988c1fe0e5bdbc0f63166c6944311b154 @substack committed Jul 19, 2011
Showing with 13 additions and 7 deletions.
  1. +13 −7 index.js
View
@@ -11,32 +11,38 @@ module.exports = function (src) {
var prevPathLen = 0;
burrito('[\n' + src + '\n][0]', function (node) {
+ var p = node.parent();
+ var key = undefined;
+
+ if (!p) return
+
if (this.path.length <= prevPathLen) {
path.pop();
+ cursor.shift();
prevPathLen = path.length;
}
- var p = node.parent();
- var key = undefined;
-
- if (!p) return
- else if (p.name === 'object') {
+ if (p.name === 'object') {
var ix = this.path[ this.path.length - 2 ];
key = p.value[0][ix][0];
}
else if (p.name === 'array') {
key = this.key;
}
else if (p.name === 'sub' && node.value[0] !== 0) {
- //console.dir(node.value);
+ return; // the root
}
else return;
+ //console.log(path.concat(key).join('/'));
+
if (node.name === 'object' || node.name === 'array') {
prevPathLen = this.path.length;
path.push(key);
+console.log(key);
+console.dir(cursor[0]);
+ cursor.unshift(cursor[0][key]);
}
- console.log(path.join('/'));
});
self.set = function (key, value) {

0 comments on commit 8cab588

Please sign in to comment.