12 Commits

Author SHA1 Message Date
Kasper Nilsson
1ba850e594 Fix comment copy logic
The addition of formatting in comments broke a variety of things having
to do with the copying logic. This change updates the logic and tests
to reflect the new DOM.

This issue arose because of a lack of integration tests for copying and
selection. That test is coming in a descendant change.

Bug: Issue 4969
Change-Id: I4e1994ab07947506c77b07877a46a9369d666d50
2016-12-02 15:25:27 -08:00
Kasper Nilsson
bc0c634347 Fix copy within same line
When the text selection exists within one line in diff-view, the
derivation of the selected text from the diff object using substring()
mutated the text and caused some selections to be artificially long.
Swapping the calls so that the end of the string is trimmed off first
fixes this.

This change also includes a regression test for this issue.

Bug: Issue 4794
Change-Id: I19dbab1cddd2e522cc6495011e8ef49f8ffe55b2
2016-10-20 10:30:55 -07:00
Kasper Nilsson
848371e628 Fix copy behavior in comment textarea
Deferring to default copy behavior when copying within diff comment
textareas allows the browser to handle copying. Also includes a
regression test.

Bug: Issue 4624
Change-Id: Ib976dd5055cf0ede89591ab2f483aa8d264a5484
2016-10-13 13:55:05 -07:00
Kasper Nilsson
a742ae3999 Fix DOM traversal of copy process for comments
The comment selection process was being performed incorrectly due to
lack of utilization of Polymer.dom. This uncovered a few more issues
with the way the fake copy events in testing were being constructed and
a base case in comment text selection.

Bug: Issue 4674
Change-Id: I7e05b7ebe0bfd60bc9cc8973166685c24e25ab37
2016-10-04 17:57:23 -07:00
Kasper Nilsson
708d34fb1f Fix comment selection and copy behavior
This change adds logic that applies a CSS class whenever mouseDown
occurs inside of a comment thread that makes comment messages
highlightable. This replicates the existing functionality of GWTUI. In
addition, logic for copying the messages of multiple comments at once
is included.

Bug: Issue 4494
Change-Id: Id8e49e500c8d48dbba661b885050657dd4cfc0be
2016-09-16 13:51:13 -07:00
Wyatt Allen
b1fbd9b310 Normalize selection ranges for copy
At the time that syntax highlighting DOM was introduced, the offsets of
selection ranges had been broken. In change [1] Kasper fixed this for
GR-DIFF-HIGHLIGHT with selection normalization functions. However,
selections for copying code as implemented in GR-DIFF-SELECTION were
still un-normalized.

With this change, the normalization functionality introduced in [1] is
moved to a JS library so that it can be used by both components. Tests
are updated.

[1] I26c61ca706575ea5df6e3b7b18a27225834396e8

Change-Id: I35ab0f71a46b3fc1d7356a314a0cae856f2ef28e
2016-09-14 10:13:46 -07:00
Wyatt Allen
9fcec7437f Generate clipboard data via diff rather than DOM reconstruction
This change uses a new method of generating the clipboard data that
circumvents several strange issues caused by shadow/shady DOM. This
new method is much more legible and abstracts more logic away from the
DOM.

Bug: Issue 4494
Change-Id: I8c186d6cbbe9536548d934f734856b1f9ced1a26
2016-09-13 14:24:57 -07:00
Kasper Nilsson
8bfab3ff24 Hotfix Safari WCT issues
This change fixes two minor issues in Safari.
- In gr-diff-highlight, Safari does not support NodeList.forEach.
- In gr-diff-selection_test, a test that should have been failing (a
  selection class was missing) was not being run in Chrome/CI. A prior
  commit modified the CSS selectors that enable text selection, and the
  test was not changed to reflect this.

  SHA of the offending commit: 613b49c

Change-Id: I7ef3b017be9ae731496609430e3856f58e5bd24e
2016-09-07 23:39:06 +00:00
Kasper Nilsson
613b49c64e Fix copy/paste in diff view
The addition of syntax highlighting silently broke copy/paste
functionality due to the addition of another layer of div nesting.

Related to this bug are some issues with correct text selection in
unified diff view, so this patch addresses them as well.

Bug: Issue 4317
Change-Id: Iac7379de4131ab4e44905a54218d42fcfe67ce62
2016-08-29 16:18:47 -07:00
Wyatt Allen
0490413eb8 Applies optimizations to GR-DIFF-SELECTION
A major source of latency in creating comments in large diffs stems from
GR-DIFF-SELECTION applying selection-restricting classes to a parent of
the diff. When the diff contains a large number of lines (and thus a
large number of elements) applying a class forces a style recompute for
the substantial subtree.

This change optimizes this in two ways:

* **Initialize to the right side:** The selection-restricting class is
  initialized to the right side, before the diff is even completely
  built. This eliminates the need for a recomputation preceding the
  first comment add on the right side (the most-likely side to be
  interacted with).
* **Minimize the number of class modifications:** only add or remove
  classes when necessary. This eliminates recomputes for consecutive
  mousedown events that occur on the a common diff side.

On an i7 MBP, this eliminates ~120ms for the first comment on the right
and ~40ms for subsequent such comments.

Change-Id: Ibb8a7eca0398a5c7265dc1385967bce3dae5e5ef
2016-08-10 11:47:27 -07:00
Viktar Donich
01c211af6e Gr-diff-selection tests to work in Safari
Change-Id: I31e232acf4d53d521d38d6b2b14f5c39146c05d1
2016-06-13 14:32:24 -07:00
Viktar Donich
e1341972d1 Move text selection out of gr-diff.
Change-Id: I0734653066a1bb78f95c141aa8202fad315b13c0
2016-06-10 12:18:25 -07:00