-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
blockquote.js
61 lines (48 loc) · 1.54 KB
/
blockquote.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
58
59
60
61
/**
* @fileoverview Implements Blockquote markdown command
* @author Sungho Kim(sungho-kim@nhnent.com) FE Development Team/NHN Ent.
*/
import CommandManager from '../commandManager';
/**
* Blockquote
* Add blockquote markdown syntax to markdown editor
* @extends Command
* @module markdownCommands/Blockquote
* @ignore
*/
const Blockquote = CommandManager.command('markdown', /** @lends Blockquote */{
name: 'Blockquote',
keyMap: ['CTRL+Q', 'META+Q'],
/**
* 커맨드 핸들러
* @param {MarkdownEditor} mde MarkdownEditor instance
*/
exec(mde) {
const cm = mde.getEditor();
const doc = cm.getDoc();
// range 을 가공함
const range = mde.getCurrentRange();
const from = {
line: range.from.line,
ch: 0
};
const to = {
line: range.to.line,
ch: doc.getLineHandle(range.to.line).text.length
};
// 영역의 텍스트를 가저오고
const textToModify = doc.getRange(from, to);
// 텍스트 컨텐트를 변경 한다
const textLinesToModify = textToModify.split('\n');
const lineLength = textLinesToModify.length;
for (let i = 0; i < lineLength; i += 1) {
textLinesToModify[i] = `>${textLinesToModify[i]}`;
}
// 해당 에디터의 내용을 변경한다
doc.replaceRange(textLinesToModify.join('\n'), from, to);
range.to.ch += 1;
doc.setCursor(range.to);
cm.focus();
}
});
export default Blockquote;