13 Commits

Author SHA1 Message Date
Wyatt Allen
d0dd392794 Establish annotation pipeline
Apply diff annotations (intraline differences and comment ranges) by
executing the annotation layers in order to each line. The diff builder
maintains an ordered array of annotation layers which are communicated
to GrDiffBuilder subclass instances. The builder also listens to each
layer for notifications that annotations have changed for some line
range and re-renders (i.e. re-applies the pipeline on DIV.contentText
elements) accordingly.

Change-Id: Iea0599d4869cafaadc0974158153a91d927913e8
2016-07-20 12:25:40 -07:00
Viktar Donich
60d8bce771 Release range comments
Remove beta diff setting and enable range comments for all.

Change-Id: I0cee7e1717574ab54317cdce9e2332c8cda7a0cb
2016-07-14 14:45:15 -07:00
Viktar Donich
056fa71f5d Range comments tabs fixes
- Allow range comments to start at a tab.
- Preserve tabs within selected comment range.

Bug: Issue 4253
Change-Id: Ia1ebdcc2e22a1fdad9619cf9ded5db3c80ebe648
2016-07-14 12:39:33 -07:00
Wyatt Allen
3d2e13c21b Organizes gr-annotation tests and fixes splitTextNode bug
Moves the tests for gr-annotation functions into their own test file and
fixes a subtle bug regarding `splitTextNode`'s Unicode branch.

In the DOM implementation of `node.splitText`, `node` is kept in the DOM
and its `textContent` is modified, whereas the Unicode path of
`splitTextNode` would replace it with an entirely new Text node. This
led to the function behaving differently when the Node contained or
did not contain astral code-points.

With this change, `splitTextNode` more-closely behaves like `splitText`
and this behavior is captured in a new unit-test.

Change-Id: I70460694040ba9a3c49937aaafc9db261ca3be3d
2016-07-13 16:06:09 -07:00
Wyatt Allen
dd0adf26aa Adds general annotation function to gr-annotation
Adds the `annotateElement` function to the gr-annotation library, which
applies an annotation to an element's text at the specified range as
deeply as possible.

Change-Id: I5e38a9718fc00df860e8b12a16e551ccc1b57722
2016-07-12 18:39:35 +00:00
Wyatt Allen
025e65d7d5 Reorganized DOM for diff content in PolyGerrit
Formerly, diff content elements mixed text with comment threads. For
example, a diff content node with an intraline highlight, a ranged
comment, and a gr-diff-comment-thread may have been organized as below:

    TD.content
      ╠ #text
      ╠ HL (intraline difference)
      ║ ╚ #text
      ╠ #text
      ╠ HL.range (ranged comment highlight)
      ║ ╚ #text
      ╠ #text
      ╚ GR-DIFF-COMMENT-THREAD
        ╠ GR-DIFF-COMMENT
        ╚ ...

Note that the comment thread was inserted at the same level as the text
of the diff line.

With this change, the text is separated from the comment thread by
introducing a DIV to contain the text with class `contentText` as
sibling to comment threads.

    TD.content
      ╠ DIV.contentText
      ║ ╠ #text
      ║ ╠ HL
      ║ ║ ╚ #text
      ║ ╠ #text
      ║ ╠ HL.range
      ║ ║ ╚ #text
      ║ ╚ #text
      ╚ GR-DIFF-COMMENT-THREAD
        ╠ GR-DIFF-COMMENT
        ╚ ...

Modifies the `getContentByLine` method of gr-diff-builder to return the
`DIV.contentText` element rather than the `TD.content` element which is
its parent. In most uses of this function, the text is what is needed
rather than the TD or comment thread, but in other cases, they can be
easily DOM traversed.

Change-Id: I0eded34afd3d22963252efc7eabfee290ae21a9c
2016-07-11 11:20:09 -07:00
Wyatt Allen
1678d988ae Addresses a gr-diff-highlight edge case
It was possible to cause a JS error when creating a ranged comment that
started at the very end of the first line (selecting no content on that
line). The relevant null-guard needed an additional set of parens to
avoid evaluating the second OR operand with a bad argument in this case.

Addresses the null-guard boolean expressions in `_normalizeStart` and
`_normalizeEnd` and reduces the number of calls to  `_getLength` from
thrice to once per iteration. Adds a relevant unit test.

Change-Id: I98848f9f6089fd3240bda175765770c9f9c5ba30
2016-07-01 13:25:41 -07:00
Viktar Donich
e88b612e29 Handle tabs for range comments
Changes:
- wrapping in HL now adds cssClass instead of discarding previous ones.
- getLength accounts for tab tags correctly.
- generic splitNode, potentially should be moved into util.
- more tests.

Feature: Issue 3915
Change-Id: Id8a646a5de4fd702aa112678c039df9ff8dd8c0b
2016-06-28 15:31:14 -07:00
Viktar Donich
b74a83162f Range comments select-to-create
Creates action box, that creates range comment on mouse down and hotkey
over selected text in diff. Makes best effort in guessing correct start
and end points for the selection.

Known issues listed as TODO items in test and code.

Feature: Issue 3915
Change-Id: I0a3e41d062e559c8cdb4b847829429f65622eb72
2016-06-27 10:21:27 -07:00
Viktar Donich
ea19586d19 Show comment ranges on render and context expand
Feature: Issue 3910
Change-Id: I9590d03b70e845b4f5ebe2f951f080ba3c9dc8db
2016-06-23 09:55:06 -07:00
Viktar Donich
3d6f8d695b Comment events wiring for ranged comments
Listen and update diff on comment events:
- call appropriate methods to apply comment ranges on comment creation
- re-render diff on and thread comment discard
- apply highlight on comment mouse over
- remove highlight on comment mouse out
- tests for all above

Feature: Issue 3910
Change-Id: I501ddcd063407777355b9c887118fcae53dcb5f1
2016-06-23 09:54:48 -07:00
Viktar Donich
d9b1f53a6a Apply range comments and highlights
Utility methods for applying comment range highlights to diff, with
tests including some of the corner cases.

Feature: Issue 3910
Change-Id: Id7de2dd4ff027ce96479a2d596e9414a0cadd6bf
2016-06-23 09:49:54 -07:00
Viktar Donich
ab1b211d80 Ranged highlights: initial commit
- Initial commit: structure, 'enabled' property controls sample
mouseDown handler.
- Minimal integration: isRangeSelected
- Minimal test.

Change-Id: I963ac7b158d57a1c24ee302d99eb6af26b0aeeeb
2016-06-13 14:38:08 -07:00