Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to delete workspace comments #8023

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 21 additions & 1 deletion core/comments/rendered_workspace_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ import {CommentDragStrategy} from '../dragging/comment_drag_strategy.js';
import * as browserEvents from '../browser_events.js';
import * as common from '../common.js';
import {ISelectable} from '../interfaces/i_selectable.js';
import {IDeletable} from '../interfaces/i_deletable.js';

export class RenderedWorkspaceComment
extends WorkspaceComment
implements IBoundedElement, IRenderedElement, IDraggable, ISelectable
implements
IBoundedElement,
IRenderedElement,
IDraggable,
ISelectable,
IDeletable
{
/** The class encompassing the svg elements making up the workspace comment. */
private view: CommentView;
Expand Down Expand Up @@ -165,6 +171,20 @@ export class RenderedWorkspaceComment
}
}

/** Returns whether this comment is deletable or not. */
isDeletable(): boolean {
return !this.workspace.options.readOnly;
}

/** Visually indicates that this comment would be deleted if dropped. */
setDeleteStyle(wouldDelete: boolean): void {
if (wouldDelete) {
dom.addClass(this.getSvgRoot(), 'blocklyDraggingDelete');
} else {
dom.removeClass(this.getSvgRoot(), 'blocklyDraggingDelete');
}
}

/** Returns whether this comment is movable or not. */
isMovable(): boolean {
return this.dragStrategy.isMovable();
Expand Down
10 changes: 9 additions & 1 deletion core/shortcut_items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js';
import {KeyCodes} from './utils/keycodes.js';
import type {WorkspaceSvg} from './workspace_svg.js';
import {isDraggable} from './interfaces/i_draggable.js';
import * as eventUtils from './events/utils.js';

/**
* Object holding the names of the default shortcut items.
Expand Down Expand Up @@ -75,7 +76,14 @@ export function registerDelete() {
if (Gesture.inProgress()) {
return false;
}
(common.getSelected() as BlockSvg).checkAndDelete();
const selected = common.getSelected();
if (selected instanceof BlockSvg) {
selected.checkAndDelete();
} else if (isDeletable(selected) && selected.isDeletable()) {
eventUtils.setGroup(true);
selected.dispose();
eventUtils.setGroup(false);
}
return true;
},
keyCodes: [KeyCodes.DELETE, KeyCodes.BACKSPACE],
Expand Down
Loading