From e62648c71916696b992434a9b54af1f4aef4d013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Fri, 15 Mar 2019 09:59:59 +0100 Subject: [PATCH] Bugfixes: Highlighting wo CRs, better scrolling --- .../src/app/core/ui-services/diff.service.ts | 2 +- .../motion-detail/motion-detail.component.ts | 30 +++++++++++++++++-- .../motions/motion/motion-slide.component.ts | 1 - 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/client/src/app/core/ui-services/diff.service.ts b/client/src/app/core/ui-services/diff.service.ts index ec77aa38c..e26ae2d7b 100644 --- a/client/src/app/core/ui-services/diff.service.ts +++ b/client/src/app/core/ui-services/diff.service.ts @@ -2208,7 +2208,7 @@ export class DiffService { } }, 0); - const numberedHtml = this.lineNumberingService.insertLineNumbers(motionHtml, lineLength); + const numberedHtml = this.lineNumberingService.insertLineNumbers(motionHtml, lineLength, highlight); if (changes.length === 0) { return numberedHtml; } diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts index bbc20fa63..ea6301be7 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts @@ -172,7 +172,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, /** * All change recommendations AND amendments, sorted by line number. */ - public allChangingObjects: ViewUnifiedChange[]; + public allChangingObjects: ViewUnifiedChange[] = []; /** * preload the next motion for direct navigation @@ -451,7 +451,10 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, this.configService .get('motions_amendments_enabled') .subscribe(enabled => (this.amendmentsEnabled = enabled)); - this.configService.get('motions_line_length').subscribe(lineLength => (this.lineLength = lineLength)); + this.configService.get('motions_line_length').subscribe(lineLength => { + this.lineLength = lineLength; + this.recalcUnifiedChanges(); + }); this.configService .get('motions_default_line_numbering') .subscribe(mode => (this.lnMode = mode)); @@ -524,6 +527,11 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, * be avoided. It's safer and simpler to return values than to manipulate the scope */ private recalcUnifiedChanges(): void { + if (!this.lineLength) { + // Happens if this function is called before the config variable has been loaded + return; + } + this.allChangingObjects = []; if (this.changeRecommendations) { this.changeRecommendations.forEach( @@ -936,7 +944,23 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, // setTimeout necessary for DOM-operations to work window.setTimeout(() => { const element = this.el.nativeElement; - const target = element.querySelector('.os-line-number.line-number-' + line.toString(10)); + + // We only scroll if it's not in the screen already + const bounding = element + .querySelector('.os-line-number.line-number-' + line.toString(10)) + .getBoundingClientRect(); + if (bounding.top >= 0 && bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight)) { + return; + } + + let target: Element; + // to make the selected line not stick at the very top of the screen, and to prevent it from being + // conceiled from the header, we actually scroll to a element a little bit above. + if (line > 4) { + target = element.querySelector('.os-line-number.line-number-' + (line - 4).toString(10)); + } else { + target = element.querySelector('.title-line'); + } target.scrollIntoView({ behavior: 'smooth' }); }, 1); } diff --git a/client/src/app/slides/motions/motion/motion-slide.component.ts b/client/src/app/slides/motions/motion/motion-slide.component.ts index 30a0c9658..79866365d 100644 --- a/client/src/app/slides/motions/motion/motion-slide.component.ts +++ b/client/src/app/slides/motions/motion/motion-slide.component.ts @@ -60,7 +60,6 @@ export class MotionSlideComponent extends BaseMotionSlideComponent