From fc7c485ba98834f6b771d713c0323c45f7f2beea Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 9 Mar 2019 20:00:45 -0800 Subject: [PATCH] Add 'n' shortcut for new doc Fixed cmd+enter shortcut to publish doc Fixed keyboard shortcut display on non-mac Fixed heading alignment Fixed documents smaller than page should not scroll --- app/components/ClickablePadding.js | 3 +-- .../Sidebar/components/Collections.js | 17 +++++++++++- app/models/Document.js | 2 +- app/scenes/Document/Document.js | 7 +++-- app/scenes/Document/components/Editor.js | 2 ++ app/scenes/Document/components/Header.js | 6 +++-- app/scenes/KeyboardShortcuts.js | 26 ++++++++++++------- app/scenes/Search/Search.js | 5 ++-- app/utils/keyboard.js | 3 +++ shared/components/Flex.js | 2 ++ 10 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 app/utils/keyboard.js diff --git a/app/components/ClickablePadding.js b/app/components/ClickablePadding.js index dde8c6795..7cb739c15 100644 --- a/app/components/ClickablePadding.js +++ b/app/components/ClickablePadding.js @@ -2,9 +2,8 @@ import styled from 'styled-components'; const ClickablePadding = styled.div` - min-height: 50vh; cursor: ${({ onClick }) => (onClick ? 'text' : 'default')}; - ${({ grow }) => grow && `flex-grow: 1;`}; + ${({ grow }) => grow && `flex-grow: 100;`}; `; export default ClickablePadding; diff --git a/app/components/Sidebar/components/Collections.js b/app/components/Sidebar/components/Collections.js index a0205511e..c1d938e4b 100644 --- a/app/components/Sidebar/components/Collections.js +++ b/app/components/Sidebar/components/Collections.js @@ -1,8 +1,11 @@ // @flow import * as React from 'react'; import { observer, inject } from 'mobx-react'; +import { withRouter } from 'react-router-dom'; +import keydown from 'react-keydown'; import Flex from 'shared/components/Flex'; import { PlusIcon } from 'outline-icons'; +import { newDocumentUrl } from 'utils/routeHelpers'; import Header from './Header'; import SidebarLink from './SidebarLink'; @@ -14,6 +17,7 @@ import UiStore from 'stores/UiStore'; import DocumentsStore from 'stores/DocumentsStore'; type Props = { + history: Object, collections: CollectionsStore, documents: DocumentsStore, onCreateCollection: () => void, @@ -28,8 +32,17 @@ class Collections extends React.Component { this.props.collections.fetchPage({ limit: 100 }); } + @keydown('n') + goToNewDocument() { + const activeCollection = this.props.collections.active; + if (!activeCollection) return; + + this.props.history.push(newDocumentUrl(activeCollection)); + } + render() { const { collections, ui, documents } = this.props; + const content = (
Collections
@@ -57,4 +70,6 @@ class Collections extends React.Component { } } -export default inject('collections', 'ui', 'documents')(Collections); +export default inject('collections', 'ui', 'documents')( + withRouter(Collections) +); diff --git a/app/models/Document.js b/app/models/Document.js index d06bf60a7..e6e593321 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -86,7 +86,7 @@ export default class Document extends BaseModel { @computed get isEmpty(): boolean { // Check if the document title has been modified and user generated content exists - return this.text.replace(new RegExp(`^#$`), '').trim().length === 0; + return this.text.replace(/^#/, '').trim().length === 0; } @computed diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index 3c8299881..f436a1dc8 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -194,6 +194,10 @@ class DocumentScene extends React.Component { handleCloseMoveModal = () => (this.moveModalOpen = false); handleOpenMoveModal = () => (this.moveModalOpen = true); + onSaveAndExit = () => { + this.onSave({ done: true, publish: true }); + }; + onSave = async ( options: { done?: boolean, publish?: boolean, autosave?: boolean } = {} ) => { @@ -367,7 +371,7 @@ class DocumentScene extends React.Component { onImageUploadStop={this.onImageUploadStop} onSearchLink={this.onSearchLink} onChange={this.onChange} - onSave={this.onSave} + onSave={this.onSaveAndExit} onCancel={this.onDiscard} readOnly={!this.isEditing} toc={!revision} @@ -387,7 +391,6 @@ const MaxWidth = styled(Flex)` padding: 0 16px; max-width: 100vw; width: 100%; - height: 100%; ${breakpoint('tablet')` padding: 0 24px; diff --git a/app/scenes/Document/components/Editor.js b/app/scenes/Document/components/Editor.js index 6dd4b5170..67cb5879b 100644 --- a/app/scenes/Document/components/Editor.js +++ b/app/scenes/Document/components/Editor.js @@ -48,6 +48,8 @@ class DocumentEditor extends React.Component { } const StyledEditor = styled(Editor)` + justify-content: start; + p { ${Placeholder} { visibility: hidden; diff --git a/app/scenes/Document/components/Header.js b/app/scenes/Document/components/Header.js index 54c78847a..972392006 100644 --- a/app/scenes/Document/components/Header.js +++ b/app/scenes/Document/components/Header.js @@ -10,6 +10,7 @@ import { NewDocumentIcon } from 'outline-icons'; import Document from 'models/Document'; import AuthStore from 'stores/AuthStore'; import { documentEditUrl } from 'utils/routeHelpers'; +import { meta } from 'utils/keyboard'; import Flex from 'shared/components/Flex'; import Breadcrumb from './Breadcrumb'; @@ -107,6 +108,7 @@ class Header extends React.Component { justify="space-between" readOnly={!isEditing} isCompact={this.isScrolled} + shrink={false} > {