Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffChangesetList.js
Show First 20 Lines • Show All 435 Lines • ▼ Show 20 Lines | _onKeyCreate: function() { | ||||
this._warnUser( | this._warnUser( | ||||
pht( | pht( | ||||
'You must select source text to create a new inline comment.')); | 'You must select source text to create a new inline comment.')); | ||||
return; | return; | ||||
} | } | ||||
this._setSourceSelection(null, null); | this._setSourceSelection(null, null); | ||||
var config = { | |||||
startOffset: start.offset, | |||||
endOffset: end.offset | |||||
}; | |||||
var changeset = start.changeset; | var changeset = start.changeset; | ||||
var config = {}; | |||||
if (changeset.getResponseDocumentEngineKey() === null) { | |||||
// If the changeset is using a document renderer, we ignore the | |||||
// selection range and just treat this as a comment from the first | |||||
// block to the last block. | |||||
// If we don't discard the range, we later render a bogus highlight | |||||
// if the block content is complex (like a Jupyter notebook cell | |||||
// with images). | |||||
config.startOffset = start.offset; | |||||
config.endOffset = end.offset; | |||||
} | |||||
changeset.newInlineForRange(start.targetNode, end.targetNode, config); | changeset.newInlineForRange(start.targetNode, end.targetNode, config); | ||||
}, | }, | ||||
_onkeydone: function() { | _onkeydone: function() { | ||||
var cursor = this._cursorItem; | var cursor = this._cursorItem; | ||||
if (cursor) { | if (cursor) { | ||||
if (cursor.type == 'comment') { | if (cursor.type == 'comment') { | ||||
▲ Show 20 Lines • Show All 2,160 Lines • ▼ Show 20 Lines | _getFragmentLocation: function(fragment) { | ||||
if (JX.DOM.isType(fragment.parentNode, 'tr')) { | if (JX.DOM.isType(fragment.parentNode, 'tr')) { | ||||
// Assume this is Safari, and that the user has carefully selected a | // Assume this is Safari, and that the user has carefully selected a | ||||
// row and then moved their mouse down a few pixels to select the | // row and then moved their mouse down a few pixels to select the | ||||
// invisible fragment at the beginning of the next row. | // invisible fragment at the beginning of the next row. | ||||
var cells = fragment.parentNode.previousSibling.childNodes; | var cells = fragment.parentNode.previousSibling.childNodes; | ||||
td = cells[cells.length - 1]; | td = cells[cells.length - 1]; | ||||
is_end = true; | is_end = true; | ||||
} else { | } else { | ||||
td = JX.DOM.findAbove(fragment, 'td'); | td = this._findContentCell(fragment); | ||||
is_end = false; | is_end = false; | ||||
} | } | ||||
var cursor = td; | var cursor = td; | ||||
while (cursor) { | while (cursor) { | ||||
if (cursor.getAttribute('data-copy-mode')) { | if (cursor.getAttribute('data-copy-mode')) { | ||||
column_count++; | column_count++; | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | _getFragmentLocation: function(fragment) { | ||||
line: line, | line: line, | ||||
displayColumn: column_count, | displayColumn: column_count, | ||||
offset: offset, | offset: offset, | ||||
targetNode: target_node | targetNode: target_node | ||||
}; | }; | ||||
}, | }, | ||||
_getSelectionOffset: function(node, target) { | _getSelectionOffset: function(node, target) { | ||||
// If this is an aural hint node in a unified diff, ignore it when | |||||
// calculating the selection offset. | |||||
if (node.getAttribute && node.getAttribute('data-aural')) { | |||||
return { | |||||
offset: 0, | |||||
content: '', | |||||
found: false | |||||
}; | |||||
} | |||||
if (!node.childNodes || !node.childNodes.length) { | if (!node.childNodes || !node.childNodes.length) { | ||||
return { | return { | ||||
offset: node.textContent.length, | offset: node.textContent.length, | ||||
content: node.textContent, | content: node.textContent, | ||||
found: false | found: false | ||||
}; | }; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | _getSelectedRanges: function() { | ||||
ranges.push(range); | ranges.push(range); | ||||
} | } | ||||
return ranges; | return ranges; | ||||
}, | }, | ||||
_isContentCell: function(node) { | _isContentCell: function(node) { | ||||
return !!node.getAttribute('data-copy-mode'); | return !!node.getAttribute('data-copy-mode'); | ||||
}, | |||||
_findContentCell: function(node) { | |||||
var cursor = node; | |||||
while (true) { | |||||
cursor = JX.DOM.findAbove(cursor, 'td'); | |||||
if (this._isContentCell(cursor)) { | |||||
return cursor; | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
}); | }); |