<commit_before>import {Action} from "../../base/intent/actions"
import {AbstractCommand, CommandExecutionContext} from "../../base/intent/commands"
import {SModelRoot, SModelElement} from "../../base/model/smodel"
import {isSelectable} from "../select/select"
import {isSizeable, Sizeable} from "../resize/resize"
import {Bounds, getBounds, combine, EMPTY_BOUNDS, center} from "../../utils/geometry"
import {isMoveable} from "../move"
import {Viewport, isViewport, ViewportAnimation} from "./viewport"
import {KeyListener} from "../../base/view/key-tool"
import {isCtrlOrCmd} from "../../utils/utils"

export class CenterAction implements Action {
    readonly kind = CenterCommand.KIND

    constructor(public readonly elementIds: string[]) {
    }
}

export class FitToScreenAction implements Action {
    readonly kind = FitToScreenCommand.KIND

    constructor(public readonly elementIds: string[]) {
    }
}

export abstract class AbstractViewportCommand extends AbstractCommand {

    oldViewport: Viewport
    newViewport: Viewport

    protected initialize(model: SModelRoot) {
        if (isViewport(model) && isSizeable(model) && model.clientBounds) {
            this.oldViewport = {
                scroll: model.scroll,
                zoom: model.zoom
            }
            const allBounds: Bounds[] = []
            this.getElementIds().forEach(
                id => {
                    const element = model.index.getById(id)
                    if (element && isSizeable(element) && isMoveable(element))
                        allBounds.push(getBounds(element))
                }
            )
            if (allBounds.length == 0) {
                model.index.all().forEach(
                    element => {
                        if (isSelectable(element) && element.selected && isSizeable(element) && isMoveable(element))
                            allBounds.push(getBounds(element))
                    }
                )
            }<commit_msg>fixed initial position in viewport animation<commit_after>import {Action} from "../../base/intent/actions"
import {AbstractCommand, CommandExecutionContext} from "../../base/intent/commands"
import {SModelRoot, SModelElement} from "../../base/model/smodel"
import {isSelectable} from "../select/select"
import {isSizeable, Sizeable} from "../resize/resize"
import {Bounds, getBounds, combine, EMPTY_BOUNDS, center} from "../../utils/geometry"
import {isMoveable} from "../move"
import {Viewport, isViewport, ViewportAnimation} from "./viewport"
import {KeyListener} from "../../base/view/key-tool"
import {isCtrlOrCmd} from "../../utils/utils"

export class CenterAction implements Action {
    readonly kind = CenterCommand.KIND

    constructor(public readonly elementIds: string[]) {
    }
}

export class FitToScreenAction implements Action {
    readonly kind = FitToScreenCommand.KIND

    constructor(public readonly elementIds: string[]) {
    }
}

export abstract class AbstractViewportCommand extends AbstractCommand {

    oldViewport: Viewport
    newViewport: Viewport

    protected initialize(model: SModelRoot) {
        if (isViewport(model) && isSizeable(model) && model.clientBounds) {
            this.oldViewport = {
                scroll: {
                    x: model.scroll.x,
                    y: model.scroll.y
                },
                zoom: model.zoom
            }
            const allBounds: Bounds[] = []
            this.getElementIds().forEach(
                id => {
                    const element = model.index.getById(id)
                    if (element && isSizeable(element) && isMoveable(element))
                        allBounds.push(getBounds(element))
                }
            )
            if (allBounds.length == 0) {
                model.index.all().forEach(
                    element => {
                        if (isSelectable(element) && element.selected && isSizeable(element) && isMoveable(element))
                            allBounds.push(getBounds(element))
                    }
                )
            }
{'fraction_non_alphanumeric': 0.1177336276674025, 'fraction_numerical': 0.0004905567819475104, 'mean_word_length': 2.117737003058104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3094763', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1024, 'n_words': 246}