Merge pull request #440 from ZogStriP/composer-count-only-significant-whitespaces
the composer will now count only significant whitespaces
This commit is contained in:
commit
259827d14b
|
@ -478,7 +478,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Computes the length of the reply minus the quote(s).
|
Computes the length of the reply minus the quote(s) and non-significant whitespaces
|
||||||
|
|
||||||
@property replyLength
|
@property replyLength
|
||||||
**/
|
**/
|
||||||
|
@ -486,7 +486,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
var reply = this.get('reply');
|
var reply = this.get('reply');
|
||||||
if(!reply) reply = "";
|
if(!reply) reply = "";
|
||||||
while (Discourse.BBCode.QUOTE_REGEXP.test(reply)) { reply = reply.replace(Discourse.BBCode.QUOTE_REGEXP, ""); }
|
while (Discourse.BBCode.QUOTE_REGEXP.test(reply)) { reply = reply.replace(Discourse.BBCode.QUOTE_REGEXP, ""); }
|
||||||
return reply.trim().length;
|
return reply.replace(/\s+/img, " ").trim().length;
|
||||||
}.property('reply')
|
}.property('reply')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,10 +10,16 @@ describe("Discourse.Composer", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("trims whitespaces", function() {
|
it("trims whitespaces", function() {
|
||||||
var composer = Discourse.Composer.create({ reply: "\nbasic reply\t" });
|
var composer = Discourse.Composer.create({ reply: " \nbasic reply\t" });
|
||||||
expect(composer.get('replyLength')).toBe(11);
|
expect(composer.get('replyLength')).toBe(11);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("count only significant whitespaces", function() {
|
||||||
|
// this will count the '\n' only once
|
||||||
|
var composer = Discourse.Composer.create({ reply: "ba sic\n\nreply" });
|
||||||
|
expect(composer.get('replyLength')).toBe(12);
|
||||||
|
});
|
||||||
|
|
||||||
it("removes quotes", function() {
|
it("removes quotes", function() {
|
||||||
var composer = Discourse.Composer.create({ reply: "1[quote=]not counted[/quote]2[quote=]at all[/quote]3" });
|
var composer = Discourse.Composer.create({ reply: "1[quote=]not counted[/quote]2[quote=]at all[/quote]3" });
|
||||||
expect(composer.get('replyLength')).toBe(3);
|
expect(composer.get('replyLength')).toBe(3);
|
||||||
|
|
Loading…
Reference in New Issue