<commit_before>import { Directive, HostListener, Optional } from '@angular/core';
import { SlidesDeckComponent } from '../deck/deck.component';
import { FullScreenModeService } from '@codelab/utils';

@Directive({
  selector: '[slideShortcuts]'
})
export class ShortcutsDirective {

  constructor(@Optional() private deck: SlidesDeckComponent, private fullScreenService: FullScreenModeService) {}

  @HostListener('window:keydown.ArrowRight', ['$event.target'])
  @HostListener('window:keydown.PageDown', ['$event.target'])
  next(target) {
    if (this.canNavigate(target) && this.deck.canGoNext()) {
      this.deck.nextSlide();
    }
  }

  @HostListener('window:keydown.ArrowLeft', ['$event.target'])
  @HostListener('window:keydown.PageUp', ['$event.target'])
  previous(target) {
    if (this.canNavigate(target) && this.deck.canGoPrevious()) {
      this.deck.previousSlide();
    }
  }

  @HostListener('window:keydown.alt.enter', ['$event'])
  fullScreenModeToggle(e) {
    // prevent page reload
    e.preventDefault();

    this.fullScreenService.toggleFullScreen();
  }

  private canNavigate(target: HTMLElement) {
    return target === document.body || this.isFromContext(target);
  }

  private isFromContext(target: HTMLElement) {
    let parent = target;

    while (parent && parent.nodeName !== 'BODY') {
      if (parent.classList.contains('shortcuts-context')) {
        return true;
      }
      parent = parent.parentElement;
    }

    return false;
  }
}
<commit_msg>fix(shortcuts): remove body node check<commit_after>import { Directive, HostListener, Optional } from '@angular/core';
import { SlidesDeckComponent } from '../deck/deck.component';
import { FullScreenModeService } from '@codelab/utils';

@Directive({
  selector: '[slideShortcuts]'
})
export class ShortcutsDirective {

  constructor(@Optional() private deck: SlidesDeckComponent, private fullScreenService: FullScreenModeService) {}

  @HostListener('window:keydown.ArrowRight', ['$event.target'])
  @HostListener('window:keydown.PageDown', ['$event.target'])
  next(target) {
    if (this.canNavigate(target) && this.deck.canGoNext()) {
      this.deck.nextSlide();
    }
  }

  @HostListener('window:keydown.ArrowLeft', ['$event.target'])
  @HostListener('window:keydown.PageUp', ['$event.target'])
  previous(target) {
    if (this.canNavigate(target) && this.deck.canGoPrevious()) {
      this.deck.previousSlide();
    }
  }

  @HostListener('window:keydown.alt.enter', ['$event'])
  fullScreenModeToggle(e) {
    // prevent page reload
    e.preventDefault();

    this.fullScreenService.toggleFullScreen();
  }

  private canNavigate(target: HTMLElement) {
    return target === document.body || this.isFromContext(target);
  }

  private isFromContext(target: HTMLElement) {
    let parent = target;

    while (parent) {
      if (parent.classList.contains('shortcuts-context')) {
        return true;
      }
      parent = parent.parentElement;
    }

    return false;
  }
}

{'fraction_non_alphanumeric': 0.15263334451526334, 'fraction_numerical': 0.0, 'mean_word_length': 4.25, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3950149', 'n_tokens_mistral': 934, 'n_tokens_neox': 915, 'n_words': 158}