mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-02 18:54: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) {
|
||||
command = command.replace(/^(\s+)/, '');
|
||||
command = command.replace(/(\s+)$/, '');
|
||||
command = _.escape(command);
|
||||
|
||||
if (index > 0 && !command.length) {
|
||||
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'
|
||||
});
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -91,7 +98,8 @@ GitEngine.prototype.getBranches = function() {
|
|||
toReturn.push({
|
||||
id: branch.get('id'),
|
||||
selected: this.HEAD.get('target') === branch,
|
||||
target: branch.get('target')
|
||||
target: branch.get('target'),
|
||||
obj: branch
|
||||
});
|
||||
}, this);
|
||||
return toReturn;
|
||||
|
@ -568,8 +576,9 @@ GitEngine.prototype.checkoutStarter = function() {
|
|||
if (args.length == 1) {
|
||||
args.push('HEAD');
|
||||
}
|
||||
this.branch(args[0], args[1]);
|
||||
this.checkout(args[0]);
|
||||
var validId = this.validateBranchName(args[0]);
|
||||
this.branch(validId, args[1]);
|
||||
this.checkout(validId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -634,6 +643,7 @@ GitEngine.prototype.branchStarter = function() {
|
|||
// making a branch from where we are now
|
||||
this.generalArgs.push('HEAD');
|
||||
}
|
||||
|
||||
this.branch(this.generalArgs[0], this.generalArgs[1]);
|
||||
};
|
||||
|
||||
|
@ -715,6 +725,7 @@ GitEngine.prototype.dispatch = function(command, callback) {
|
|||
gitVisuals.refreshTree();
|
||||
}
|
||||
}));
|
||||
|
||||
// TODO (get rid of)
|
||||
for (var i = 0; i < 1; i++) {
|
||||
this.animationQueue.add(new Animation({closure: function() { console.log(Math.random()); }}));
|
||||
|
@ -840,6 +851,10 @@ var Ref = Backbone.Model.extend({
|
|||
});
|
||||
|
||||
var Branch = Ref.extend({
|
||||
defaults: {
|
||||
visBranch: null,
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
Ref.prototype.initialize.call(this);
|
||||
this.set('type', 'branch');
|
||||
|
@ -853,7 +868,8 @@ var Commit = Backbone.Model.extend({
|
|||
parents: null,
|
||||
author: 'Peter Cottle',
|
||||
createTime: null,
|
||||
commitMessage: null
|
||||
commitMessage: null,
|
||||
visNode: null
|
||||
},
|
||||
|
||||
getLogEntry: function() {
|
||||
|
|
32
src/tree.js
32
src/tree.js
|
@ -34,7 +34,13 @@ var VisBranch = Backbone.Model.extend({
|
|||
|
||||
getBranchStackIndex: function() {
|
||||
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() {
|
||||
|
@ -107,11 +113,25 @@ var VisBranch = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
getTextSize: function() {
|
||||
var getTextWidth = function(visBranch) {
|
||||
var textNode = visBranch.get('text').node;
|
||||
return textNode.clientWidth;
|
||||
};
|
||||
|
||||
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 {
|
||||
w: textNode.clientWidth,
|
||||
w: maxWidth,
|
||||
h: textNode.clientHeight
|
||||
};
|
||||
},
|
||||
|
@ -158,7 +178,8 @@ var VisBranch = Backbone.Model.extend({
|
|||
var name = this.getName();
|
||||
var text = paper.text(textPos.x, textPos.y, String(name));
|
||||
text.attr({
|
||||
'font-size': 16
|
||||
'font-size': 14,
|
||||
'font-family': 'Monaco, Courier, font-monospace'
|
||||
});
|
||||
this.set('text', text);
|
||||
|
||||
|
@ -193,6 +214,7 @@ var VisBranch = Backbone.Model.extend({
|
|||
this.get('text').attr({
|
||||
text: this.getName()
|
||||
});
|
||||
|
||||
var textPos = this.getTextPosition();
|
||||
this.get('text').stop().animate({
|
||||
x: textPos.x,
|
||||
|
|
|
@ -107,8 +107,15 @@ GitVisuals.prototype.calcBranchStacks = function() {
|
|||
var thisId = branch.target.get('id');
|
||||
|
||||
map[thisId] = map[thisId] || [];
|
||||
map[thisId].push(branch.id);
|
||||
map[thisId].sort();
|
||||
map[thisId].push(branch);
|
||||
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;
|
||||
};
|
||||
|
@ -208,10 +215,11 @@ GitVisuals.prototype.addBranch = function(branch) {
|
|||
var visBranch = new VisBranch({
|
||||
branch: branch
|
||||
});
|
||||
branch.set('visBranch', visBranch);
|
||||
|
||||
this.visBranchCollection.add(visBranch);
|
||||
if (this.paperReady) {
|
||||
visBranch.genGraphics(paper);
|
||||
this.zIndexReflow();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue