diff --git a/app/assets/javascripts/discourse/components/formatter.js b/app/assets/javascripts/discourse/components/formatter.js index 8a21385a46e..85f0de23ad1 100644 --- a/app/assets/javascripts/discourse/components/formatter.js +++ b/app/assets/javascripts/discourse/components/formatter.js @@ -13,13 +13,29 @@ Discourse.Formatter = (function(){ var firstPart = string.substr(0, maxLength); - var betterSplit = firstPart.substr(1).search(/[^a-z]/); - if (betterSplit >= 0) { - var offset = 1; - if(string[betterSplit+1] === "_") { - offset = 2; + // work backward to split stuff like ABPoop to AB Poop + var i; + for(i=firstPart.length-1;i>0;i--){ + if(firstPart[i].match(/[A-Z]/)){ + break; } - return string.substr(0, betterSplit + offset) + " " + string.substring(betterSplit + offset); + } + + // work forwards to split stuff like ab111 to ab 111 + if(i===0) { + for(i=1;i 0 && i < firstPart.length) { + var offset = 0; + if(string[i] === "_") { + offset = 1; + } + return string.substr(0, i + offset) + " " + string.substring(i + offset); } else { return firstPart + " " + string.substr(maxLength); } diff --git a/test/javascripts/components/formatter_test.js b/test/javascripts/components/formatter_test.js index 1ff9678b656..0767ca379e8 100644 --- a/test/javascripts/components/formatter_test.js +++ b/test/javascripts/components/formatter_test.js @@ -199,5 +199,6 @@ test("breakUp", function(){ equal(b("HeMans"), "He Mans"); equal(b("he_man"), "he_ man"); equal(b("he11111"), "he 11111"); + equal(b("HRCBob"), "HRC Bob"); });