diff --git a/webapp/src/components/cardDetail.tsx b/webapp/src/components/cardDetail.tsx index 5fc1434e2..9622ed3b1 100644 --- a/webapp/src/components/cardDetail.tsx +++ b/webapp/src/components/cardDetail.tsx @@ -13,9 +13,9 @@ import {Utils} from '../utils' import MenuWrapper from '../widgets/menuWrapper' import Menu from '../widgets/menu' +import Editable from '../widgets/editable' import Button from './button' -import {Editable} from './editable' import {MarkdownEditor} from './markdownEditor' import ContentBlock from './contentBlock' import CommentsList from './commentsList' @@ -32,6 +32,7 @@ type Props = { type State = { cardTree?: CardTree + title: string } class CardDetail extends React.Component { @@ -44,7 +45,9 @@ class CardDetail extends React.Component { constructor(props: Props) { super(props) - this.state = {} + this.state = { + title: '', + } } componentDidMount() { @@ -52,11 +55,11 @@ class CardDetail extends React.Component { this.cardListener.open([this.props.cardId], async (blockId) => { Utils.log(`cardListener.onChanged: ${blockId}`) await cardTree.sync() - this.setState({...this.state, cardTree}) + this.setState({cardTree}) }) const cardTree = new MutableCardTree(this.props.cardId) cardTree.sync().then(() => { - this.setState({...this.state, cardTree}) + this.setState({cardTree, title: cardTree.card.title}) setTimeout(() => { if (this.titleRef.current) { this.titleRef.current.focus() @@ -79,8 +82,6 @@ class CardDetail extends React.Component { } const {card, comments} = cardTree - const newCommentRef = React.createRef() - const sendCommentButtonRef = React.createRef() let contentElements if (cardTree.contents.length > 0) { contentElements = @@ -151,10 +152,21 @@ class CardDetail extends React.Component { { - mutator.changeTitle(card, text) + onChange={(title: string) => this.setState({title})} + onBlur={() => mutator.changeTitle(card, this.state.title)} + onFocus={() => this.titleRef.current.focus()} + onKeyDown={(e: React.KeyboardEvent): void => { + if (e.keyCode === 27 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { // ESC + e.stopPropagation() + this.setState({title: this.state.cardTree.card.title}) + setTimeout(() => this.titleRef.current.blur(), 0) + } else if (e.keyCode === 13 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { // Return + e.stopPropagation() + mutator.changeTitle(card, this.state.title) + this.titleRef.current.blur() + } }} />