@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
86 lines • 4.36 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2022 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { __decorate } from "tslib";
import { injectable, inject } from 'inversify';
import { CompressionToggle, TreeCompressionService } from './tree-compression-service.js';
import { CompositeTreeNode } from '../tree.js';
import { TreeModelImpl } from '../tree-model.js';
import { SelectableTreeNode, TreeSelection } from '../tree-selection.js';
import { ExpandableTreeNode } from '../tree-expansion.js';
import { TopDownTreeIterator } from '../tree-iterator.js';
export class TopDownCompressedTreeIterator extends TopDownTreeIterator {
constructor(root, options, compressionService = new TreeCompressionService()) {
super(root, options);
this.compressionService = compressionService;
}
isCollapsed(candidate) {
return ExpandableTreeNode.isCollapsed(candidate) && !this.compressionService.isCompressionParent(candidate);
}
}
var BackOrForward;
(function (BackOrForward) {
BackOrForward[BackOrForward["Forward"] = 0] = "Forward";
BackOrForward[BackOrForward["Backward"] = 1] = "Backward";
})(BackOrForward || (BackOrForward = {}));
let CompressedTreeModel = class CompressedTreeModel extends TreeModelImpl {
selectAdjacentRow(direction, type = TreeSelection.SelectionType.DEFAULT, startingPoint = this.getFocusedNode()) {
if (!startingPoint && this.root) {
this.selectAdjacentRow(BackOrForward.Forward, type, this.root);
}
if (this.compressionService.isCompressionParticipant(startingPoint)) {
const chain = this.compressionService.getCompressionChain(startingPoint);
startingPoint = (direction === BackOrForward.Backward ? chain?.head() : chain?.tail()) ?? startingPoint;
}
const iterator = direction === BackOrForward.Backward ? this.createBackwardIterator(startingPoint) : this.createIterator(startingPoint);
const test = (candidate) => SelectableTreeNode.isVisible(candidate)
&& (this.compressionService.isCompressionHead(candidate) || !this.compressionService.isCompressionParticipant(candidate));
const rowRoot = iterator && this.doGetNextNode(iterator, test);
const nodes = (this.compressionService.getCompressionChain(rowRoot) ?? [rowRoot]).reverse();
const node = nodes.find(SelectableTreeNode.is);
if (node) {
this.addSelection({ node, type });
}
}
selectPrevRow(type) {
this.selectAdjacentRow(BackOrForward.Backward, type);
}
selectNextRow(type) {
this.selectAdjacentRow(BackOrForward.Forward, type);
}
createForwardIteratorForNode(node) {
return new TopDownCompressedTreeIterator(node, { pruneCollapsed: true }, this.compressionService);
}
selectIfAncestorOfSelected(node) {
if (!this.compressionToggle.compress) {
return super.selectIfAncestorOfSelected(node);
}
const tail = this.compressionService.getCompressionChain(node)?.tail() ?? node;
if (SelectableTreeNode.is(tail) && !tail.expanded && this.selectedNodes.some(selectedNode => CompositeTreeNode.isAncestor(tail, selectedNode))) {
this.selectNode(tail);
}
}
};
__decorate([
inject(CompressionToggle)
], CompressedTreeModel.prototype, "compressionToggle", void 0);
__decorate([
inject(TreeCompressionService)
], CompressedTreeModel.prototype, "compressionService", void 0);
CompressedTreeModel = __decorate([
injectable()
], CompressedTreeModel);
export { CompressedTreeModel };
//# sourceMappingURL=compressed-tree-model.js.map