]> cat aescling's git repositories - mastodon.git/commitdiff
Fix #204, fix #515 - URL truncating is now a style so copypasting is not
authorEugen Rochko <eugen@zeonfederated.com>
Tue, 24 Jan 2017 16:05:44 +0000 (17:05 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 24 Jan 2017 16:05:44 +0000 (17:05 +0100)
affected, replaced onClick handler with onMouseUp/Down to detect text
selection not trigger onClick handler then

app/assets/javascripts/components/components/status_content.jsx
app/assets/stylesheets/components.scss
app/lib/formatter.rb
spec/lib/formatter_spec.rb

index f2c88cee0fe256bac736069e0f992b0d9ea81642..68224b7ba8cc4a642d87b0a97c1e1f801f9416bf 100644 (file)
@@ -56,12 +56,35 @@ const StatusContent = React.createClass({
     e.stopPropagation();
   },
 
+  handleMouseDown (e) {
+    this.startXY = [e.clientX, e.clientY];
+  },
+
+  handleMouseUp (e) {
+    const [ startX, startY ] = this.startXY;
+    const [ deltaX, deltaY ] = [Math.abs(e.clientX - startX), Math.abs(e.clientY - startY)];
+
+    if (deltaX + deltaY < 5) {
+      this.props.onClick();
+    }
+
+    this.startXY = null;
+  },
+
   render () {
-    const { status, onClick } = this.props;
+    const { status } = this.props;
 
     const content = { __html: emojify(status.get('content')) };
 
-    return <div className='status__content' style={{ cursor: 'pointer' }} dangerouslySetInnerHTML={content} onClick={onClick} />;
+    return (
+      <div
+        className='status__content'
+        style={{ cursor: 'pointer' }}
+        dangerouslySetInnerHTML={content}
+        onMouseDown={this.handleMouseDown}
+        onMouseUp={this.handleMouseUp}
+      />
+    );
   },
 
 });
index e1710580c762da9a4c299db3c1a14a780fc96dbc..4a3a7df5fd75166031c3ed6febb57c3f7abe808c 100644 (file)
   }
 }
 
+.invisible {
+  font-size: 0;
+  line-height: 0;
+}
+
+.ellipsis {
+  &:after {
+    content: "…";
+  }
+}
+
 .lightbox .icon-button {
   color: $color1;
 }
index 3565611bc9c4985f86d848c65ab0645765022399..1fa5b83fb303870a41a3593ba8ccba233e4a2a03 100644 (file)
@@ -65,8 +65,11 @@ class Formatter
   end
 
   def link_html(url)
-    link_text = truncate(url.gsub(/\Ahttps?:\/\/(www\.)?/, ''), length: 30)
-    "<a rel=\"nofollow noopener\" target=\"_blank\" href=\"#{url}\">#{link_text}</a>"
+    prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s
+    text   = url[prefix.length, 30]
+    suffix = url[prefix.length + 30..-1]
+
+    "<a rel=\"nofollow noopener\" target=\"_blank\" href=\"#{url}\"><span class=\"invisible\">#{prefix}</span><span class=\"ellipsis\">#{text}</span><span class=\"invisible\">#{suffix}</span></a>"
   end
 
   def hashtag_html(match)
index 7b8259fa62c3a3d463738c9b0dc7830ac35a7ed6..6ec28f5d88e8e2b47fc9d884d0ade592d10a712e 100644 (file)
@@ -17,7 +17,7 @@ RSpec.describe Formatter do
     end
 
     it 'contains a link' do
-      expect(subject).to match('<a rel="nofollow noopener" target="_blank" href="http://google.com">google.com</a>')
+      expect(subject).to match('<a rel="nofollow noopener" target="_blank" href="http://google.com"><span class="invisible">http://</span><span class="ellipsis">google.com</span><span class="invisible"></span></a>')
     end
   end