Skip to content

Commit

Permalink
feat: optional edit area location (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
YangFong committed Jan 9, 2024
1 parent 5767e38 commit 6f572ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/CodemirrorEditor/EditorHeader/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
></i>
暗黑模式
</el-dropdown-item>
<el-dropdown-item divided @click.native="isEditOnLeftChanged">
<i
class="el-icon-check"
:style="{ opacity: isEditOnLeft ? 1 : 0 }"
></i>
左侧编辑
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-dropdown>
Expand Down Expand Up @@ -188,6 +195,7 @@ export default {
config,
citeStatus: false,
isMacCodeBlock: true,
isEditOnLeft: true,
showResetConfirm: false,
selectFont: ``,
selectSize: ``,
Expand Down Expand Up @@ -249,6 +257,7 @@ export default {
nightMode: (state) => state.nightMode,
currentCiteStatus: (state) => state.citeStatus,
currentIsMacCodeBlock: (state) => state.isMacCodeBlock,
currentIsEditOnLeft: (state) => state.isEditOnLeft,
}),
},
methods: {
Expand Down Expand Up @@ -333,6 +342,10 @@ export default {
this.setIsMacCodeBlock(this.isMacCodeBlock)
this.$emit(`refresh`)
},
isEditOnLeftChanged() {
this.isEditOnLeft = !this.isEditOnLeft
this.setIsEditOnLeft(this.isEditOnLeft)
},
// 复制到微信公众号
copy() {
this.$emit(`startCopy`)
Expand Down Expand Up @@ -430,6 +443,7 @@ export default {
`setCurrentCodeTheme`,
`setWxRendererOptions`,
`setIsMacCodeBlock`,
`setIsEditOnLeft`,
]),
},
mounted() {
Expand All @@ -439,6 +453,7 @@ export default {
this.selectCodeTheme = this.codeTheme
this.citeStatus = this.currentCiteStatus
this.isMacCodeBlock = this.currentIsMacCodeBlock
this.isEditOnLeft = this.currentIsEditOnLeft
const fileInput = this.$refs.fileInput
fileInput.onchange = () => {
Expand Down
6 changes: 6 additions & 0 deletions src/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useStore = defineStore(`store`, {
nightMode: false,
codeTheme: config.codeThemeOption[2].value,
isMacCodeBlock: true,
isEditOnLeft: true,
}),
actions: {
setEditorValue(data) {
Expand Down Expand Up @@ -61,6 +62,10 @@ export const useStore = defineStore(`store`, {
this.isMacCodeBlock = data
localStorage.setItem(`isMacCodeBlock`, data)
},
setIsEditOnLeft(data) {
this.isEditOnLeft = data
localStorage.setItem(`isEditOnLeft`, data)
},
themeChanged() {
this.nightMode = !this.nightMode
localStorage.setItem(`nightMode`, this.nightMode)
Expand All @@ -79,6 +84,7 @@ export const useStore = defineStore(`store`, {
this.isMacCodeBlock = !(
localStorage.getItem(`isMacCodeBlock`) === `false`
)
this.isEditOnLeft = !(localStorage.getItem(`isEditOnLeft`) === `false`)
this.wxRenderer = new WxRenderer({
theme: setColor(this.currentColor),
fonts: this.currentFont,
Expand Down
8 changes: 8 additions & 0 deletions src/views/CodemirrorEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<el-main class="main-body">
<el-row class="main-section">
<el-col
:style="{ order: store.isEditOnLeft ? 0 : 1 }"
:span="12"
class="codeMirror-wrapper"
ref="codeMirrorWrapper"
Expand Down Expand Up @@ -609,6 +610,13 @@ export default {
window.PR.prettyPrint()
}, 300)
},
setup() {
const store = useStore()
return {
store,
}
},
}
</script>

Expand Down

0 comments on commit 6f572ba

Please sign in to comment.