MCPcopy
hub / github.com/alibaba/lowcode-engine / init

Function init

packages/engine/src/inner-plugins/builtin-hotkey.ts:226–546  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

224export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
225 return {
226 init() {
227 const { hotkey, project, logger, canvas } = ctx;
228 const { clipboard } = canvas;
229 // hotkey binding
230 hotkey.bind(['backspace', 'del'], (e: KeyboardEvent, action) => {
231 logger.info(`action ${action} is triggered`);
232
233 if (canvas.isInLiveEditing) {
234 return;
235 }
236 // TODO: use focus-tracker
237 const doc = project.currentDocument;
238 if (isFormEvent(e) || !doc) {
239 return;
240 }
241 e.preventDefault();
242
243 const sel = doc.selection;
244 const topItems = sel.getTopNodes();
245 // TODO: check can remove
246 topItems.forEach((node) => {
247 if (node?.canPerformAction('remove')) {
248 node && doc.removeNode(node);
249 }
250 });
251 sel.clear();
252 });
253
254 hotkey.bind('escape', (e: KeyboardEvent, action) => {
255 logger.info(`action ${action} is triggered`);
256
257 if (canvas.isInLiveEditing) {
258 return;
259 }
260 const sel = project.currentDocument?.selection;
261 if (isFormEvent(e) || !sel) {
262 return;
263 }
264 e.preventDefault();
265
266 sel.clear();
267 // currentFocus.esc();
268 });
269
270 // command + c copy command + x cut
271 hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => {
272 logger.info(`action ${action} is triggered`);
273 if (canvas.isInLiveEditing) {
274 return;
275 }
276 const doc = project.currentDocument;
277 if (isFormEvent(e) || !doc) {
278 return;
279 }
280 const anchorValue = document.getSelection()?.anchorNode?.nodeValue;
281 if (anchorValue && typeof anchorValue === 'string') {
282 return;
283 }

Callers

nothing calls this directly

Calls 15

isFormEventFunction · 0.85
getSuitableInsertionFunction · 0.85
getNextForSelectFunction · 0.85
getPrevForSelectFunction · 0.85
getSuitablePlaceForNodeFunction · 0.85
insertChildrenFunction · 0.70
bindMethod · 0.65
infoMethod · 0.65
getTopNodesMethod · 0.65
forEachMethod · 0.65
canPerformActionMethod · 0.65
removeNodeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…