Merge "Handle diff selection edge case"
This commit is contained in:
@@ -156,11 +156,10 @@
|
||||
|
||||
/**
|
||||
* Adjust triple click selection for the whole line.
|
||||
* domRange.endContainer may be one of the following:
|
||||
* 1) 0 offset at right column's line number cell, or
|
||||
* 2) 0 offset at left column's line number at the next line.
|
||||
* Case 1 means left column was triple clicked.
|
||||
* Case 2 means right column or unified view triple clicked.
|
||||
* A triple click always results in:
|
||||
* - start.column == end.column == 0
|
||||
* - end.line == start.line + 1
|
||||
*
|
||||
* @param {!Object} range Normalized range, ie column/line numbers
|
||||
* @param {!Range} domRange DOM Range object
|
||||
* @return {!Object} fixed normalized range
|
||||
@@ -172,20 +171,13 @@
|
||||
}
|
||||
const start = range.start;
|
||||
const end = range.end;
|
||||
const endsAtOtherSideLineNum =
|
||||
domRange.endOffset === 0 &&
|
||||
domRange.endContainer.nodeName === 'TD' &&
|
||||
(domRange.endContainer.classList.contains('left') ||
|
||||
domRange.endContainer.classList.contains('right'));
|
||||
const endsOnOtherSideStart = endsAtOtherSideLineNum ||
|
||||
end &&
|
||||
const endsAtBeginningOfNextLine = end &&
|
||||
start.column === 0 &&
|
||||
end.column === 0 &&
|
||||
end.line === start.line &&
|
||||
end.side != start.side;
|
||||
end.line === start.line + 1;
|
||||
const content = domRange.cloneContents().querySelector('.contentText');
|
||||
const lineLength = content && this._getLength(content) || 0;
|
||||
if (lineLength && endsOnOtherSideStart || endsAtOtherSideLineNum) {
|
||||
// Selection ends at the beginning of the next line.
|
||||
if (lineLength && endsAtBeginningOfNextLine) {
|
||||
// Move the selection to the end of the previous line.
|
||||
range.end = {
|
||||
node: start.node,
|
||||
|
@@ -576,54 +576,18 @@ limitations under the License.
|
||||
assert.equal(result, 0);
|
||||
});
|
||||
|
||||
// TODO (viktard): Selection starts in line number.
|
||||
// TODO (viktard): Empty lines in selection start.
|
||||
// TODO (viktard): Empty lines in selection end.
|
||||
// TODO (viktard): Only empty lines selected.
|
||||
// TODO (viktard): Unified mode.
|
||||
|
||||
suite('triple click', () => {
|
||||
test('_fixTripleClickSelection', () => {
|
||||
const fakeRange = {
|
||||
startContainer: '',
|
||||
startOffset: '',
|
||||
endContainer: '',
|
||||
endOffset: '',
|
||||
};
|
||||
const fixedRange = {};
|
||||
sandbox.stub(GrRangeNormalizer, 'normalize').returns(fakeRange);
|
||||
sandbox.stub(element, '_normalizeSelectionSide');
|
||||
sandbox.stub(element, '_fixTripleClickSelection').returns(fixedRange);
|
||||
assert.strictEqual(element._normalizeRange({}), fixedRange);
|
||||
assert.isTrue(element._fixTripleClickSelection.called);
|
||||
});
|
||||
|
||||
test('left pane', () => {
|
||||
const startNode = stubContent(138, 'left');
|
||||
const endNode =
|
||||
stubContent(119, 'right').parentElement.previousElementSibling;
|
||||
builder.getLineNumberByChild.withArgs(endNode).returns(119);
|
||||
emulateSelection(startNode, 0, endNode, 0);
|
||||
assert.deepEqual(getActionRange(), {
|
||||
startLine: 138,
|
||||
startChar: 0,
|
||||
endLine: 138,
|
||||
endChar: 63,
|
||||
});
|
||||
});
|
||||
|
||||
test('right pane', () => {
|
||||
const startNode = stubContent(119, 'right');
|
||||
const endNode =
|
||||
stubContent(140, 'left').parentElement.previousElementSibling;
|
||||
emulateSelection(startNode, 0, endNode, 0);
|
||||
assert.deepEqual(getActionRange(), {
|
||||
startLine: 119,
|
||||
startChar: 0,
|
||||
endLine: 119,
|
||||
endChar: 63,
|
||||
});
|
||||
test('_fixTripleClickSelection', () => {
|
||||
const startContent = stubContent(119, 'right');
|
||||
const endContent = stubContent(120, 'right');
|
||||
emulateSelection(startContent.firstChild, 0, endContent.firstChild, 0);
|
||||
assert.isTrue(element.isRangeSelected());
|
||||
assert.deepEqual(getActionRange(), {
|
||||
startLine: 119,
|
||||
startChar: 0,
|
||||
endLine: 119,
|
||||
endChar: element._getLength(startContent),
|
||||
});
|
||||
assert.equal(getActionSide(), 'right');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user