forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss.ts
More file actions
41 lines (39 loc) · 1.1 KB
/
Copy pathcss.ts
File metadata and controls
41 lines (39 loc) · 1.1 KB
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
import { css } from '@codemirror/lang-css'
import { EditorView, keymap } from '@codemirror/view'
import { formatDoc } from '../utils/fileHelpers'
import { basicSetup } from './basicSetup'
/**
* CSS 格式化处理函数
*/
async function formatCSS(view: EditorView) {
const content = view.state.doc.toString()
const formatted = await formatDoc(content, `css`)
view.dispatch({
changes: { from: 0, to: view.state.doc.length, insert: formatted },
})
}
/**
* CSS 编辑器的基础扩展集合
*
* 包含:
* - basicSetup(无行号、代码折叠、自动补全、括号匹配等完整功能)
* - 自动换行(无横向滚动)
* - CSS 语言支持
* - 格式化功能(Shift-Alt-f)
*
* basicSetup 包含的功能详见 ./basicSetup.ts
*
* 主题请使用统一的 theme() 函数,从 './themes' 导入
*/
export function cssSetup() {
return [
basicSetup,
css(),
// 自动换行,禁用横向滚动
EditorView.lineWrapping,
// 格式化快捷键
keymap.of([
{ key: `Shift-Alt-f`, run: (view: EditorView) => { formatCSS(view); return true } },
]),
]
}