diff --git a/client/src/app/core/repositories/motions/motion-repository.service.ts b/client/src/app/core/repositories/motions/motion-repository.service.ts index e4b27c4e2..65c926815 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -358,7 +358,8 @@ export class MotionRepositoryService extends BaseRepository to: change.getLineFrom() }, true, - lineLength + lineLength, + highlightLine ); } else if (changes[idx - 1].getLineTo() < change.getLineFrom()) { text += this.extractMotionLineRange( @@ -368,7 +369,8 @@ export class MotionRepositoryService extends BaseRepository to: change.getLineFrom() }, true, - lineLength + lineLength, + highlightLine ); } text += this.getChangeDiff(targetMotion, change, lineLength, highlightLine); @@ -418,8 +420,15 @@ export class MotionRepositoryService extends BaseRepository * @param {LineRange} lineRange * @param {boolean} lineNumbers - weather to add line numbers to the returned HTML string * @param {number} lineLength + * @param {number|null} highlightedLine */ - public extractMotionLineRange(id: number, lineRange: LineRange, lineNumbers: boolean, lineLength: number): string { + public extractMotionLineRange( + id: number, + lineRange: LineRange, + lineNumbers: boolean, + lineLength: number, + highlightedLine: number + ): string { const origHtml = this.formatMotion(id, ChangeRecoMode.Original, [], lineLength); const extracted = this.diff.extractRangeByLineNumbers(origHtml, lineRange.from, lineRange.to); let html = @@ -429,7 +438,7 @@ export class MotionRepositoryService extends BaseRepository extracted.innerContextEnd + extracted.outerContextEnd; if (lineNumbers) { - html = this.lineNumbering.insertLineNumbers(html, lineLength, null, null, lineRange.from); + html = this.lineNumbering.insertLineNumbers(html, lineLength, highlightedLine, null, lineRange.from); } return html; } @@ -491,6 +500,19 @@ export class MotionRepositoryService extends BaseRepository return html; } + /** + * Returns the last line number of a motion + * + * @param {ViewMotion} motion + * @param {number} lineLength + * @return {number} + */ + public getLastLineNumber(motion: ViewMotion, lineLength: number): number { + const numberedHtml = this.lineNumbering.insertLineNumbers(motion.text, lineLength); + const range = this.lineNumbering.getLineNumberRange(numberedHtml); + return range.to; + } + /** * Creates a {@link ViewChangeReco} object based on the motion ID and the given lange range. * This object is not saved yet and does not yet have any changed HTML. It's meant to populate the UI form. @@ -508,7 +530,7 @@ export class MotionRepositoryService extends BaseRepository changeReco.line_from = lineRange.from; changeReco.line_to = lineRange.to; changeReco.type = ModificationType.TYPE_REPLACEMENT; - changeReco.text = this.extractMotionLineRange(motionId, lineRange, false, lineLength); + changeReco.text = this.extractMotionLineRange(motionId, lineRange, false, lineLength, null); changeReco.rejected = false; changeReco.motion_id = motionId; diff --git a/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.spec.ts b/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.spec.ts index 5e7d79551..56f092561 100644 --- a/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.spec.ts +++ b/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.spec.ts @@ -6,13 +6,15 @@ import { ViewMotion } from '../../models/view-motion'; import { ViewChangeReco } from '../../models/view-change-reco'; import { MotionDetailDiffComponent } from './motion-detail-diff.component'; import { MotionDetailOriginalChangeRecommendationsComponent } from '../motion-detail-original-change-recommendations/motion-detail-original-change-recommendations.component'; +import { ViewUnifiedChange } from '../../models/view-unified-change'; @Component({ template: ` @@ -21,14 +23,13 @@ import { MotionDetailOriginalChangeRecommendationsComponent } from '../motion-de class TestHostComponent { public motion: ViewMotion; public changes: ViewChangeReco[]; + public scrollToChange: ViewUnifiedChange = null; public constructor() { this.motion = new ViewMotion(); this.changes = []; } - public scrollToChange($event: Event): void {} - public createChangeRecommendation($event: Event): void {} } diff --git a/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts b/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts index 128405a94..44742dc55 100644 --- a/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts +++ b/client/src/app/site/motions/components/motion-detail-diff/motion-detail-diff.component.ts @@ -32,6 +32,7 @@ import { ConfigService } from 'app/core/ui-services/config.service'; * [motion]="motion" * [changes]="changes" * [scrollToChange]="change" + * [highlightedLine]="highlightedLine" * (createChangeRecommendation)="createChangeRecommendation($event)" * > * ``` @@ -48,6 +49,8 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte public changes: ViewUnifiedChange[]; @Input() public scrollToChange: ViewUnifiedChange; + @Input() + public highlightedLine: number; @Output() public createChangeRecommendation: EventEmitter = new EventEmitter(); @@ -109,7 +112,13 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte return ''; } - return this.motionRepo.extractMotionLineRange(this.motion.id, lineRange, true, this.lineLength); + return this.motionRepo.extractMotionLineRange( + this.motion.id, + lineRange, + true, + this.lineLength, + this.highlightedLine + ); } /** @@ -138,7 +147,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte * @param {ViewUnifiedChange} change */ public getDiff(change: ViewUnifiedChange): SafeHtml { - const html = this.motionRepo.getChangeDiff(this.motion, change, this.lineLength); + const html = this.motionRepo.getChangeDiff(this.motion, change, this.lineLength, this.highlightedLine); return this.sanitizer.bypassSecurityTrustHtml(html); } @@ -149,7 +158,12 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte if (!this.lineLength) { return ''; // @TODO This happens in the test case when the lineLength-variable is not set } - return this.motionRepo.getTextRemainderAfterLastChange(this.motion, this.changes, this.lineLength); + return this.motionRepo.getTextRemainderAfterLastChange( + this.motion, + this.changes, + this.lineLength, + this.highlightedLine + ); } /** diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.html b/client/src/app/site/motions/components/motion-detail/motion-detail.component.html index 7331a681a..32271e634 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.html +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.html @@ -118,8 +118,7 @@ · - Amendment to {{ + Amendment to {{ motion.parent.identifier || motion.parent.title }} @@ -336,9 +335,7 @@
- - {{ '–' }} - + {{ '–' }} @@ -352,9 +349,7 @@
- - {{ tag }} - + {{ tag }}
@@ -418,6 +413,42 @@ >
+ + + Invalid line number + + + + +