Skip to content

Commit

Permalink
Merge pull request #358 from XpressAI/fahreza/propagation-bugfix
Browse files Browse the repository at this point in the history
🐛 Prevent Event Propagation to Other Widgets
  • Loading branch information
MFA-X-AI authored Oct 7, 2024
2 parents 46c8ba1 + 4e70839 commit dc4b639
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/commands/CustomActionEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ interface CustomActionEventOptions {

export class CustomActionEvent extends Action {
constructor(options: CustomActionEventOptions) {

super({
type: InputType.KEY_DOWN,
fire: (event: ActionEvent<React.KeyboardEvent>) => {
const app = options.app;
// @ts-ignore
if(app.shell._tracker._activeWidget && options.getWidgetId() === app.shell._tracker._activeWidget.id){
if (app.shell._tracker._activeWidget && options.getWidgetId() === app.shell._tracker._activeWidget.id) {
const keyCode = event.event.key;
const ctrlKey = event.event.ctrlKey;

const executeIf = (condition, command) => {
if(condition){
// @ts-ignore
event.event.stopImmediatePropagation();
app.commands.execute(command)
if (condition) {
event.event.preventDefault();
event.event.stopPropagation();
if (event.event.nativeEvent) {
event.event.nativeEvent.stopImmediatePropagation();
}
app.commands.execute(command);
}
}
};

executeIf(ctrlKey && keyCode === 'z', commandIDs.undo);
executeIf(ctrlKey && keyCode === 'y', commandIDs.redo);
Expand Down

0 comments on commit dc4b639

Please sign in to comment.