mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-04 11:44:27 +02:00
better escaping
This commit is contained in:
parent
6e7e06277e
commit
09ca30b224
4 changed files with 59 additions and 12 deletions
|
@ -70,6 +70,7 @@ var CommandPromptView = Backbone.View.extend({
|
||||||
_.each(value.split(';'), _.bind(function(command, index) {
|
_.each(value.split(';'), _.bind(function(command, index) {
|
||||||
command = command.replace(/^(\s+)/, '');
|
command = command.replace(/^(\s+)/, '');
|
||||||
command = command.replace(/(\s+)$/, '');
|
command = command.replace(/(\s+)$/, '');
|
||||||
|
command = _.escape(command);
|
||||||
|
|
||||||
if (index > 0 && !command.length) {
|
if (index > 0 && !command.length) {
|
||||||
return;
|
return;
|
||||||
|
|
24
src/git.js
24
src/git.js
|
@ -61,6 +61,13 @@ GitEngine.prototype.validateBranchName = function(name) {
|
||||||
msg: 'branch name of "head" is ambiguous, dont name it that'
|
msg: 'branch name of "head" is ambiguous, dont name it that'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (name.length > 9) {
|
||||||
|
name = name.slice(0, 9);
|
||||||
|
this.command.addWarning(
|
||||||
|
'Sorry, we need to keep branch names short for the visuals. Your branch ' +
|
||||||
|
'name was truncated to 9 characters, resulting in ' + name
|
||||||
|
);
|
||||||
|
}
|
||||||
return name;
|
return name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -91,7 +98,8 @@ GitEngine.prototype.getBranches = function() {
|
||||||
toReturn.push({
|
toReturn.push({
|
||||||
id: branch.get('id'),
|
id: branch.get('id'),
|
||||||
selected: this.HEAD.get('target') === branch,
|
selected: this.HEAD.get('target') === branch,
|
||||||
target: branch.get('target')
|
target: branch.get('target'),
|
||||||
|
obj: branch
|
||||||
});
|
});
|
||||||
}, this);
|
}, this);
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
@ -568,8 +576,9 @@ GitEngine.prototype.checkoutStarter = function() {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
args.push('HEAD');
|
args.push('HEAD');
|
||||||
}
|
}
|
||||||
this.branch(args[0], args[1]);
|
var validId = this.validateBranchName(args[0]);
|
||||||
this.checkout(args[0]);
|
this.branch(validId, args[1]);
|
||||||
|
this.checkout(validId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,6 +643,7 @@ GitEngine.prototype.branchStarter = function() {
|
||||||
// making a branch from where we are now
|
// making a branch from where we are now
|
||||||
this.generalArgs.push('HEAD');
|
this.generalArgs.push('HEAD');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.branch(this.generalArgs[0], this.generalArgs[1]);
|
this.branch(this.generalArgs[0], this.generalArgs[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -715,6 +725,7 @@ GitEngine.prototype.dispatch = function(command, callback) {
|
||||||
gitVisuals.refreshTree();
|
gitVisuals.refreshTree();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// TODO (get rid of)
|
// TODO (get rid of)
|
||||||
for (var i = 0; i < 1; i++) {
|
for (var i = 0; i < 1; i++) {
|
||||||
this.animationQueue.add(new Animation({closure: function() { console.log(Math.random()); }}));
|
this.animationQueue.add(new Animation({closure: function() { console.log(Math.random()); }}));
|
||||||
|
@ -840,6 +851,10 @@ var Ref = Backbone.Model.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
var Branch = Ref.extend({
|
var Branch = Ref.extend({
|
||||||
|
defaults: {
|
||||||
|
visBranch: null,
|
||||||
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
Ref.prototype.initialize.call(this);
|
Ref.prototype.initialize.call(this);
|
||||||
this.set('type', 'branch');
|
this.set('type', 'branch');
|
||||||
|
@ -853,7 +868,8 @@ var Commit = Backbone.Model.extend({
|
||||||
parents: null,
|
parents: null,
|
||||||
author: 'Peter Cottle',
|
author: 'Peter Cottle',
|
||||||
createTime: null,
|
createTime: null,
|
||||||
commitMessage: null
|
commitMessage: null,
|
||||||
|
visNode: null
|
||||||
},
|
},
|
||||||
|
|
||||||
getLogEntry: function() {
|
getLogEntry: function() {
|
||||||
|
|
32
src/tree.js
32
src/tree.js
|
@ -34,7 +34,13 @@ var VisBranch = Backbone.Model.extend({
|
||||||
|
|
||||||
getBranchStackIndex: function() {
|
getBranchStackIndex: function() {
|
||||||
var myArray = this.getBranchStackArray();
|
var myArray = this.getBranchStackArray();
|
||||||
return myArray.indexOf(this.get('branch').get('id'));
|
var index = -1;
|
||||||
|
_.each(myArray, function(branch, i) {
|
||||||
|
if (branch.obj == this.get('branch')) {
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
return index;
|
||||||
},
|
},
|
||||||
|
|
||||||
getBranchStackLength: function() {
|
getBranchStackLength: function() {
|
||||||
|
@ -107,11 +113,25 @@ var VisBranch = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
getTextSize: function() {
|
getTextSize: function() {
|
||||||
|
var getTextWidth = function(visBranch) {
|
||||||
|
var textNode = visBranch.get('text').node;
|
||||||
|
return textNode.clientWidth;
|
||||||
|
};
|
||||||
|
|
||||||
var textNode = this.get('text').node;
|
var textNode = this.get('text').node;
|
||||||
var w = textNode.clientWidth;
|
|
||||||
var h = textNode.clientHeight;
|
var maxWidth = 0;
|
||||||
|
_.each(this.getBranchStackArray(), function(branch) {
|
||||||
|
maxWidth = Math.max(maxWidth, getTextWidth(
|
||||||
|
branch.obj.get('visBranch')
|
||||||
|
));
|
||||||
|
console.log('this branch', branch.id, 'is selected', branch.selected);
|
||||||
|
console.log('and i just calculated its width', getTextWidth(branch.obj.get('visBranch')));
|
||||||
|
});
|
||||||
|
console.log('I am ****', this.getName(), ' and got max width of', maxWidth);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
w: textNode.clientWidth,
|
w: maxWidth,
|
||||||
h: textNode.clientHeight
|
h: textNode.clientHeight
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -158,7 +178,8 @@ var VisBranch = Backbone.Model.extend({
|
||||||
var name = this.getName();
|
var name = this.getName();
|
||||||
var text = paper.text(textPos.x, textPos.y, String(name));
|
var text = paper.text(textPos.x, textPos.y, String(name));
|
||||||
text.attr({
|
text.attr({
|
||||||
'font-size': 16
|
'font-size': 14,
|
||||||
|
'font-family': 'Monaco, Courier, font-monospace'
|
||||||
});
|
});
|
||||||
this.set('text', text);
|
this.set('text', text);
|
||||||
|
|
||||||
|
@ -193,6 +214,7 @@ var VisBranch = Backbone.Model.extend({
|
||||||
this.get('text').attr({
|
this.get('text').attr({
|
||||||
text: this.getName()
|
text: this.getName()
|
||||||
});
|
});
|
||||||
|
|
||||||
var textPos = this.getTextPosition();
|
var textPos = this.getTextPosition();
|
||||||
this.get('text').stop().animate({
|
this.get('text').stop().animate({
|
||||||
x: textPos.x,
|
x: textPos.x,
|
||||||
|
|
|
@ -107,8 +107,15 @@ GitVisuals.prototype.calcBranchStacks = function() {
|
||||||
var thisId = branch.target.get('id');
|
var thisId = branch.target.get('id');
|
||||||
|
|
||||||
map[thisId] = map[thisId] || [];
|
map[thisId] = map[thisId] || [];
|
||||||
map[thisId].push(branch.id);
|
map[thisId].push(branch);
|
||||||
map[thisId].sort();
|
map[thisId].sort(function(a, b) {
|
||||||
|
var aId = a.obj.get('id');
|
||||||
|
var bId = b.obj.get('id');
|
||||||
|
if (aId == 'master' || bId == 'master') {
|
||||||
|
return aId == 'master' ? -1 : 1;
|
||||||
|
}
|
||||||
|
return aId.localeCompare(bId);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
this.branchStackMap = map;
|
this.branchStackMap = map;
|
||||||
};
|
};
|
||||||
|
@ -208,10 +215,11 @@ GitVisuals.prototype.addBranch = function(branch) {
|
||||||
var visBranch = new VisBranch({
|
var visBranch = new VisBranch({
|
||||||
branch: branch
|
branch: branch
|
||||||
});
|
});
|
||||||
|
branch.set('visBranch', visBranch);
|
||||||
|
|
||||||
this.visBranchCollection.add(visBranch);
|
this.visBranchCollection.add(visBranch);
|
||||||
if (this.paperReady) {
|
if (this.paperReady) {
|
||||||
visBranch.genGraphics(paper);
|
visBranch.genGraphics(paper);
|
||||||
this.zIndexReflow();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue