aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/GlobalKeyHandler.ts
diff options
context:
space:
mode:
authorEric <ericmabr@gmail.com>2023-08-13 16:08:28 -0400
committerEric <ericmabr@gmail.com>2023-08-13 16:08:28 -0400
commit0020ec69b847c8607affb57babddfddc812dc9b6 (patch)
treee24255039015745d2073806bee97ce449ddb5260 /src/client/views/GlobalKeyHandler.ts
parent7b2553514bb000eb7f618eb0f0d653baee78742c (diff)
parent3b45f1d30a947dc1702ec347b83e98374c5b603c (diff)
Merge branch 'master' into UI_Update_Eric_Ma
Diffstat (limited to 'src/client/views/GlobalKeyHandler.ts')
-rw-r--r--src/client/views/GlobalKeyHandler.ts87
1 files changed, 34 insertions, 53 deletions
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index b9b92dd2b..7b693c8da 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -1,22 +1,18 @@
import { random } from 'lodash';
import { action, runInAction } from 'mobx';
-import { DateField } from '../../fields/DateField';
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, 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';
@@ -161,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;
@@ -267,6 +261,18 @@ export class KeyManager {
case 't':
PromiseValue(Cast(Doc.UserDoc()['tabs-button-tools'], Doc)).then(pv => pv && (pv.onClick as ScriptField).script.run({ this: pv }));
break;
+ case 'i':
+ const importBtn = DocListCast(Doc.MyLeftSidebarMenu.data).find(d => d.target === Doc.MyImports);
+ if (importBtn) {
+ MainView.Instance.selectMenu(importBtn);
+ }
+ break;
+ case 's':
+ const trailsBtn = DocListCast(Doc.MyLeftSidebarMenu.data).find(d => d.target === Doc.MyTrails);
+ if (trailsBtn) {
+ MainView.Instance.selectMenu(trailsBtn);
+ }
+ break;
case 'f':
if (SelectionManager.Views().length === 1 && SelectionManager.Views()[0].ComponentView?.search) {
SelectionManager.Views()[0].ComponentView?.search?.('', false, false);
@@ -278,26 +284,26 @@ export class KeyManager {
}
break;
case 'e':
- Doc.ActiveTool = InkTool.Eraser;
+ Doc.ActiveTool = (Doc.ActiveTool === InkTool.Eraser ? InkTool.None : InkTool.Eraser);
break;
case 'p':
- Doc.ActiveTool = InkTool.Pen;
- break;
- case 'o':
- const target = SelectionManager.Docs().lastElement();
- target && CollectionDockingView.OpenFullScreen(target);
+ Doc.ActiveTool = (Doc.ActiveTool === InkTool.Pen ? InkTool.None : InkTool.Pen);
break;
case 'r':
preventDefault = false;
break;
case 'y':
- SelectionManager.DeselectAll();
- UndoManager.Redo();
+ if (Doc.ActivePage !== 'home') {
+ SelectionManager.DeselectAll();
+ UndoManager.Redo();
+ }
stopPropagation = false;
break;
case 'z':
- SelectionManager.DeselectAll();
- UndoManager.Undo();
+ if (Doc.ActivePage !== 'home') {
+ SelectionManager.DeselectAll();
+ UndoManager.Undo();
+ }
stopPropagation = false;
break;
case 'a':
@@ -352,38 +358,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, true)).clone : d)));
- if (added.length) {
- added.map(doc => (doc.embedContainer = targetDataDoc));
- undoBatch(() => {
- targetDataDoc[fieldKey] = new List<Doc>([...docList, ...added]);
- targetDataDoc[fieldKey + '_modificationDate'] = 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);
}
}