Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/powerpoint/ui/NativePowerPointView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4713,7 +4713,7 @@ export class NativePowerPointView extends FileView {
this.selectedShapeIndex = shapeIndex;
this.selectedShapeIndices = new Set([shapeIndex]);
this.removeMultiSelectionBoxes();
this.svgEl.querySelectorAll('g[data-ooxml-shape-idx]').forEach((shape) => {
this.svgEl?.querySelectorAll('.native-powerpoint-shape-selected').forEach((shape) => {
shape.removeClass('native-powerpoint-shape-selected');
});

Expand Down Expand Up @@ -4748,7 +4748,7 @@ export class NativePowerPointView extends FileView {
this.selectedShapeIndex = shapeIndex;
this.selectedShapeIndices = new Set([shapeIndex]);
this.removeMultiSelectionBoxes();
this.svgEl.querySelectorAll('g[data-ooxml-shape-idx]').forEach((shape) => {
this.svgEl?.querySelectorAll('.native-powerpoint-shape-selected').forEach((shape) => {
shape.removeClass('native-powerpoint-shape-selected');
});

Expand Down Expand Up @@ -4824,14 +4824,16 @@ export class NativePowerPointView extends FileView {
}

private applySelectionClasses(): void {
this.svgEl?.querySelectorAll('g[data-ooxml-shape-idx]').forEach((shape) => {
const index = getShapeIndex(shape);
if (index !== null && this.selectedShapeIndices.has(index)) {
if (!this.svgEl) return;
this.svgEl.querySelectorAll('.native-powerpoint-shape-selected').forEach((shape) => {
shape.removeClass('native-powerpoint-shape-selected');
});
for (const index of this.selectedShapeIndices) {
const shape = this.svgEl.querySelector(`g[data-ooxml-shape-idx="${index}"]`);
if (shape) {
shape.addClass('native-powerpoint-shape-selected');
} else {
shape.removeClass('native-powerpoint-shape-selected');
}
});
}
}

private clearSelection(options: { skipTextCommit?: boolean } = {}): void {
Expand All @@ -4849,7 +4851,7 @@ export class NativePowerPointView extends FileView {
this.selectedShapeIndex = null;
this.selectedShapeIndices.clear();
this.selectedTransform = null;
this.svgEl?.querySelectorAll('g[data-ooxml-shape-idx]').forEach((shape) => {
this.svgEl?.querySelectorAll('.native-powerpoint-shape-selected').forEach((shape) => {
shape.removeClass('native-powerpoint-shape-selected');
});
this.removeSelectionOverlay();
Expand Down Expand Up @@ -12288,14 +12290,16 @@ export class NativePowerPointView extends FileView {
}

private previewSelectionClasses(indices: Set<number>): void {
this.svgEl?.querySelectorAll('g[data-ooxml-shape-idx]').forEach((shape) => {
const index = getShapeIndex(shape);
if (index !== null && indices.has(index)) {
if (!this.svgEl) return;
this.svgEl.querySelectorAll('.native-powerpoint-shape-selected').forEach((shape) => {
shape.removeClass('native-powerpoint-shape-selected');
});
for (const index of indices) {
const shape = this.svgEl.querySelector(`g[data-ooxml-shape-idx="${index}"]`);
Comment on lines +12297 to +12298

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid per-shape DOM scans during marquee previews

When a marquee covers many shapes, updateMarquee invokes this method on every pointer move, and the loop now performs a separate root-level querySelector for every hit. With N shapes and M selected shapes this can add O(N×M) selector work after the existing O(N) hit test, whereas the previous implementation traversed the SVG once. Large selections—the exact case this change aims to optimize—can therefore become substantially slower; retain a single traversal or cache the shape-index-to-element mapping.

Useful? React with 👍 / 👎.

if (shape) {
shape.addClass('native-powerpoint-shape-selected');
} else {
shape.removeClass('native-powerpoint-shape-selected');
}
});
}
}

private beginMarquee(event: PointerEvent, additive: boolean): void {
Expand Down
Loading