Merge pull request #2678 from CatoTH/goto-line-numbers-always-available
Make line highlighting and 'Goto'-Feature available on all modes
This commit is contained in:
commit
d068765db9
@ -198,7 +198,7 @@ angular.module('OpenSlidesApp.motions', [
|
||||
|
||||
return lineNumberingService.insertLineNumbers(html, lineLength, highlight, callback);
|
||||
},
|
||||
getTextBetweenChangeRecommendations: function (versionId, change1, change2) {
|
||||
getTextBetweenChangeRecommendations: function (versionId, change1, change2, highlight) {
|
||||
var line_from = (change1 ? change1.line_to : 1),
|
||||
line_to = (change2 ? change2.line_from : null);
|
||||
|
||||
@ -216,11 +216,11 @@ angular.module('OpenSlidesApp.motions', [
|
||||
|
||||
html = data.outerContextStart + data.innerContextStart + data.html +
|
||||
data.innerContextEnd + data.outerContextEnd;
|
||||
html = lineNumberingService.insertLineNumbers(html, lineLength, null, null, line_from);
|
||||
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, line_from);
|
||||
|
||||
return html;
|
||||
},
|
||||
getTextRemainderAfterLastChangeRecommendation: function(versionId, changes) {
|
||||
getTextRemainderAfterLastChangeRecommendation: function(versionId, changes, highlight) {
|
||||
var maxLine = 0;
|
||||
for (var i = 0; i < changes.length; i++) {
|
||||
if (changes[i].line_to > maxLine) {
|
||||
@ -235,11 +235,11 @@ angular.module('OpenSlidesApp.motions', [
|
||||
html = data.outerContextStart + data.innerContextStart +
|
||||
data.html +
|
||||
data.innerContextEnd + data.outerContextEnd;
|
||||
html = lineNumberingService.insertLineNumbers(html, lineLength, null, null, maxLine);
|
||||
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, maxLine);
|
||||
|
||||
return html;
|
||||
},
|
||||
_getTextWithChangeRecommendations: function (versionId, statusCompareCb) {
|
||||
_getTextWithChangeRecommendations: function (versionId, highlight, statusCompareCb) {
|
||||
var lineLength = Config.get('motions_line_length').value,
|
||||
html = this.getVersion(versionId).text,
|
||||
changes = this.getChangeRecommendations(versionId, 'DESC');
|
||||
@ -252,42 +252,43 @@ angular.module('OpenSlidesApp.motions', [
|
||||
}
|
||||
}
|
||||
|
||||
return lineNumberingService.insertLineNumbers(html, lineLength);
|
||||
return lineNumberingService.insertLineNumbers(html, lineLength, highlight);
|
||||
},
|
||||
getTextWithAllChangeRecommendations: function (versionId) {
|
||||
return this._getTextWithChangeRecommendations(versionId, function() {
|
||||
getTextWithAllChangeRecommendations: function (versionId, highlight) {
|
||||
return this._getTextWithChangeRecommendations(versionId, highlight, function() {
|
||||
return true;
|
||||
});
|
||||
},
|
||||
getTextWithoutRejectedChangeRecommendations: function (versionId) {
|
||||
return this._getTextWithChangeRecommendations(versionId, function(rejected) {
|
||||
getTextWithoutRejectedChangeRecommendations: function (versionId, highlight) {
|
||||
return this._getTextWithChangeRecommendations(versionId, highlight, function(rejected) {
|
||||
return !rejected;
|
||||
});
|
||||
},
|
||||
getTextByMode: function(mode, versionId) {
|
||||
getTextByMode: function(mode, versionId, highlight) {
|
||||
/*
|
||||
* @param mode ['original', 'diff', 'changed', 'agreed']
|
||||
* @param versionId [if undefined, active_version will be used]
|
||||
* @param highlight [the line number to highlight]
|
||||
*/
|
||||
var text;
|
||||
switch (mode) {
|
||||
case 'original':
|
||||
text = this.getTextWithLineBreaks(versionId);
|
||||
text = this.getTextWithLineBreaks(versionId, highlight);
|
||||
break;
|
||||
case 'diff':
|
||||
var changes = this.getChangeRecommendations(versionId, 'ASC');
|
||||
text = '';
|
||||
for (var i = 0; i < changes.length; i++) {
|
||||
text += this.getTextBetweenChangeRecommendations(versionId, (i === 0 ? null : changes[i - 1]), changes[i]);
|
||||
text += changes[i].format(this, versionId);
|
||||
text += this.getTextBetweenChangeRecommendations(versionId, (i === 0 ? null : changes[i - 1]), changes[i], highlight);
|
||||
text += changes[i].format(this, versionId, highlight);
|
||||
}
|
||||
text += this.getTextRemainderAfterLastChangeRecommendation(versionId, changes);
|
||||
break;
|
||||
case 'changed':
|
||||
text = this.getTextWithAllChangeRecommendations(versionId);
|
||||
text = this.getTextWithAllChangeRecommendations(versionId, highlight);
|
||||
break;
|
||||
case 'agreed':
|
||||
text = this.getTextWithoutRejectedChangeRecommendations(versionId);
|
||||
text = this.getTextWithoutRejectedChangeRecommendations(versionId, highlight);
|
||||
break;
|
||||
}
|
||||
return text;
|
||||
@ -583,14 +584,14 @@ angular.module('OpenSlidesApp.motions', [
|
||||
saveStatus: function() {
|
||||
this.DSSave();
|
||||
},
|
||||
format: function(motion, version) {
|
||||
format: function(motion, version, highlight) {
|
||||
var lineLength = Config.get('motions_line_length').value,
|
||||
html = lineNumberingService.insertLineNumbers(motion.getVersion(version).text, lineLength);
|
||||
|
||||
var data = diffService.extractRangeByLineNumbers(html, this.line_from, this.line_to),
|
||||
oldText = data.outerContextStart + data.innerContextStart +
|
||||
data.html + data.innerContextEnd + data.outerContextEnd,
|
||||
oldTextWithBreaks = lineNumberingService.insertLineNumbersNode(oldText, lineLength, null, this.line_from),
|
||||
oldTextWithBreaks = lineNumberingService.insertLineNumbersNode(oldText, lineLength, highlight, this.line_from),
|
||||
newTextWithBreaks = lineNumberingService.insertLineNumbersNode(this.text, lineLength, null, this.line_from);
|
||||
|
||||
for (var i = 0; i < oldTextWithBreaks.childNodes.length; i++) {
|
||||
|
@ -76,7 +76,6 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
|
||||
this._currentLineNumber++;
|
||||
node.setAttribute('class', 'os-line-number line-number-' + lineNumber);
|
||||
node.setAttribute('data-line-number', lineNumber + '');
|
||||
node.setAttribute('name', 'L' + lineNumber);
|
||||
node.setAttribute('contenteditable', 'false');
|
||||
node.innerHTML = ' '; // Prevent tinymce from stripping out empty span's
|
||||
return node;
|
||||
|
@ -1075,11 +1075,20 @@ angular.module('OpenSlidesApp.motions.site', [
|
||||
};
|
||||
$scope.scrollToAndHighlight = function (line) {
|
||||
$scope.highlight = line;
|
||||
var lineElement = document.getElementsByName('L' + line);
|
||||
if (lineElement[0]) {
|
||||
// Scroll local
|
||||
|
||||
// The same line number can occur twice in diff view; we scroll to the first one in this case
|
||||
var scrollTop = null;
|
||||
$(".line-number-" + line).each(function() {
|
||||
var top = $(this).offset().top;
|
||||
if (top > 0 && (scrollTop === null || top < scrollTop)) {
|
||||
scrollTop = top;
|
||||
}
|
||||
});
|
||||
|
||||
if (scrollTop) {
|
||||
// Scroll local; 50 pixel above the line, so it's not completely squeezed to the screen border
|
||||
$('html, body').animate({
|
||||
scrollTop: lineElement[0].getBoundingClientRect().top
|
||||
'scrollTop': scrollTop - 50
|
||||
}, 1000);
|
||||
}
|
||||
// set highlight and scroll on Projector
|
||||
|
@ -345,7 +345,7 @@
|
||||
|
||||
<!-- Changed View -->
|
||||
<div ng-if="viewChangeRecommendations.mode == 'changed'">
|
||||
<div ng-bind-html="motion.getTextByMode('changed', version) | trusted"
|
||||
<div ng-bind-html="motion.getTextByMode('changed', version, highlight) | trusted"
|
||||
class="motion-text motion-text-changed line-numbers-{{ lineNumberMode }}"></div>
|
||||
|
||||
<div style="text-align: right;" ng-if="motion.state.versioning && (change_recommendations | filter:{motion_version_id:version}:true).length > 0">
|
||||
@ -360,7 +360,7 @@
|
||||
|
||||
<!-- Agreed View -->
|
||||
<div ng-if="viewChangeRecommendations.mode == 'agreed'">
|
||||
<div ng-bind-html="motion.getTextByMode('agreed', version) | trusted"
|
||||
<div ng-bind-html="motion.getTextByMode('agreed', version, highlight) | trusted"
|
||||
class="motion-text motion-text-changed line-numbers-{{ lineNumberMode }}"></div>
|
||||
|
||||
<div style="text-align: right;" ng-if="motion.state.versioning && (change_recommendations | filter:{motion_version_id:version}:true).length > 0">
|
||||
|
@ -49,8 +49,7 @@
|
||||
|
||||
<!-- go to line number -->
|
||||
<div class="goto-line-number">
|
||||
<form class="input-group" ng-if="viewChangeRecommendations.mode == 'original' && lineNumberMode != 'none'"
|
||||
ng-submit="scrollToAndHighlight(gotoLinenumber)">
|
||||
<form class="input-group" ng-if="lineNumberMode != 'none'" ng-submit="scrollToAndHighlight(gotoLinenumber)">
|
||||
<input type="number" class="form-control input-sm" ng-model="gotoLinenumber"
|
||||
placeholder="{{ 'Line' | translate }}"/>
|
||||
<div class="input-group-btn">
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div class="motion-text-with-diffs line-numbers-{{ lineNumberMode }}">
|
||||
<div ng-repeat="change in (changes = (change_recommendations | filter:{motion_version_id:version}:true | orderBy: 'line_from')) ">
|
||||
<div class="motion-text original-text line-numbers-{{ lineNumberMode }}"
|
||||
ng-bind-html="motion.getTextBetweenChangeRecommendations(version, changes[$index - 1], change) | trusted"></div>
|
||||
ng-bind-html="motion.getTextBetweenChangeRecommendations(version, changes[$index - 1], change, highlight) | trusted"></div>
|
||||
|
||||
<div class="diff-box diff-box-{{ change.id }} clearfix">
|
||||
<div class="action-row" ng-if="motion.isAllowed('can_manage')">
|
||||
@ -36,11 +36,11 @@
|
||||
</div>
|
||||
|
||||
<div class="motion-text motion-text-diff line-numbers-{{ lineNumberMode }}"
|
||||
ng-bind-html="change.format(motion, version) | trusted"></div>
|
||||
ng-bind-html="change.format(motion, version, highlight) | trusted"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="motion-text original-text line-numbers-{{ lineNumberMode }}"
|
||||
ng-bind-html="motion.getTextRemainderAfterLastChangeRecommendation(version, changes) | trusted"></div>
|
||||
ng-bind-html="motion.getTextRemainderAfterLastChangeRecommendation(version, changes, highlight) | trusted"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -5,10 +5,10 @@ describe('linenumbering', function () {
|
||||
var lineNumberingService,
|
||||
brMarkup = function (no) {
|
||||
return '<br class="os-line-break">' +
|
||||
'<span class="os-line-number line-number-' + no + '" data-line-number="' + no + '" name="L' + no + '" contenteditable="false"> </span>';
|
||||
'<span class="os-line-number line-number-' + no + '" data-line-number="' + no + '" contenteditable="false"> </span>';
|
||||
},
|
||||
noMarkup = function (no) {
|
||||
return '<span class="os-line-number line-number-' + no + '" data-line-number="' + no + '" name="L' + no + '" contenteditable="false"> </span>';
|
||||
return '<span class="os-line-number line-number-' + no + '" data-line-number="' + no + '" contenteditable="false"> </span>';
|
||||
},
|
||||
longstr = function (length) {
|
||||
var outstr = '';
|
||||
|
Loading…
Reference in New Issue
Block a user