forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
101 lines (95 loc) · 2.56 KB
/
index.js
File metadata and controls
101 lines (95 loc) · 2.56 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { ipcRenderer } from 'electron'
import { isSamePathSync } from 'common/filesystem/paths'
import bus from '../bus'
export const tabsMixins = {
methods: {
selectFile (file) {
if (file.id !== this.currentFile.id) {
this.$store.dispatch('UPDATE_CURRENT_FILE', file)
}
},
removeFileInTab (file) {
const { isSaved } = file
if (isSaved) {
this.$store.dispatch('FORCE_CLOSE_TAB', file)
} else {
this.$store.dispatch('CLOSE_UNSAVED_TAB', file)
}
}
}
}
export const loadingPageMixins = {
methods: {
hideLoadingPage () {
const loadingPage = document.querySelector('#loading-page')
if (loadingPage) {
loadingPage.remove()
}
}
}
}
export const fileMixins = {
methods: {
handleSearchResultClick (searchMatch) {
const { range } = searchMatch
const { filePath } = this.searchResult
const openedTab = this.tabs.find(file => isSamePathSync(file.pathname, filePath))
const cursor = {
isCollapsed: range[0][0] !== range[1][0],
anchor: {
line: range[0][0],
ch: range[0][1]
},
focus: {
line: range[1][0],
ch: range[1][1]
}
}
if (openedTab) {
openedTab.cursor = cursor
if (this.currentFile !== openedTab) {
this.$store.dispatch('UPDATE_CURRENT_FILE', openedTab)
} else {
const { id, markdown, cursor, history } = this.currentFile
bus.$emit('file-changed', { id, markdown, cursor, renderCursor: true, history })
}
} else {
ipcRenderer.send('mt::open-file', filePath, {
cursor
})
}
},
handleFileClick () {
const { isMarkdown, pathname } = this.file
if (!isMarkdown) return
const openedTab = this.tabs.find(file => isSamePathSync(file.pathname, pathname))
if (openedTab) {
if (this.currentFile === openedTab) {
return
}
this.$store.dispatch('UPDATE_CURRENT_FILE', openedTab)
} else {
ipcRenderer.send('mt::open-file', pathname, {})
}
}
}
}
export const createFileOrDirectoryMixins = {
methods: {
handleInputFocus () {
this.$nextTick(() => {
if (this.$refs.input) {
this.$refs.input.focus()
this.createName = ''
if (this.folder) {
this.folder.isCollapsed = false
}
}
})
},
handleInputEnter () {
const { createName } = this
this.$store.dispatch('CREATE_FILE_DIRECTORY', createName)
}
}
}