forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlineEnding.js
More file actions
55 lines (46 loc) · 1.48 KB
/
lineEnding.js
File metadata and controls
55 lines (46 loc) · 1.48 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { ipcRenderer } from 'electron'
import { delay } from '@/util'
import bus from '../bus'
const crlfDescription = 'Carriage return and line feed (CRLF)'
const lfDescription = 'Line feed (LF)'
class LineEndingCommand {
constructor (editorState) {
this.id = 'file.line-ending'
this.description = 'File: Change Line Ending'
this.placeholder = 'Select an option'
this.subcommands = [{
id: 'file.line-ending-crlf',
description: crlfDescription,
value: 'crlf'
}, {
id: 'file.line-ending-lf',
description: lfDescription,
value: 'lf'
}]
this.subcommandSelectedIndex = -1
// Reference to editor state.
this._editorState = editorState
}
run = async () => {
const { lineEnding } = this._editorState.currentFile
if (lineEnding === 'crlf') {
this.subcommandSelectedIndex = 0
this.subcommands[0].description = `${crlfDescription} - current`
this.subcommands[1].description = lfDescription
} else {
this.subcommandSelectedIndex = 1
this.subcommands[0].description = crlfDescription
this.subcommands[1].description = `${lfDescription} - current`
}
}
execute = async () => {
// Timeout to hide the command palette and then show again to prevent issues.
await delay(100)
bus.$emit('show-command-palette', this)
}
executeSubcommand = async (_, value) => {
ipcRenderer.emit('mt::set-line-ending', null, value)
}
unload = () => {}
}
export default LineEndingCommand