Skip to content

Commit 28623cd

Browse files
authored
fix(list, tree): copying text using hotkeys (#DS-4362) (#1131)
1 parent 60fa254 commit 28623cd

File tree

6 files changed

+48
-22
lines changed

6 files changed

+48
-22
lines changed

packages/components-dev/tree/module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ export class DevApp {
227227
console.log('onSelectAll', $event);
228228
}
229229

230+
onCopy($event) {
231+
console.log('onCopy', $event);
232+
}
233+
230234
onNavigationChange($event) {
231235
console.log('onNavigationChange', $event);
232236
}

packages/components-dev/tree/template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
[(ngModel)]="modelValue"
5555
(ngModelChange)="onModelValueChange($event)"
5656
(onSelectAll)="onSelectAll($event)"
57+
(onCopy)="onCopy($event)"
5758
>
5859
<kbq-tree-option *kbqTreeNodeDef="let node" kbqTreeNodePadding>
5960
<i kbq-icon="kbq-info-circle_16"></i>

packages/components/list/list-selection.component.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,19 @@ export class KbqListSelectAllEvent<T> {
8585
) {}
8686
}
8787

88+
/**
89+
* Event class that occurs when copying an item from the KbqListSelection.
90+
* Used to pass data about the copied item and copy context.
91+
*
92+
* @param source - instance of KbqListSelection
93+
* @param option - instance of KbqListOption
94+
* @param event - original keyboard event (optional) that triggered the copy
95+
*/
8896
export class KbqListCopyEvent<T> {
8997
constructor(
9098
public source: KbqListSelection,
91-
public option: T
99+
public option: T,
100+
public event?: KeyboardEvent
92101
) {}
93102
}
94103

@@ -482,8 +491,7 @@ export class KbqListSelection implements AfterContentInit, AfterViewInit, OnDest
482491

483492
return;
484493
} else if (isCopy(event)) {
485-
this.copyActiveOption();
486-
event.preventDefault();
494+
this.copyActiveOption(event);
487495

488496
return;
489497
} else if ([SPACE, ENTER].includes(keyCode)) {
@@ -615,19 +623,19 @@ export class KbqListSelection implements AfterContentInit, AfterViewInit, OnDest
615623
this.onSelectAll.emit(new KbqListSelectAllEvent(this, optionsToSelect));
616624
}
617625

618-
private copyActiveOption() {
619-
if (!this.keyManager.activeItem) {
620-
return;
621-
}
626+
private copyActiveOption(event: KeyboardEvent) {
627+
if (!this.keyManager.activeItem) return;
622628

623629
const option = this.keyManager.activeItem;
624630

625631
option.preventBlur = true;
626632

627-
if (this.onCopy.observers.length) {
628-
this.onCopy.emit(new KbqListCopyEvent(this, option));
633+
if (this.onCopy.observed) {
634+
this.onCopy.emit(new KbqListCopyEvent(this, option, event));
629635
} else {
630636
this.onCopyDefaultHandler();
637+
638+
event.preventDefault();
631639
}
632640

633641
option.preventBlur = false;

packages/components/tree/tree-selection.component.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,19 @@ export class KbqTreeSelectAllEvent<T> {
6767
) {}
6868
}
6969

70+
/**
71+
* Event class that occurs when copying an item from the KbqTreeSelection.
72+
* Used to pass data about the copied item and copy context.
73+
*
74+
* @param source - instance of KbqTreeSelection
75+
* @param option - instance of KbqTreeOption
76+
* @param event - original keyboard event (optional) that triggered the copy
77+
*/
7078
export class KbqTreeCopyEvent<T> {
7179
constructor(
7280
public source: KbqTreeSelection,
73-
public option: T
81+
public option: T,
82+
public event?: KeyboardEvent
7483
) {}
7584
}
7685

@@ -354,7 +363,7 @@ export class KbqTreeSelection
354363

355364
return;
356365
} else if (isCopy(event)) {
357-
this.copyActiveOption();
366+
this.copyActiveOption(event);
358367

359368
return;
360369
} else if (keyCode === TAB) {
@@ -522,19 +531,19 @@ export class KbqTreeSelection
522531
this.onSelectAll.emit(new KbqTreeSelectAllEvent(this, optionsToSelect));
523532
}
524533

525-
copyActiveOption(): void {
526-
if (!this.keyManager.activeItem) {
527-
return;
528-
}
534+
copyActiveOption(event: KeyboardEvent): void {
535+
if (!this.keyManager.activeItem) return;
529536

530537
const option = this.keyManager.activeItem;
531538

532539
option.preventBlur = true;
533540

534-
if (this.onCopy.observers.length) {
535-
this.onCopy.emit(new KbqTreeCopyEvent(this, this.keyManager.activeItem as KbqTreeOption));
541+
if (this.onCopy.observed) {
542+
this.onCopy.emit(new KbqTreeCopyEvent(this, this.keyManager.activeItem as KbqTreeOption, event));
536543
} else {
537544
this.onCopyDefaultHandler();
545+
546+
event.preventDefault();
538547
}
539548

540549
option.preventBlur = false;

tools/public_api_guard/components/list.api.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ export class KbqList {
4444
static ɵfac: i0.ɵɵFactoryDeclaration<KbqList, never>;
4545
}
4646

47-
// @public (undocumented)
47+
// @public
4848
export class KbqListCopyEvent<T> {
49-
constructor(source: KbqListSelection, option: T);
49+
constructor(source: KbqListSelection, option: T, event?: KeyboardEvent | undefined);
50+
// (undocumented)
51+
event?: KeyboardEvent | undefined;
5052
// (undocumented)
5153
option: T;
5254
// (undocumented)

tools/public_api_guard/components/tree.api.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,11 @@ export class KbqTreeBase<T> implements AfterContentChecked, CollectionViewer, On
201201
static ɵfac: i0.ɵɵFactoryDeclaration<KbqTreeBase<any>, never>;
202202
}
203203

204-
// @public (undocumented)
204+
// @public
205205
export class KbqTreeCopyEvent<T> {
206-
constructor(source: KbqTreeSelection, option: T);
206+
constructor(source: KbqTreeSelection, option: T, event?: KeyboardEvent | undefined);
207+
// (undocumented)
208+
event?: KeyboardEvent | undefined;
207209
// (undocumented)
208210
option: T;
209211
// (undocumented)
@@ -562,7 +564,7 @@ export class KbqTreeSelection extends KbqTreeBase<any> implements ControlValueAc
562564
// (undocumented)
563565
blur(): void;
564566
// (undocumented)
565-
copyActiveOption(): void;
567+
copyActiveOption(event: KeyboardEvent): void;
566568
// (undocumented)
567569
get disabled(): boolean;
568570
set disabled(rawValue: boolean);

0 commit comments

Comments
 (0)