<commit_before>import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';

import { Model, ModelTrackNote } from '../../model/model';
import { ModelService } from '../../model/model.service';
import { Track, getTrack } from '../../track/track';
import { TrackService } from '../../track/track.service';

@Injectable()
export class SelectedNoteService {

    private selectedNotesSubject: BehaviorSubject<ModelTrackNote>;
    private model: Model;
    private track: Track;

    constructor(
        private modelService: ModelService,
        private trackService: TrackService,
    ) {
        this.selectedNotesSubject = new BehaviorSubject<ModelTrackNote>(undefined);
        Observable.combineLatest(
            this.modelService.models,
            this.trackService.tracks,
            (model, track) => {
                this.model = model;
                this.track = track;
            }).subscribe(() => {
                if (this.selectedNotesSubject.value) {
                    this.selectNote(this.selectedNotesSubject.value.id);
                }
            });
    }

    get selectedNotes(): Observable<ModelTrackNote> {
        return this.selectedNotesSubject.asObservable();
    }

    selectNote(id: number): void {
        const note = this.findNote(id);
        this.newSelection(note);
    }

    selectNextNote(): void {
        const note = this.findNextNote();
        if (note) {
            this.newSelection(note);            
        }
    }

    selectPreviousNote(): void {
        const note = this.findPreviousNote();
        if (note) {
            this.newSelection(note);            
        }
    }<commit_msg>fix: Don't reselect note when track changes<commit_after>import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';

import { Model, ModelTrackNote } from '../../model/model';
import { ModelService } from '../../model/model.service';
import { Track, getTrack } from '../../track/track';
import { TrackService } from '../../track/track.service';

@Injectable()
export class SelectedNoteService {

    private selectedNotesSubject: BehaviorSubject<ModelTrackNote>;
    private model: Model;
    private track: Track;

    constructor(
        private modelService: ModelService,
        private trackService: TrackService,
    ) {
        this.selectedNotesSubject = new BehaviorSubject<ModelTrackNote>(undefined);
        this.modelService.models.subscribe((model) => {
            this.model = model;
            if (this.selectedNotesSubject.value) {
                this.selectNote(this.selectedNotesSubject.value.id);
            }
        });
        this.trackService.tracks.subscribe((track) => {
            this.track = track;
        });
    }

    get selectedNotes(): Observable<ModelTrackNote> {
        return this.selectedNotesSubject.asObservable();
    }

    selectNote(id: number): void {
        const note = this.findNote(id);
        this.newSelection(note);
    }

    selectNextNote(): void {
        const note = this.findNextNote();
        if (note) {
            this.newSelection(note);            
        }
    }

    selectPreviousNote(): void {
        const note = this.findPreviousNote();
        if (note) {
            this.newSelection(note);            
        }
    }
{'fraction_non_alphanumeric': 0.12181218121812182, 'fraction_numerical': 0.0, 'mean_word_length': 2.2119460500963393, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3301002', 'n_tokens_mistral': 885, 'n_tokens_neox': 853, 'n_words': 184}