-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
hr.js
57 lines (47 loc) 路 1.27 KB
/
hr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @fileoverview HR markdown command
* @author Sungho Kim(sungho-kim@nhnent.com) FE Development Team/NHN Ent.
*/
import CommandManager from '../commandManager';
/**
* HR
* Add HR markdown syntax to markdown editor
* @extends Command
* @module markdownCommands/HR
* @ignore
*/
const HR = CommandManager.command('markdown', /** @lends HR */{
name: 'HR',
keyMap: ['CTRL+L', 'META+L'],
/**
* Command handler
* @param {MarkdownEditor} mde MarkdownEditor instance
*/
exec(mde) {
const cm = mde.getEditor();
const doc = cm.getDoc();
let replaceText = '';
const range = mde.getCurrentRange();
const from = {
line: range.from.line,
ch: range.from.ch
};
const to = {
line: range.to.line,
ch: range.to.ch
};
if (range.collapsed) {
replaceText = doc.getLine(from.line);
from.ch = 0;
to.ch = doc.getLineHandle(range.to.line).text.length;
}
if (doc.getLine(from.line).length) {
replaceText += '\n\n* * *\n\n';
} else {
replaceText += '\n* * *\n';
}
doc.replaceRange(replaceText, from, to);
cm.focus();
}
});
export default HR;