Expand (not open) if user prefers inline diffs
Pressing enter or 'o' with no modifier key has three modes of behavior. 1. Show diffs: in this mode this keypress always acts on the diff cursor 2. Expand diffs inline: if user has this preference, expand current file 3. Otherwise: navigate to diff view of current file Bug: Issue 6067 Change-Id: I64bbe0720ddac54a4dc7fbca6df87aa95321442f
This commit is contained in:
@@ -519,6 +519,9 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (this._showInlineDiffs) {
|
if (this._showInlineDiffs) {
|
||||||
this._openCursorFile();
|
this._openCursorFile();
|
||||||
|
} else if (this._userPrefs && this._userPrefs.expand_inline_diffs) {
|
||||||
|
if (this.$.fileCursor.index === -1) { return; }
|
||||||
|
this._togglePathExpandedByIndex(this.$.fileCursor.index);
|
||||||
} else {
|
} else {
|
||||||
this._openSelectedFile();
|
this._openSelectedFile();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -381,42 +381,70 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_handleEnterKey navigates', function() {
|
suite('_handleEnterKey', function() {
|
||||||
sandbox.stub(element, 'shouldSuppressKeyboardShortcut').returns(false);
|
var interact;
|
||||||
sandbox.stub(element, 'modifierPressed').returns(false);
|
|
||||||
var expandStub = sandbox.stub(element, '_openCursorFile');
|
|
||||||
var navStub = sandbox.stub(element, '_openSelectedFile');
|
|
||||||
var e = new CustomEvent('fake-keyboard-event');
|
|
||||||
sinon.stub(e, 'preventDefault');
|
|
||||||
element._showInlineDiffs = false;
|
|
||||||
element._handleEnterKey(e);
|
|
||||||
assert.isTrue(e.preventDefault.called);
|
|
||||||
assert.isTrue(navStub.called);
|
|
||||||
assert.isFalse(expandStub.called);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('_handleEnterKey expands', function() {
|
setup(function() {
|
||||||
sandbox.stub(element, 'shouldSuppressKeyboardShortcut').returns(false);
|
sandbox.stub(element, 'shouldSuppressKeyboardShortcut')
|
||||||
sandbox.stub(element, 'modifierPressed').returns(false);
|
.returns(false);
|
||||||
var expandStub = sandbox.stub(element, '_openCursorFile');
|
sandbox.stub(element, 'modifierPressed').returns(false);
|
||||||
var navStub = sandbox.stub(element, '_openSelectedFile');
|
var openCursorStub = sandbox.stub(element, '_openCursorFile');
|
||||||
var e = new CustomEvent('fake-keyboard-event');
|
var openSelectedStub = sandbox.stub(element, '_openSelectedFile');
|
||||||
sinon.stub(e, 'preventDefault');
|
var expandStub = sandbox.stub(element, '_togglePathExpanded');
|
||||||
element._showInlineDiffs = true;
|
|
||||||
element._handleEnterKey(e);
|
|
||||||
assert.isTrue(e.preventDefault.called);
|
|
||||||
assert.isFalse(navStub.called);
|
|
||||||
assert.isTrue(expandStub.called);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('_handleEnterKey noop when anchor focused', function() {
|
interact = function(opt_payload) {
|
||||||
sandbox.stub(element, 'shouldSuppressKeyboardShortcut').returns(false);
|
openCursorStub.reset();
|
||||||
sandbox.stub(element, 'modifierPressed').returns(false);
|
openSelectedStub.reset();
|
||||||
var e = new CustomEvent('fake-keyboard-event',
|
expandStub.reset();
|
||||||
{detail: {keyboardEvent: {target: document.createElement('a')}}});
|
|
||||||
sinon.stub(e, 'preventDefault');
|
var e = new CustomEvent('fake-keyboard-event', opt_payload);
|
||||||
element._handleEnterKey(e);
|
sinon.stub(e, 'preventDefault');
|
||||||
assert.isFalse(e.preventDefault.called);
|
element._handleEnterKey(e);
|
||||||
|
assert.isTrue(e.preventDefault.called);
|
||||||
|
var result = {};
|
||||||
|
if (openCursorStub.called) {
|
||||||
|
result.opened_cursor = true;
|
||||||
|
}
|
||||||
|
if (openSelectedStub.called) {
|
||||||
|
result.opened_selected = true;
|
||||||
|
}
|
||||||
|
if (expandStub.called) {
|
||||||
|
result.expanded = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
test('open from selected file', function() {
|
||||||
|
element._showInlineDiffs = false;
|
||||||
|
assert.deepEqual(interact(), {opened_selected: true});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('open from diff cursor', function() {
|
||||||
|
element._showInlineDiffs = true;
|
||||||
|
assert.deepEqual(interact(), {opened_cursor: true});
|
||||||
|
|
||||||
|
// "Show diffs" mode overrides userPrefs.expand_inline_diffs
|
||||||
|
element._userPrefs = {expand_inline_diffs: true};
|
||||||
|
assert.deepEqual(interact(), {opened_cursor: true});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('expand when user prefers', function() {
|
||||||
|
element._showInlineDiffs = false;
|
||||||
|
assert.deepEqual(interact(), {opened_selected: true});
|
||||||
|
element._userPrefs = {};
|
||||||
|
assert.deepEqual(interact(), {opened_selected: true});
|
||||||
|
element._userPrefs.expand_inline_diffs = true;
|
||||||
|
assert.deepEqual(interact(), {expanded: true});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('noop when anchor focused', function() {
|
||||||
|
var e = new CustomEvent('fake-keyboard-event',
|
||||||
|
{detail: {keyboardEvent: {target: document.createElement('a')}}});
|
||||||
|
sinon.stub(e, 'preventDefault');
|
||||||
|
element._handleEnterKey(e);
|
||||||
|
assert.isFalse(e.preventDefault.called);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user