Fixes link editing

This commit is contained in:
Tom Moor
2017-10-23 20:13:22 -07:00
parent 6ef886ad2a
commit e79897e5cb
4 changed files with 25 additions and 10 deletions

View File

@ -3,7 +3,7 @@ import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { Editor, Plain } from 'slate';
import keydown from 'react-keydown';
import type { Document, State, Editor as EditorType } from './types';
import type { State, Editor as EditorType } from './types';
import getDataTransferFiles from 'utils/getDataTransferFiles';
import Flex from 'components/Flex';
import ClickablePadding from './components/ClickablePadding';
@ -76,10 +76,10 @@ type KeyData = {
onChange = (state: State) => {
this.setState({ state });
};
onDocumentChange = (document: Document, state: State) => {
this.props.onChange(Markdown.serialize(state));
if (this.state.state !== state) {
this.props.onChange(Markdown.serialize(state));
}
};
handleDrop = async (ev: SyntheticEvent) => {
@ -205,7 +205,6 @@ type KeyData = {
state={this.state.state}
onKeyDown={this.onKeyDown}
onChange={this.onChange}
onDocumentChange={this.onDocumentChange}
onSave={onSave}
readOnly={readOnly}
/>

View File

@ -3,7 +3,7 @@ import React from 'react';
import styled from 'styled-components';
import { fontWeight, color } from 'styles/constants';
import Document from 'models/Document';
import GoToIcon from 'components/Icon/GoToIcon';
import NextIcon from 'components/Icon/NextIcon';
type Props = {
innerRef?: Function,
@ -14,7 +14,7 @@ type Props = {
function DocumentResult({ document, ...rest }: Props) {
return (
<ListItem {...rest} href="">
<i><GoToIcon light /></i>
<i><NextIcon light /></i>
{document.title}
</ListItem>
);

View File

@ -114,9 +114,10 @@ class LinkToolbar extends Component {
const { state } = this.props;
const transform = state.transform();
if (state.selection.isExpanded) {
if (href) {
transform.setInline({ type: 'link', data: { href } });
} else {
transform.unwrapInline('link');
if (href) transform.wrapInline({ type: 'link', data: { href } });
}
this.props.onChange(transform.apply());
@ -179,7 +180,7 @@ class LinkToolbar extends Component {
}
const SearchResults = styled.div`
background: rgba(34, 34, 34, .95);
background: #2F3336;
position: absolute;
top: 100%;
width: 100%;