Skip to content

Commit 9010456

Browse files
authored
Merge pull request #2 from mdnice/develop
update develop branch
2 parents bd63796 + 931535a commit 9010456

File tree

10 files changed

+143
-87
lines changed

10 files changed

+143
-87
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ v1.4.0 发布日期:2019-11-02
77
- 修复 Safari 无法复制问题
88
- 新增主题「极客黑」、「简」
99
- 修改主题「蓝山」为「前端之巅同款」
10+
- 新增快捷键
1011

1112
v1.3.1 发布日期:2019-10-28
1213

src/component/Dialog/FormDialog.js

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {observer, inject} from "mobx-react";
3-
import {Modal, Input, Form, message} from "antd";
3+
import {Modal, InputNumber, Form} from "antd";
44

55
@inject("dialog")
66
@inject("content")
@@ -26,7 +26,7 @@ class FormDialog extends React.Component {
2626
appendText += " |";
2727
}
2828
}
29-
return appendText + (/macintosh|mac\sos\sx+/i.test(navigator.userAgent) ? "\n" : "\r\n");
29+
return appendText + (/windows|win32/i.test(navigator.userAgent) ? "\r\n" : "\n");
3030
};
3131

3232
buildFormFormat = (rowNum, columnNum) => {
@@ -41,17 +41,13 @@ class FormDialog extends React.Component {
4141
};
4242

4343
handleOk = () => {
44-
const columnCheck = this.state.columnNum <= 10;
45-
const rowCheck = this.state.rowNum <= 10;
46-
if (columnCheck && rowCheck) {
47-
const {markdownEditor} = this.props.content;
48-
const cursor = markdownEditor.getCursor();
49-
const text = this.buildFormFormat(this.state.rowNum, this.state.columnNum);
50-
markdownEditor.replaceSelection(text, cursor);
44+
const {markdownEditor} = this.props.content;
45+
const cursor = markdownEditor.getCursor();
46+
const text = this.buildFormFormat(this.state.rowNum, this.state.columnNum);
47+
markdownEditor.replaceSelection(text, cursor);
5148

52-
const content = markdownEditor.getValue();
53-
this.props.content.setContent(content);
54-
} else message.error(`${rowCheck ? "" : "行数"}${columnCheck ? "" : "列数"}不能大于10`);
49+
const content = markdownEditor.getValue();
50+
this.props.content.setContent(content);
5551

5652
this.handleCancel();
5753
};
@@ -61,12 +57,6 @@ class FormDialog extends React.Component {
6157
this.props.dialog.setFormOpen(false);
6258
};
6359

64-
handleChange = (value, target) => {
65-
this.setState({
66-
[target]: value,
67-
});
68-
};
69-
7060
render() {
7161
return (
7262
<Modal
@@ -77,37 +67,32 @@ class FormDialog extends React.Component {
7767
onOk={this.handleOk}
7868
onCancel={this.handleCancel}
7969
>
80-
<div style={style.column}>
81-
<Form.Item label="行">
82-
<Input
83-
placeholder="请输入表格的行数"
84-
value={this.state.rowNum}
85-
onChange={(e) => this.handleChange(e.target.value, "rowNum")}
86-
/>
87-
</Form.Item>
88-
<Form.Item label="列">
89-
<Input
90-
placeholder="请输入表格的列数"
91-
value={this.state.columnNum}
92-
onChange={(e) => this.handleChange(e.target.value, "columnNum")}
93-
/>
94-
</Form.Item>
95-
</div>
70+
<Form.Item label="行数" labelCol={{span: 4}}>
71+
<InputNumber
72+
min={2}
73+
max={10}
74+
value={this.state.rowNum}
75+
defaultValue={1}
76+
onChange={(value) => this.setState({rowNum: value})}
77+
/>
78+
</Form.Item>
79+
<Form.Item label="列数" labelCol={{span: 4}}>
80+
<InputNumber
81+
min={1}
82+
max={10}
83+
value={this.state.columnNum}
84+
defaultValue={1}
85+
onChange={(value) => this.setState({columnNum: value})}
86+
/>
87+
</Form.Item>
9688
</Modal>
9789
);
9890
}
9991
}
10092

10193
const initialState = {
102-
columnNum: 0,
103-
rowNum: 0,
104-
};
105-
106-
const style = {
107-
column: {
108-
display: "flex",
109-
flexDirection: "column",
110-
},
94+
columnNum: 1,
95+
rowNum: 2,
11196
};
11297

11398
export default FormDialog;

src/component/Form.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, {Component} from "react";
2+
import {inject, observer} from "mobx-react";
3+
import {Tooltip, Button} from "antd";
4+
5+
import {ENTER_DELAY, LEAVE_DELAY} from "../utils/constant";
6+
import SvgIcon from "../icon";
7+
8+
@inject("dialog")
9+
@observer
10+
class Form extends Component {
11+
showModal = () => {
12+
this.props.dialog.setFormOpen(true);
13+
};
14+
15+
render() {
16+
return (
17+
<Tooltip placement="bottom" mouseEnterDelay={ENTER_DELAY} mouseLeaveDelay={LEAVE_DELAY} title="表格">
18+
<Button style={style.btnPadding} onClick={this.showModal}>
19+
<SvgIcon name="form" style={style.svgIcon} />
20+
</Button>
21+
</Tooltip>
22+
);
23+
}
24+
}
25+
26+
const style = {
27+
btnPadding: {
28+
padding: "0",
29+
},
30+
svgIcon: {
31+
padding: "6px 7px 10px 7px",
32+
width: "33px",
33+
height: "33px",
34+
},
35+
};
36+
37+
export default Form;

src/icon/Form.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import "./index.css";
3+
4+
export default ({fill = "rgba(0,0,0,0.65)", style = {}, className = "icon", viewBox = "0 0 1024 1024"}) => (
5+
<svg style={style} viewBox={viewBox} className={className} fill={fill} xmlns="http://www.w3.org/2000/svg">
6+
<path
7+
d="M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32z m-40 208H676V232h212v136z m0 224H676V432h212v160zM412 432h200v160H412V432z m200-64H412V232h200v136z m-476 64h212v160H136V432z m0-200h212v136H136V232z m0 424h212v136H136V656z m276 0h200v136H412V656z m476 136H676V656h212v136z"
8+
p-id="1250"
9+
/>
10+
</svg>
11+
);

src/icon/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Del from "./Del";
88
import Down from "./Down";
99
import Environment from "./Environment";
1010
import Font from "./Font";
11+
import Form from "./Form";
1112
import FullScreen from "./FullScreen";
1213
import GitHub from "./GitHub";
1314
import Inbox from "./Inbox";
@@ -66,6 +67,8 @@ export default (props) => {
6667
return <PC {...props} />;
6768
case "mobile":
6869
return <Mobile {...props} />;
70+
case "form":
71+
return <Form {...props} />;
6972
default:
7073
return <svg />;
7174
}

src/layout/Navbar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Copy from "../component/Copy";
88
import Reset from "../component/Reset";
99
import Image from "../component/Image";
1010
import Link from "../component/Link";
11+
import Form from "../component/Form";
1112
import Code from "../component/Code";
1213
import Italic from "../component/Italic";
1314
import Bold from "../component/Bold";
@@ -40,6 +41,7 @@ class Navbar extends Component {
4041
<ButtonGroup style={style.btnGroupMargin}>
4142
<Link />
4243
<Image />
44+
<Form />
4345
</ButtonGroup>
4446
<ButtonGroup style={style.btnGroupRight}>
4547
<Reset />

src/layout/StyleEditor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class StyleEditor extends Component {
2626
getStyleInstance = (instance) => {
2727
if (instance) {
2828
this.styleEditor = instance.editor;
29-
this.styleEditor.on("keyup", (cm, e) => {
30-
if ((e.keyCode >= 65 && e.keyCode <= 90) || e.keyCode === 189) {
31-
cm.showHint(e);
29+
this.styleEditor.on("keyup", (cm, event) => {
30+
if ((event.keyCode >= 65 && event.keyCode <= 90) || event.keyCode === 189) {
31+
cm.showHint({completeSingle: false});
3232
}
3333
});
3434
}

src/utils/hotkey.js

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const handlePressHotkey = (type, content) => {
22
const {markdownEditor} = content;
33
const cursor = markdownEditor.getCursor();
44
const selection = markdownEditor.getSelection();
5+
const wrapChar = /windows|win32/i.test(navigator.userAgent) ? "\r\n" : "\n";
56
switch (type) {
67
case "Bold":
78
markdownEditor.replaceSelection(`**${selection}**`, cursor);
@@ -13,6 +14,9 @@ const handlePressHotkey = (type, content) => {
1314
markdownEditor.replaceSelection(`*${selection}*`, cursor);
1415
break;
1516
case "Code":
17+
markdownEditor.replaceSelection(`${wrapChar}\`\`\`${wrapChar}${selection}${wrapChar}\`\`\`${wrapChar}`);
18+
break;
19+
case "InlineCode":
1620
markdownEditor.replaceSelection(`\`${selection}\``, cursor);
1721
break;
1822
case "H1":
@@ -24,12 +28,6 @@ const handlePressHotkey = (type, content) => {
2428
case "H3":
2529
markdownEditor.replaceSelection(`### ${selection}`, cursor);
2630
break;
27-
case "H4":
28-
markdownEditor.replaceSelection(`#### ${selection}`, cursor);
29-
break;
30-
case "H5":
31-
markdownEditor.replaceSelection(`##### ${selection}`, cursor);
32-
break;
3331
default:
3432
return;
3533
}
@@ -39,80 +37,75 @@ const handlePressHotkey = (type, content) => {
3937
};
4038

4139
const bindHotkeys = (content, dialog) =>
42-
/macintosh|mac\sos\s+x/i.test(navigator.userAgent)
40+
// /macintosh|mac\sos\s+x/i.test(navigator.userAgent)
41+
/windows|win32/i.test(navigator.userAgent)
4342
? {
44-
"Cmd-B": () => {
43+
"Ctrl-B": () => {
4544
handlePressHotkey("Bold", content);
4645
},
47-
"Cmd-U": () => {
46+
"Ctrl-U": () => {
4847
handlePressHotkey("Del", content);
4948
},
50-
"Cmd-I": () => {
49+
"Ctrl-I": () => {
5150
handlePressHotkey("Italic", content);
5251
},
53-
"Cmd-Alt-C": () => {
52+
"Ctrl-Alt-C": () => {
5453
handlePressHotkey("Code", content);
5554
},
56-
"Cmd-Alt-1": () => {
55+
"Ctrl-Alt-F": () => {
56+
handlePressHotkey("InlineCode", content);
57+
},
58+
"Ctrl-Alt-1": () => {
5759
handlePressHotkey("H1", content);
5860
},
59-
"Cmd-Alt-2": () => {
61+
"Ctrl-Alt-2": () => {
6062
handlePressHotkey("H2", content);
6163
},
62-
"Cmd-Alt-3": () => {
64+
"Ctrl-Alt-3": () => {
6365
handlePressHotkey("H3", content);
6466
},
65-
"Cmd-Alt-4": () => {
66-
handlePressHotkey("H4", content);
67-
},
68-
"Cmd-Alt-5": () => {
69-
handlePressHotkey("H5", content);
70-
},
71-
"Cmd-K": () => {
67+
"Ctrl-K": () => {
7268
dialog.setLinkOpen(true);
7369
},
74-
"Cmd-Alt-I": () => {
70+
"Ctrl-Alt-I": () => {
7571
dialog.setImageOpen(true);
7672
},
77-
"Cmd-Alt-T": () => {
73+
"Ctrl-Alt-T": () => {
7874
dialog.setFormOpen(true);
7975
},
8076
}
8177
: {
82-
"Ctrl-B": () => {
78+
"Cmd-B": () => {
8379
handlePressHotkey("Bold", content);
8480
},
85-
"Ctrl-U": () => {
81+
"Cmd-U": () => {
8682
handlePressHotkey("Del", content);
8783
},
88-
"Ctrl-I": () => {
84+
"Cmd-I": () => {
8985
handlePressHotkey("Italic", content);
9086
},
91-
"Ctrl-Alt-F": () => {
87+
"Cmd-Alt-C": () => {
9288
handlePressHotkey("Code", content);
9389
},
94-
"Ctrl-Alt-1": () => {
90+
"Cmd-Alt-F": () => {
91+
handlePressHotkey("InlineCode", content);
92+
},
93+
"Cmd-Alt-1": () => {
9594
handlePressHotkey("H1", content);
9695
},
97-
"Ctrl-Alt-2": () => {
96+
"Cmd-Alt-2": () => {
9897
handlePressHotkey("H2", content);
9998
},
100-
"Ctrl-Alt-3": () => {
99+
"Cmd-Alt-3": () => {
101100
handlePressHotkey("H3", content);
102101
},
103-
"Ctrl-Alt-4": () => {
104-
handlePressHotkey("H4", content);
105-
},
106-
"Ctrl-Alt-5": () => {
107-
handlePressHotkey("H5", content);
108-
},
109-
"Ctrl-K": () => {
102+
"Cmd-K": () => {
110103
dialog.setLinkOpen(true);
111104
},
112-
"Ctrl-Alt-I": () => {
105+
"Cmd-Alt-I": () => {
113106
dialog.setImageOpen(true);
114107
},
115-
"Ctrl-Alt-T": () => {
108+
"Cmd-Alt-T": () => {
116109
dialog.setFormOpen(true);
117110
},
118111
};

src/utils/mdMirror.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
.cm-s-md-mirror div.CodeMirror-selected {
1919
background: #e0e0e0;
2020
}
21+
22+
.cm-s-md-mirror pre.CodeMirror-line {
23+
word-break: break-all;
24+
}
25+
2126
.cm-s-md-mirror .CodeMirror-line::selection,
2227
.cm-s-md-mirror .CodeMirror-line > span::selection,
2328
.cm-s-md-mirror .CodeMirror-line > span > span::selection {

src/utils/styleMirror.css

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@
9898
background: #dddcdc;
9999
}
100100
.cm-s-style-mirror .CodeMirror-matchingbracket {
101-
color: rgb(32,32,32) !important;
102-
background-color: rgba(0,0,0,0.1) !important;
101+
color: rgb(32, 32, 32) !important;
102+
background-color: rgba(0, 0, 0, 0.1) !important;
103+
}
104+
105+
.CodeMirror-hints {
106+
background-color: rgb(245, 245, 245);
107+
font-size: 14px;
108+
font-family: 'source-code-pro', Menlo, 'Courier New', Consolas, monospace;
109+
}
110+
111+
.CodeMirror-hints li {
112+
line-height: 20px;
113+
}
114+
115+
li.CodeMirror-hint-active {
116+
color: black;
117+
background-color: rgb(202,222,185);
118+
}
119+
120+
.CodeMirror-hints li:hover {
121+
background-color: rgb(224, 224, 224);
103122
}

0 commit comments

Comments
 (0)