Skip to content
Browse files

added long comment about the newline issue

  • Loading branch information...
1 parent 2461432 commit 2a5158402524999f2149f666b76796f2505cc21e Jen Fong-Adwent committed
Showing with 11 additions and 1 deletion.
  1. +11 −1 public/javascripts/main.js
View
12 public/javascripts/main.js
@@ -97,8 +97,18 @@ define(['jquery', 'appnet', 'friends', 'user', 'jquery.caret'],
var getEffectiveLength = function(text) {
// Same as in markdown-to-entities, but global
var markdownLinkRegex = /\[([^\]]+)\]\((\S+(?=\)))\)/g;
+
// Apparently newlines are considered part of the character count limitation
- return text.replace(markdownLinkRegex, '$1').length + text.split(/\n/).length;
+ // And apparently the newline is treated as two characters, not one when passed
+ // to the API as a post message - so here we count one for the key enter and one for
+ // the newline regex match. Which results in working out as two: '\n'
+ var markdownText = text.replace(markdownLinkRegex, '$1');
+ var markdownTextNewlineCount = 0;
+ if (markdownText.match(/\n/g)) {
+ markdownTextNewlineCount = markdownText.match(/\n/g).length;
+ }
+
+ return markdownText.length + markdownTextNewlineCount;
};
var checkCharLimit = function(text) {

0 comments on commit 2a51584

Please sign in to comment.
Something went wrong with that request. Please try again.