{"action":"created","comment":{"url":"https://api.github.com/repos/flutter/flutter/pulls/comments/60150909","id":60150909,"diff_hunk":"@@ -0,0 +1,223 @@\n+// Copyright 2015 The Chromium Authors. All rights reserved.\n+// Use of this source code is governed by a BSD-style license that can be\n+// found in the LICENSE file.\n+\n+import 'package:flutter/rendering.dart';\n+\n+import 'basic.dart';\n+import 'framework.dart';\n+import 'gesture_detector.dart';\n+import 'overlay.dart';\n+\n+// TODO(mpcomplete): Need one for [collapsed].\n+/// Which type of selection handle to be displayed. With mixed-direction text,\n+/// both handles may be the same type. Examples:\n+/// LTR text: 'the <quick brown> fox'\n+///   The '<' is drawn with the [left] type, the '>' with the [right]\n+/// RTL text: 'xof <nworb kciuq> eht'\n+///   Same as above.\n+/// mixed text: '<the nwor<b quick fox'\n+///   Here 'the b' is selected, but 'brown' is RTL. Both are drawn with the\n+///   [left] type.\n+enum TextSelectionHandleType { left, right }\n+\n+/// Builds a handle of the given type.\n+typedef Widget TextSelectionHandleBuilder(BuildContext context, TextSelectionHandleType type);\n+\n+/// The text position that a give selection handle manipulates. Dragging the\n+/// [start] handle always moves the [start]/[baseOffset] of the selection.\n+enum _TextSelectionHandlePosition { start, end }\n+\n+/// Manages a pair of text selection handles to be shown in an Overlay\n+/// containing the owning widget.\n+class TextSelectionHandles {\n+  TextSelectionHandles({\n+    this.selection,\n+    this.renderObject,\n+    this.onSelectionHandleChanged,\n+    this.builder\n+  });\n+\n+  /// A map of a _handles index to Position.\n+  static final List<_TextSelectionHandlePosition> _positions =\n+    <_TextSelectionHandlePosition>[\n+      _TextSelectionHandlePosition.start,\n+      _TextSelectionHandlePosition.end,\n+    ];\n+\n+  // TODO(mpcomplete): what if the renderObject is removed or replaced, or\n+  // moves? Not sure what cases I need to handle, or how to handle them.\n+  final RenderEditableLine renderObject;\n+  final ValueChanged<TextSelection> onSelectionHandleChanged;\n+  final TextSelectionHandleBuilder builder;\n+  TextSelection selection;\n+\n+  /// A pair of handles. If this is non-null, there are always 2, though the\n+  /// second is hidden when the selection is collapsed.\n+  List<OverlayEntry> _handles;\n+\n+  /// Shows the handles by inserting them into the [context]'s overlay.\n+  void show(BuildContext context, { Widget debugRequiredFor }) {\n+    assert(_handles == null);\n+    _handles = [\n+      new OverlayEntry(builder: (BuildContext c) => _buildOverlay(c, 0)),\n+      new OverlayEntry(builder: (BuildContext c) => _buildOverlay(c, 1)),\n+    ];\n+    Overlay.of(context, debugRequiredFor: debugRequiredFor).insertAll(_handles);\n+  }\n+\n+  /// Updates the handles after the [selection] has changed.\n+  void update(TextSelection newSelection) {\n+    selection = newSelection;\n+    _handles[0].markNeedsBuild();\n+    _handles[1].markNeedsBuild();\n+  }\n+\n+  /// Hides the handles.\n+  void hide() {\n+    _handles[0].remove();\n+    _handles[1].remove();\n+    _handles = null;\n+  }\n+\n+  Widget _buildOverlay(BuildContext context, int which) {\n+    if (selection.isCollapsed && which == 1)\n+      return new OffStage(child: null);  // hide the second handle when collapsed\n+    return new _TextSelectionHandleOverlay(\n+      onSelectionHandleChanged: _handleSelectionHandleChanged,\n+      renderObject: renderObject,\n+      selection: selection,\n+      builder: builder,\n+      position: _positions[which]\n+    );\n+  }\n+\n+  void _handleSelectionHandleChanged(TextSelection newSelection) {\n+    if (onSelectionHandleChanged != null)\n+      onSelectionHandleChanged(newSelection);\n+    update(selection);\n+  }\n+}\n+\n+/// This widget represents a single draggable text selection handle.\n+class _TextSelectionHandleOverlay extends StatefulWidget {\n+  _TextSelectionHandleOverlay({\n+    Key key,\n+    this.selection,\n+    this.position,\n+    this.renderObject,\n+    this.onSelectionHandleChanged,\n+    this.builder\n+  }) : super(key: key);\n+\n+  final TextSelection selection;\n+  final _TextSelectionHandlePosition position;\n+  final RenderEditableLine renderObject;\n+  final ValueChanged<TextSelection> onSelectionHandleChanged;\n+  final TextSelectionHandleBuilder builder;\n+\n+  @override\n+  _TextSelectionHandleOverlayState createState() => new _TextSelectionHandleOverlayState();\n+}\n+\n+class _TextSelectionHandleOverlayState extends State<_TextSelectionHandleOverlay> {\n+  Point _dragPosition;\n+  void _handleDragStart(Point position) {\n+    _dragPosition = position;\n+  }\n+\n+  void _handleDragUpdate(double delta) {\n+    _dragPosition += new Offset(delta, 0.0);\n+    TextPosition position = config.renderObject.getPositionForPoint(_dragPosition);\n+\n+    if (config.selection.isCollapsed) {\n+      config.onSelectionHandleChanged(new TextSelection.fromPosition(position));\n+      return;\n+    }\n+\n+    TextSelection newSelection;\n+    switch (config.position) {\n+      case _TextSelectionHandlePosition.start:\n+        newSelection = new TextSelection(\n+          baseOffset: position.offset,\n+          extentOffset: config.selection.extentOffset\n+        );\n+        break;\n+      case _TextSelectionHandlePosition.end:\n+        newSelection = new TextSelection(\n+          baseOffset: config.selection.baseOffset,\n+          extentOffset: position.offset\n+        );\n+        break;\n+    }\n+\n+    if (newSelection.baseOffset >= newSelection.extentOffset)\n+      return; // don't allow order swapping.\n+\n+    config.onSelectionHandleChanged(newSelection);\n+  }\n+\n+  @override\n+  Widget build(BuildContext context) {\n+    List<TextSelectionPoint> endpoints = config.renderObject.getEndpointsForSelection(config.selection);\n+    Point point;\n+    TextSelectionHandleType type;\n+\n+    switch (config.position) {\n+      case _TextSelectionHandlePosition.start:\n+        point = endpoints[0].point;\n+        type = _chooseType(endpoints[0], TextSelectionHandleType.left, TextSelectionHandleType.right);\n+        break;\n+      case _TextSelectionHandlePosition.end:\n+        // [endpoints] will only contain 1 point for collapsed selections, in\n+        // which case we shouldn't be building the [end] handle.\n+        assert(endpoints.length == 2);\n+        point = endpoints[1].point;\n+        type = _chooseType(endpoints[1], TextSelectionHandleType.right, TextSelectionHandleType.left);\n+        break;\n+    }\n+\n+    return new GestureDetector(\n+      onHorizontalDragStart: _handleDragStart,\n+      onHorizontalDragUpdate: _handleDragUpdate,\n+      child: new Stack(\n+        children: <Widget>[\n+          new Positioned(\n+            left: point.x,\n+            top: point.y,\n+            child: _buildChild(context, type)\n+          )\n+        ]\n+      )","path":"packages/flutter/lib/src/widgets/text_selection.dart","position":null,"original_position":191,"commit_id":"c66927a536e1f1681411ee04a2ad7720c4c334b2","original_commit_id":"228759b5388393452714af9034a99e43367d6b15","user":{"login":"abarth","id":112007,"avatar_url":"https://avatars.githubusercontent.com/u/112007?v=3","gravatar_id":"","url":"https://api.github.com/users/abarth","html_url":"https://github.com/abarth","followers_url":"https://api.github.com/users/abarth/followers","following_url":"https://api.github.com/users/abarth/following{/other_user}","gists_url":"https://api.github.com/users/abarth/gists{/gist_id}","starred_url":"https://api.github.com/users/abarth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abarth/subscriptions","organizations_url":"https://api.github.com/users/abarth/orgs","repos_url":"https://api.github.com/users/abarth/repos","events_url":"https://api.github.com/users/abarth/events{/privacy}","received_events_url":"https://api.github.com/users/abarth/received_events","type":"User","site_admin":false},"body":"Stack+Positioned is just a bit of a roundabout way to position something.  There's nothing wrong with it particularly.","created_at":"2016-04-18T23:16:46Z","updated_at":"2016-04-18T23:16:46Z","html_url":"https://github.com/flutter/flutter/pull/3223#discussion_r60150909","pull_request_url":"https://api.github.com/repos/flutter/flutter/pulls/3223","_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments/60150909"},"html":{"href":"https://github.com/flutter/flutter/pull/3223#discussion_r60150909"},"pull_request":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3223"}}},"pull_request":{"url":"https://api.github.com/repos/flutter/flutter/pulls/3223","id":65840328,"html_url":"https://github.com/flutter/flutter/pull/3223","diff_url":"https://github.com/flutter/flutter/pull/3223.diff","patch_url":"https://github.com/flutter/flutter/pull/3223.patch","issue_url":"https://api.github.com/repos/flutter/flutter/issues/3223","number":3223,"state":"open","locked":false,"title":"Add basic text selection to editable text.","user":{"login":"mpcomplete","id":1071986,"avatar_url":"https://avatars.githubusercontent.com/u/1071986?v=3","gravatar_id":"","url":"https://api.github.com/users/mpcomplete","html_url":"https://github.com/mpcomplete","followers_url":"https://api.github.com/users/mpcomplete/followers","following_url":"https://api.github.com/users/mpcomplete/following{/other_user}","gists_url":"https://api.github.com/users/mpcomplete/gists{/gist_id}","starred_url":"https://api.github.com/users/mpcomplete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpcomplete/subscriptions","organizations_url":"https://api.github.com/users/mpcomplete/orgs","repos_url":"https://api.github.com/users/mpcomplete/repos","events_url":"https://api.github.com/users/mpcomplete/events{/privacy}","received_events_url":"https://api.github.com/users/mpcomplete/received_events","type":"User","site_admin":false},"body":"Only partially works. Editing the selected text doesn't work, which\r\nprobably will require engine changes. Currently only draws the selected\r\ntext and allows you to manipulate the selection with draggable selection\r\nhandles.","created_at":"2016-04-08T20:07:50Z","updated_at":"2016-04-18T23:16:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6324f8b37f3ea6018a467cb610ab17ead1f5cf01","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flutter/flutter/pulls/3223/commits","review_comments_url":"https://api.github.com/repos/flutter/flutter/pulls/3223/comments","review_comment_url":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flutter/flutter/issues/3223/comments","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/c66927a536e1f1681411ee04a2ad7720c4c334b2","head":{"label":"mpcomplete:selection","ref":"selection","sha":"c66927a536e1f1681411ee04a2ad7720c4c334b2","user":{"login":"mpcomplete","id":1071986,"avatar_url":"https://avatars.githubusercontent.com/u/1071986?v=3","gravatar_id":"","url":"https://api.github.com/users/mpcomplete","html_url":"https://github.com/mpcomplete","followers_url":"https://api.github.com/users/mpcomplete/followers","following_url":"https://api.github.com/users/mpcomplete/following{/other_user}","gists_url":"https://api.github.com/users/mpcomplete/gists{/gist_id}","starred_url":"https://api.github.com/users/mpcomplete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpcomplete/subscriptions","organizations_url":"https://api.github.com/users/mpcomplete/orgs","repos_url":"https://api.github.com/users/mpcomplete/repos","events_url":"https://api.github.com/users/mpcomplete/events{/privacy}","received_events_url":"https://api.github.com/users/mpcomplete/received_events","type":"User","site_admin":false},"repo":{"id":45862350,"name":"flutter","full_name":"mpcomplete/flutter","owner":{"login":"mpcomplete","id":1071986,"avatar_url":"https://avatars.githubusercontent.com/u/1071986?v=3","gravatar_id":"","url":"https://api.github.com/users/mpcomplete","html_url":"https://github.com/mpcomplete","followers_url":"https://api.github.com/users/mpcomplete/followers","following_url":"https://api.github.com/users/mpcomplete/following{/other_user}","gists_url":"https://api.github.com/users/mpcomplete/gists{/gist_id}","starred_url":"https://api.github.com/users/mpcomplete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpcomplete/subscriptions","organizations_url":"https://api.github.com/users/mpcomplete/orgs","repos_url":"https://api.github.com/users/mpcomplete/repos","events_url":"https://api.github.com/users/mpcomplete/events{/privacy}","received_events_url":"https://api.github.com/users/mpcomplete/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mpcomplete/flutter","description":"The Flutter framework","fork":true,"url":"https://api.github.com/repos/mpcomplete/flutter","forks_url":"https://api.github.com/repos/mpcomplete/flutter/forks","keys_url":"https://api.github.com/repos/mpcomplete/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mpcomplete/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mpcomplete/flutter/teams","hooks_url":"https://api.github.com/repos/mpcomplete/flutter/hooks","issue_events_url":"https://api.github.com/repos/mpcomplete/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/mpcomplete/flutter/events","assignees_url":"https://api.github.com/repos/mpcomplete/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/mpcomplete/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/mpcomplete/flutter/tags","blobs_url":"https://api.github.com/repos/mpcomplete/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mpcomplete/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mpcomplete/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/mpcomplete/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mpcomplete/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/mpcomplete/flutter/languages","stargazers_url":"https://api.github.com/repos/mpcomplete/flutter/stargazers","contributors_url":"https://api.github.com/repos/mpcomplete/flutter/contributors","subscribers_url":"https://api.github.com/repos/mpcomplete/flutter/subscribers","subscription_url":"https://api.github.com/repos/mpcomplete/flutter/subscription","commits_url":"https://api.github.com/repos/mpcomplete/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/mpcomplete/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/mpcomplete/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/mpcomplete/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/mpcomplete/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/mpcomplete/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mpcomplete/flutter/merges","archive_url":"https://api.github.com/repos/mpcomplete/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mpcomplete/flutter/downloads","issues_url":"https://api.github.com/repos/mpcomplete/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/mpcomplete/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/mpcomplete/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/mpcomplete/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mpcomplete/flutter/labels{/name}","releases_url":"https://api.github.com/repos/mpcomplete/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/mpcomplete/flutter/deployments","created_at":"2015-11-09T19:43:57Z","updated_at":"2015-11-09T19:43:59Z","pushed_at":"2016-04-15T19:37:05Z","git_url":"git://github.com/mpcomplete/flutter.git","ssh_url":"git@github.com:mpcomplete/flutter.git","clone_url":"https://github.com/mpcomplete/flutter.git","svn_url":"https://github.com/mpcomplete/flutter","homepage":"http://flutter.io","size":15862,"stargazers_count":0,"watchers_count":0,"language":"Dart","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"flutter:master","ref":"master","sha":"d5d4e7c05432414bd154a898583b8894f3332074","user":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"repo":{"id":31792824,"name":"flutter","full_name":"flutter/flutter","owner":{"login":"flutter","id":14101776,"avatar_url":"https://avatars.githubusercontent.com/u/14101776?v=3","gravatar_id":"","url":"https://api.github.com/users/flutter","html_url":"https://github.com/flutter","followers_url":"https://api.github.com/users/flutter/followers","following_url":"https://api.github.com/users/flutter/following{/other_user}","gists_url":"https://api.github.com/users/flutter/gists{/gist_id}","starred_url":"https://api.github.com/users/flutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flutter/subscriptions","organizations_url":"https://api.github.com/users/flutter/orgs","repos_url":"https://api.github.com/users/flutter/repos","events_url":"https://api.github.com/users/flutter/events{/privacy}","received_events_url":"https://api.github.com/users/flutter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flutter/flutter","description":"Framework for building high-performance, high-fidelity iOS and Android apps","fork":false,"url":"https://api.github.com/repos/flutter/flutter","forks_url":"https://api.github.com/repos/flutter/flutter/forks","keys_url":"https://api.github.com/repos/flutter/flutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flutter/flutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flutter/flutter/teams","hooks_url":"https://api.github.com/repos/flutter/flutter/hooks","issue_events_url":"https://api.github.com/repos/flutter/flutter/issues/events{/number}","events_url":"https://api.github.com/repos/flutter/flutter/events","assignees_url":"https://api.github.com/repos/flutter/flutter/assignees{/user}","branches_url":"https://api.github.com/repos/flutter/flutter/branches{/branch}","tags_url":"https://api.github.com/repos/flutter/flutter/tags","blobs_url":"https://api.github.com/repos/flutter/flutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flutter/flutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flutter/flutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/flutter/flutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flutter/flutter/statuses/{sha}","languages_url":"https://api.github.com/repos/flutter/flutter/languages","stargazers_url":"https://api.github.com/repos/flutter/flutter/stargazers","contributors_url":"https://api.github.com/repos/flutter/flutter/contributors","subscribers_url":"https://api.github.com/repos/flutter/flutter/subscribers","subscription_url":"https://api.github.com/repos/flutter/flutter/subscription","commits_url":"https://api.github.com/repos/flutter/flutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/flutter/flutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/flutter/flutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/flutter/flutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/flutter/flutter/contents/{+path}","compare_url":"https://api.github.com/repos/flutter/flutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flutter/flutter/merges","archive_url":"https://api.github.com/repos/flutter/flutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flutter/flutter/downloads","issues_url":"https://api.github.com/repos/flutter/flutter/issues{/number}","pulls_url":"https://api.github.com/repos/flutter/flutter/pulls{/number}","milestones_url":"https://api.github.com/repos/flutter/flutter/milestones{/number}","notifications_url":"https://api.github.com/repos/flutter/flutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flutter/flutter/labels{/name}","releases_url":"https://api.github.com/repos/flutter/flutter/releases{/id}","deployments_url":"https://api.github.com/repos/flutter/flutter/deployments","created_at":"2015-03-06T22:54:58Z","updated_at":"2016-04-18T20:10:52Z","pushed_at":"2016-04-18T22:32:09Z","git_url":"git://github.com/flutter/flutter.git","ssh_url":"git@github.com:flutter/flutter.git","clone_url":"https://github.com/flutter/flutter.git","svn_url":"https://github.com/flutter/flutter","homepage":"http://flutter.io","size":109670,"stargazers_count":2748,"watchers_count":2748,"language":"Dart","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":278,"mirror_url":null,"open_issues_count":833,"forks":278,"open_issues":833,"watchers":2748,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3223"},"html":{"href":"https://github.com/flutter/flutter/pull/3223"},"issue":{"href":"https://api.github.com/repos/flutter/flutter/issues/3223"},"comments":{"href":"https://api.github.com/repos/flutter/flutter/issues/3223/comments"},"review_comments":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3223/comments"},"review_comment":{"href":"https://api.github.com/repos/flutter/flutter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flutter/flutter/pulls/3223/commits"},"statuses":{"href":"https://api.github.com/repos/flutter/flutter/statuses/c66927a536e1f1681411ee04a2ad7720c4c334b2"}}}}