aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/GlobalKeyHandler.ts
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-05-15 22:41:58 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-05-15 22:41:58 +0530
commit0cc83ef72b6b1b254d97bf07a97dd1fe936aa25a (patch)
treebce434d8545a953fd943743f0714609f23529220 /src/client/views/GlobalKeyHandler.ts
parent9c0b8ab5820232292e02fbf453e50261137a533c (diff)
parent98c7540fff67c232c1b04f2130ee624f9a70afbd (diff)
resolved conflicts
Diffstat (limited to 'src/client/views/GlobalKeyHandler.ts')
-rw-r--r--src/client/views/GlobalKeyHandler.ts76
1 files changed, 69 insertions, 7 deletions
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index 185222541..255142771 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -1,17 +1,26 @@
-import { UndoManager } from "../util/UndoManager";
+import { UndoManager, undoBatch } from "../util/UndoManager";
import { SelectionManager } from "../util/SelectionManager";
import { CollectionDockingView } from "./collections/CollectionDockingView";
import { MainView } from "./MainView";
import { DragManager } from "../util/DragManager";
import { action, runInAction } from "mobx";
-import { Doc } from "../../new_fields/Doc";
+import { Doc, DocListCast } from "../../fields/Doc";
import { DictationManager } from "../util/DictationManager";
import SharingManager from "../util/SharingManager";
-import { Cast, PromiseValue, NumCast } from "../../new_fields/Types";
-import { ScriptField } from "../../new_fields/ScriptField";
+import { Cast, PromiseValue, NumCast } from "../../fields/Types";
+import { ScriptField } from "../../fields/ScriptField";
import { InkingControl } from "./InkingControl";
-import { InkTool } from "../../new_fields/InkField";
+import { InkTool } from "../../fields/InkField";
import { DocumentView } from "./nodes/DocumentView";
+import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager";
+import { CollectionFreeFormView } from "./collections/collectionFreeForm/CollectionFreeFormView";
+import { MarqueeView } from "./collections/collectionFreeForm/MarqueeView";
+import { Id } from "../../fields/FieldSymbols";
+import { DocumentDecorations } from "./DocumentDecorations";
+import { DocumentType } from "../documents/DocumentTypes";
+import { DocServer } from "../DocServer";
+import { List } from "../../fields/List";
+import { DateField } from "../../fields/DateField";
const modifiers = ["control", "meta", "shift", "alt"];
type KeyHandler = (keycode: string, e: KeyboardEvent) => KeyControlInfo | Promise<KeyControlInfo>;
@@ -64,6 +73,9 @@ export default class KeyManager {
private unmodified = action((keyname: string, e: KeyboardEvent) => {
switch (keyname) {
+ case " ":
+ MarqueeView.DragMarquee = !MarqueeView.DragMarquee;
+ break;
case "escape":
const main = MainView.Instance;
InkingControl.Instance.switchTool(InkTool.None);
@@ -79,6 +91,7 @@ export default class KeyManager {
SelectionManager.DeselectAll();
DictationManager.Controls.stop();
// RecommendationsBox.Instance.closeMenu();
+ GoogleAuthenticationManager.Instance.cancel();
SharingManager.Instance.close();
break;
case "delete":
@@ -233,11 +246,30 @@ export default class KeyManager {
break;
case "a":
case "v":
- case "x":
- case "c":
stopPropagation = false;
preventDefault = false;
break;
+ case "x":
+ if (SelectionManager.SelectedDocuments().length) {
+ const bds = DocumentDecorations.Instance.Bounds;
+ const pt = [bds.x + (bds.r - bds.x) / 2, bds.y + (bds.b - bds.y) / 2];
+ const text = `__DashDocId(${pt[0]},${pt[1]}):` + SelectionManager.SelectedDocuments().map(dv => dv.Document[Id]).join(":");
+ SelectionManager.SelectedDocuments().length && navigator.clipboard.writeText(text);
+ DocumentDecorations.Instance.onCloseClick(undefined);
+ stopPropagation = false;
+ preventDefault = false;
+ }
+ break;
+ case "c":
+ if (SelectionManager.SelectedDocuments().length) {
+ const bds = DocumentDecorations.Instance.Bounds;
+ const pt = SelectionManager.SelectedDocuments()[0].props.ScreenToLocalTransform().transformPoint(bds.x + (bds.r - bds.x) / 2, bds.y + (bds.b - bds.y) / 2);
+ const text = `__DashDocId(${pt?.[0] || 0},${pt?.[1] || 0}):` + SelectionManager.SelectedDocuments().map(dv => dv.Document[Id]).join(":");
+ SelectionManager.SelectedDocuments().length && navigator.clipboard.writeText(text);
+ stopPropagation = false;
+ preventDefault = false;
+ }
+ break;
}
return {
@@ -246,6 +278,36 @@ export default class KeyManager {
};
});
+ public paste(e: ClipboardEvent) {
+ if (e.clipboardData?.getData("text/plain") !== "" && e.clipboardData?.getData("text/plain").startsWith("__DashDocId(")) {
+ const first = SelectionManager.SelectedDocuments().length ? SelectionManager.SelectedDocuments()[0] : undefined;
+ if (first?.props.Document.type === DocumentType.COL) {
+ const docids = e.clipboardData.getData("text/plain").split(":");
+ let count = 1;
+ const list: Doc[] = [];
+ const targetDataDoc = Doc.GetProto(first.props.Document);
+ const fieldKey = Doc.LayoutFieldKey(first.props.Document);
+ const docList = DocListCast(targetDataDoc[fieldKey]);
+ docids.map((did, i) => i && DocServer.GetRefField(did).then(doc => {
+ count++;
+ if (doc instanceof Doc) {
+ list.push(doc);
+ }
+ if (count === docids.length) {
+ const added = list.filter(d => !docList.includes(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()));
+ })();
+ }
+ }
+ }));
+ }
+ }
+ }
+
async printClipboard() {
const text: string = await navigator.clipboard.readText();
}