Smarter way to avoid triming the space before a channel name
authorCory Chaplin <cory.chaplin@laposte.net>
Sun, 11 May 2014 00:04:41 +0000 (02:04 +0200)
committerCory Chaplin <cory.chaplin@laposte.net>
Sun, 11 May 2014 00:04:41 +0000 (02:04 +0200)
client/src/views/channel.js

index 1ebc66626246b5a2c1230df58fd06bc6ee15e05f..04639f3bff707bf1f3fd9db8eebed98799a9fdbe 100644 (file)
@@ -59,7 +59,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
             time_difference,
             sb = this.model.get('scrollback'),
             prev_msg = sb[sb.length-2],
-            network, hour, pm, extra_space = '';
+            network, hour, pm;
 
         // Nick highlight detecting
         if ((new RegExp('(^|\\W)(' + escapeRegex(_kiwi.app.connections.active_connection.get('nick')) + ')(\\W|$)', 'i')).test(msg.msg)) {
@@ -72,12 +72,9 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
 
         // Make the channels clickable
         if ((network = this.model.get('network'))) {
-            re = new RegExp('(?:^|\\s)([' + escapeRegex(network.get('channel_prefix')) + '][^ ,\\007]+)', 'g');
-            msg.msg = msg.msg.replace(re, function (match) {
-                if(match.match(/^\s+/g)) {
-                    extra_space = ' ';
-                }
-                return extra_space + '<a class="chan" data-channel="' + _.escape(match.trim()) + '">' + _.escape(match.trim()) + '</a>';
+            re = new RegExp('(^|\\s)([' + escapeRegex(network.get('channel_prefix')) + '][^ ,\\007]+)', 'g');
+            msg.msg = msg.msg.replace(re, function (m1, m2) {
+                return m2 + '<a class="chan" data-channel="' + _.escape(m1.trim()) + '">' + _.escape(m1.trim()) + '</a>';
             });
         }