From a30cbfd90f3b5207fc790a1c8dc61e58f69f4e38 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Wed, 5 Jun 2019 22:13:34 -0400 Subject: tab focus shifting on tab drag over and beginnings of global key handling, including splitting with control + rightarrow --- src/client/views/MainView.tsx | 36 +++++++++++++++++++--- .../views/collections/CollectionDockingView.tsx | 20 ++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index 408d454f4..67a026897 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -26,13 +26,14 @@ import { PreviewCursor } from './PreviewCursor'; import { SearchBox } from './SearchBox'; import { SelectionManager } from '../util/SelectionManager'; import { FieldResult, Field, Doc, Opt, DocListCast } from '../../new_fields/Doc'; -import { Cast, FieldValue, StrCast } from '../../new_fields/Types'; +import { Cast, FieldValue, StrCast, PromiseValue } from '../../new_fields/Types'; import { DocServer } from '../DocServer'; import { listSpec } from '../../new_fields/Schema'; import { Id } from '../../new_fields/FieldSymbols'; import { HistoryUtil } from '../util/History'; import { CollectionBaseView } from './collections/CollectionBaseView'; - +import { timingSafeEqual } from 'crypto'; +import * as _ from "lodash"; @observer export class MainView extends React.Component { @@ -43,6 +44,14 @@ export class MainView extends React.Component { @computed private get mainContainer(): Opt { return FieldValue(Cast(CurrentUserUtils.UserDocument.activeWorkspace, Doc)); } + @computed private get mainFreeform(): Opt { + let docs = DocListCast(this.mainContainer!.data); + return (docs && docs.length > 1) ? docs[1] : undefined; + } + private globalDisplayFlags = observable({ + jumpToVisible: false + }); + private set mainContainer(doc: Opt) { if (doc) { if (!("presentationView" in doc)) { @@ -308,6 +317,7 @@ export class MainView extends React.Component { this.isSearchVisible = !this.isSearchVisible; } + @action globalKeyHandler = (e: KeyboardEvent) => { if (e.key === "Control" || !e.ctrlKey) return; @@ -316,11 +326,28 @@ export class MainView extends React.Component { switch (e.key) { case "ArrowRight": - CollectionDockingView.Instance.AddRightSplit(this.mainContainer!); - console.log("split screen right"); + if (this.mainFreeform) { + CollectionDockingView.Instance.AddRightSplit(this.mainFreeform!); + } + break; + case "ArrowLeft": + if (this.mainFreeform) { + CollectionDockingView.Instance.CloseRightSplit(this.mainFreeform!); + } + break; + case "o": + this.globalDisplayFlags.jumpToVisible = true; + break; + case "escape": + _.mapValues(this.globalDisplayFlags, () => false) + break; } } + renderJumpTo = () => { + return
JUMP TO
; + } + render() { return (
@@ -332,6 +359,7 @@ export class MainView extends React.Component { {this.miscButtons} + {this.globalDisplayFlags.jumpToVisible ? this.renderJumpTo() : (null)}
); } diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index dcc1bd95d..4b7868e81 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -44,6 +44,7 @@ export class CollectionDockingView extends React.Component(); private _flush: boolean = false; private _ignoreStateChange = ""; + private _isPointerDown = false; constructor(props: SubCollectionViewProps) { super(props); @@ -247,6 +248,7 @@ export class CollectionDockingView extends React.Component { + this._isPointerDown = false; if (this._flush) { this._flush = false; setTimeout(() => this.stateChanged(), 10); @@ -254,6 +256,7 @@ export class CollectionDockingView extends React.Component { + this._isPointerDown = true; var className = (e.target as any).className; if (className === "messageCounter") { e.stopPropagation(); @@ -334,6 +337,23 @@ export class CollectionDockingView extends React.Component { + if (!this._isPointerDown) return; + var activeContentItem = tab.header.parent.getActiveContentItem(); + if (tab.contentItem !== activeContentItem) { + tab.header.parent.setActiveContentItem(tab.contentItem); + } + tab.setActive(true); + } + // tab.element[0].ondragenter = (e: any) => { + // console.log("DRAGGING OVER DETECTED!"); + // console.log(e); + // } + // tab.element[0].ondrag = (e: any) => { + // console.log("DRAGGING!"); + // console.log(e); + // } ReactDOM.render( CollectionDockingView.Instance.AddTab(stack, doc)} />, upDiv); tab.reactComponents = [upDiv]; tab.element.append(upDiv); -- cgit v1.2.3-70-g09d2