Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffChangesetList.js
| Show First 20 Lines • Show All 2,226 Lines • ▼ Show 20 Lines | |||||
| _onSelectRange: function(e) { | _onSelectRange: function(e) { | ||||
| this._updateSourceSelection(); | this._updateSourceSelection(); | ||||
| }, | }, | ||||
| _updateSourceSelection: function() { | _updateSourceSelection: function() { | ||||
| var ranges = this._getSelectedRanges(); | var ranges = this._getSelectedRanges(); | ||||
| // If we have zero or more than one range, don't do anything. | // In Firefox, selecting multiple rows gives us multiple ranges. In | ||||
| if (ranges.length === 1) { | // Safari and Chrome, we get a single range. | ||||
| for (var ii = 0; ii < ranges.length; ii++) { | if (!ranges.length) { | ||||
| var range = ranges[ii]; | this._setSourceSelection(null, null); | ||||
| return; | |||||
| } | |||||
| var head = range.startContainer; | var min = 0; | ||||
| var last = range.endContainer; | var max = ranges.length - 1; | ||||
| var head = ranges[min].startContainer; | |||||
| var last = ranges[max].endContainer; | |||||
| var head_loc = this._getFragmentLocation(head); | var head_loc = this._getFragmentLocation(head); | ||||
| var last_loc = this._getFragmentLocation(last); | var last_loc = this._getFragmentLocation(last); | ||||
| if (head_loc === null || last_loc === null) { | if (head_loc === null || last_loc === null) { | ||||
| break; | this._setSourceSelection(null, null); | ||||
| return; | |||||
| } | } | ||||
| if (head_loc.changesetID !== last_loc.changesetID) { | if (head_loc.changesetID !== last_loc.changesetID) { | ||||
| break; | this._setSourceSelection(null, null); | ||||
| return; | |||||
| } | } | ||||
| head_loc.offset += range.startOffset; | head_loc.offset += ranges[min].startOffset; | ||||
| last_loc.offset += range.endOffset; | last_loc.offset += ranges[max].endOffset; | ||||
| this._setSourceSelection(head_loc, last_loc); | this._setSourceSelection(head_loc, last_loc); | ||||
| return; | |||||
| } | |||||
| } | |||||
| this._setSourceSelection(null, null); | |||||
| }, | }, | ||||
| _setSourceSelection: function(start, end) { | _setSourceSelection: function(start, end) { | ||||
| var start_updated = | var start_updated = | ||||
| !this._isSameSourceSelection(this._sourceSelectionStart, start); | !this._isSameSourceSelection(this._sourceSelectionStart, start); | ||||
| var end_updated = | var end_updated = | ||||
| !this._isSameSourceSelection(this._sourceSelectionEnd, end); | !this._isSameSourceSelection(this._sourceSelectionEnd, end); | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | _getFragmentLocation: function(fragment) { | ||||
| } | } | ||||
| } catch (ex) { | } catch (ex) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| // Find the line number and display column for the fragment. | // Find the line number and display column for the fragment. | ||||
| var line = null; | var line = null; | ||||
| var column_count = -1; | var column_count = -1; | ||||
| var has_new = false; | |||||
| var has_old = false; | |||||
| var offset = null; | var offset = null; | ||||
| var target_node = null; | var target_node = null; | ||||
| var td; | var td; | ||||
| try { | try { | ||||
| // NOTE: In Safari, you can carefully select an entire line and then | // NOTE: In Safari, you can carefully select an entire line and then | ||||
| // move your mouse down slightly, causing selection of an empty | // move your mouse down slightly, causing selection of an empty | ||||
| // document fragment which is an immediate child of the next "<tr />". | // document fragment which is an immediate child of the next "<tr />". | ||||
| Show All 17 Lines | _getFragmentLocation: function(fragment) { | ||||
| td = JX.DOM.findAbove(fragment, 'td'); | td = JX.DOM.findAbove(fragment, 'td'); | ||||
| 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 { | |||||
| // In unified mode, the content column isn't currently marked | |||||
| // with an attribute, and we can't count content columns anyway. | |||||
| // Keep track of whether or not we see a "NL" (New Line) column | |||||
| // and/or an "OL" (Old Line) column to try to puzzle out which | |||||
| // side of the display change we're on. | |||||
| if (cursor.id.match(/NL/)) { | |||||
| has_new = true; | |||||
| } else if (cursor.id.match(/OL/)) { | |||||
| has_old = true; | |||||
| } | |||||
| } | } | ||||
| var n = parseInt(cursor.getAttribute('data-n')); | var n = parseInt(cursor.getAttribute('data-n')); | ||||
| if (n) { | if (n) { | ||||
| if (line === null) { | if (line === null) { | ||||
| target_node = cursor; | target_node = cursor; | ||||
| line = n; | line = n; | ||||
| } | } | ||||
| } | } | ||||
| cursor = cursor.previousSibling; | cursor = cursor.previousSibling; | ||||
| } | } | ||||
| if (!line) { | if (!line) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| if (column_count < 0) { | if (column_count < 0) { | ||||
| if (has_new || has_old) { | |||||
| if (has_new) { | |||||
| column_count = 1; | |||||
| } else { | |||||
| column_count = 0; | |||||
| } | |||||
| } else { | |||||
| return null; | return null; | ||||
| } | } | ||||
| } | |||||
| var seen = 0; | var seen = 0; | ||||
| for (var ii = 0; ii < td.childNodes.length; ii++) { | for (var ii = 0; ii < td.childNodes.length; ii++) { | ||||
| var child = td.childNodes[ii]; | var child = td.childNodes[ii]; | ||||
| if (child === fragment) { | if (child === fragment) { | ||||
| offset = seen; | offset = seen; | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||