Skip to content

Commit 12c6906

Browse files
feat: use escape to exit from markdown, code & screenshot previews (#235)
1 parent 3fb66e4 commit 12c6906

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/renderer/components/editor/EditorPreview.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ import { computed, ref, onMounted, watch } from 'vue'
4747
import interact from 'interactjs'
4848
import { useAppStore } from '@/store/app'
4949
import { i18n, ipc, track } from '@/electron'
50+
import { useMagicKeys } from '@vueuse/core'
5051
5152
const snippetStore = useSnippetStore()
5253
const appStore = useAppStore()
54+
const { escape } = useMagicKeys()
55+
5356
const srcDoc = ref()
5457
const height = computed(() => appStore.sizes.codePreviewHeight + 'px')
5558
@@ -112,6 +115,10 @@ const onClickSnippetShowcase = () => {
112115
track('app/open-url', 'https://masscode.io/snippets')
113116
}
114117
118+
watch(escape, () => {
119+
snippetStore.isCodePreview = false
120+
})
121+
115122
onMounted(() => {
116123
interact(previewRef.value).resizable({
117124
edges: { top: true },

src/renderer/components/markdown/TheMarkdown.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import mermaid from 'mermaid'
1818
import { useHljsTheme, goToSnippet } from '@/composable'
1919
import { useCodemirror } from '@/composable/codemirror'
2020
import { nanoid } from 'nanoid'
21+
import { useMagicKeys } from '@vueuse/core'
2122
2223
const isDev = import.meta.env.DEV
2324
@@ -38,6 +39,7 @@ const props = withDefaults(defineProps<Props>(), {
3839
3940
const appStore = useAppStore()
4041
const snippetStore = useSnippetStore()
42+
const { escape } = useMagicKeys()
4143
4244
const renderedHtml = ref()
4345
@@ -269,6 +271,10 @@ watch(
269271
}
270272
)
271273
274+
watch(escape, () => {
275+
snippetStore.isMarkdownPreview = false
276+
})
277+
272278
init()
273279
274280
onMounted(() => {

src/renderer/components/screenshot/TheScreenshot.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<div class="right">
2727
<AppActionButton
2828
v-tooltip="i18n.t('saveScreenshot')"
29-
@click="onSaveScreenshot">
29+
@click="onSaveScreenshot"
30+
>
3031
<UniconsFileDownload />
3132
</AppActionButton>
3233
</div>
@@ -109,6 +110,7 @@ import { computed, onMounted, ref, watch } from 'vue'
109110
import { useHljsTheme } from '@/composable'
110111
import { store, track, i18n } from '@/electron'
111112
import { useSnippetStore } from '@/store/snippets'
113+
import { useMagicKeys } from '@vueuse/core'
112114
113115
const GUTTER_RIGHT_OFFSET = 10
114116
const GUTTER_WIDTH = 8
@@ -125,6 +127,7 @@ const props = defineProps<Props>()
125127
126128
const appStore = useAppStore()
127129
const snippetStore = useSnippetStore()
130+
const { escape } = useMagicKeys()
128131
129132
const frameRef = ref<HTMLElement>()
130133
const snippetRef = ref<HTMLElement>()
@@ -211,6 +214,10 @@ watch(
211214
{ deep: true }
212215
)
213216
217+
watch(escape, () => {
218+
snippetStore.isScreenshotPreview = false
219+
})
220+
214221
onMounted(() => {
215222
interact(frameRef.value!).resizable({
216223
allowFrom: gutterRef.value!,

0 commit comments

Comments
 (0)