aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/GlobalKeyHandler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/GlobalKeyHandler.ts')
-rw-r--r--src/client/views/GlobalKeyHandler.ts87
1 files changed, 42 insertions, 45 deletions
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index 5e700e281..47dcdd2e4 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -1,23 +1,20 @@
import { random } from 'lodash';
-import { action, observable, runInAction } from 'mobx';
-import { DateField } from '../../fields/DateField';
+import { action, runInAction } from 'mobx';
import { Doc, DocListCast } from '../../fields/Doc';
import { Id } from '../../fields/FieldSymbols';
import { InkTool } from '../../fields/InkField';
-import { List } from '../../fields/List';
import { ScriptField } from '../../fields/ScriptField';
-import { Cast, DocCast, PromiseValue } from '../../fields/Types';
+import { Cast, PromiseValue } from '../../fields/Types';
import { GoogleAuthenticationManager } from '../apis/GoogleAuthenticationManager';
-import { DocServer } from '../DocServer';
-import { DocumentType } from '../documents/DocumentTypes';
import { DragManager } from '../util/DragManager';
import { GroupManager } from '../util/GroupManager';
import { SelectionManager } from '../util/SelectionManager';
import { SettingsManager } from '../util/SettingsManager';
import { SharingManager } from '../util/SharingManager';
import { SnappingManager } from '../util/SnappingManager';
-import { undoBatch, UndoManager } from '../util/UndoManager';
+import { UndoManager } from '../util/UndoManager';
import { CollectionDockingView } from './collections/CollectionDockingView';
+import { CollectionFreeFormView } from './collections/collectionFreeForm';
import { CollectionFreeFormViewChrome } from './collections/CollectionMenu';
import { CollectionStackedTimeline } from './collections/CollectionStackedTimeline';
import { ContextMenu } from './ContextMenu';
@@ -103,6 +100,20 @@ export class KeyManager {
const groupings = SelectionManager.Views().slice();
const randomGroup = random(0, 1000);
+ const collectionView = groupings.reduce(
+ (col, g) => (col === null || g.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView === col ? g.props.CollectionFreeFormDocumentView?.().props.CollectionFreeFormView : undefined),
+ null as null | undefined | CollectionFreeFormView
+ );
+ if (collectionView) {
+ UndoManager.RunInBatch(() => {
+ collectionView._marqueeViewRef.current?.collection(
+ e,
+ true,
+ groupings.map(g => g.rootDoc)
+ );
+ }, 'grouping');
+ break;
+ }
UndoManager.RunInBatch(() => groupings.map(dv => (dv.layoutDoc.group = randomGroup)), 'group');
SelectionManager.DeselectAll();
break;
@@ -146,12 +157,10 @@ export class KeyManager {
case 'delete':
case 'backspace':
if (document.activeElement?.tagName !== 'INPUT' && document.activeElement?.tagName !== 'TEXTAREA') {
- UndoManager.RunInBatch(() => {
- if (LightboxView.LightboxDoc) {
- LightboxView.SetLightboxDoc(undefined);
- SelectionManager.DeselectAll();
- } else DocumentDecorations.Instance.onCloseClick(true);
- }, 'backspace');
+ if (LightboxView.LightboxDoc) {
+ LightboxView.SetLightboxDoc(undefined);
+ SelectionManager.DeselectAll();
+ } else DocumentDecorations.Instance.onCloseClick(true);
return { stopPropagation: true, preventDefault: true };
}
break;
@@ -192,6 +201,16 @@ export class KeyManager {
case 'arrowdown':
UndoManager.RunInBatch(() => SelectionManager.Views().map(dv => dv.props.CollectionFreeFormDocumentView?.().nudge?.(0, 10)), 'nudge down');
break;
+ case 'g':
+ if (document.activeElement?.tagName === 'INPUT' || document.activeElement?.tagName === 'TEXTAREA') {
+ return { stopPropagation: false, preventDefault: false };
+ }
+
+ const groupings = SelectionManager.Views().slice();
+ const randomGroup = random(0, 1000);
+ UndoManager.RunInBatch(() => groupings.map(dv => (dv.layoutDoc.group = randomGroup)), 'group');
+ SelectionManager.DeselectAll();
+ break;
}
return {
@@ -327,38 +346,13 @@ export class KeyManager {
});
public paste(e: ClipboardEvent) {
- const plain = e.clipboardData?.getData('text/plain');
- const clone = plain?.startsWith('__DashCloneId(');
- if (plain && (plain.startsWith('__DashDocId(') || clone)) {
- const first = SelectionManager.Views().length ? SelectionManager.Views()[0] : undefined;
- if (first?.props.Document.type === DocumentType.COL) {
- const docids = plain.split(':');
- let count = 1;
- const list: Doc[] = [];
- const targetDataDoc = Doc.GetProto(first.props.Document);
- const fieldKey = first.LayoutFieldKey;
- const docList = DocListCast(targetDataDoc[fieldKey]);
- docids.map(
- (did, i) =>
- i &&
- DocServer.GetRefField(did).then(async doc => {
- count++;
- if (doc instanceof Doc) {
- list.push(doc);
- }
- if (count === docids.length) {
- const added = await Promise.all(list.filter(d => !docList.includes(d)).map(async d => (clone ? (await Doc.MakeClone(d)).clone : d)));
- if (added.length) {
- added.map(doc => (doc.context = targetDataDoc));
- undoBatch(() => {
- targetDataDoc[fieldKey] = new List<Doc>([...docList, ...added]);
- targetDataDoc[fieldKey + '-lastModified'] = new DateField(new Date(Date.now()));
- })();
- }
- }
- })
- );
- }
+ const plain = e.clipboardData?.getData('text/plain'); // list of document ids, separated by ':'s
+ if (!plain) return;
+ const clone = plain.startsWith('__DashCloneId(');
+ const docids = plain.split(':'); // hack! docids[0] is the top left of the selection rectangle
+ const addDocument = SelectionManager.Views().lastElement()?.ComponentView?.addDocument;
+ if (addDocument && (plain.startsWith('__DashDocId(') || clone)) {
+ Doc.Paste(docids.slice(1), clone, addDocument);
}
}
@@ -374,6 +368,9 @@ export class KeyManager {
case 'z':
UndoManager.Redo();
break;
+ case 'p':
+ Doc.ActiveTool = InkTool.Write;
+ break;
}
return {