Skip to content

Commit 45cbd7e

Browse files
committed
Add Key Map Demo.
1 parent 1f5c0c5 commit 45cbd7e

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src-docs/DemoPage.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { vue } from '@codemirror/lang-vue';
44
import { useDark } from '@vueuse/core';
55
6+
import KeyMapDemo from './components/KeyMapDemo.vue';
7+
import KeyMapDemoSrc from './components/KeyMapDemo.vue?raw';
68
import LinterAndCrossBindingDemo from './components/LinterAndCrossBindingDemo.vue';
79
import LinterAndCrossBindingDemoSrc from './components/LinterAndCrossBindingDemo.vue?raw';
810
import MarkdownDemo from './components/MarkdownDemo.vue';
@@ -20,6 +22,7 @@ const markdownDemoSrc = MarkdownDemoSrc.trim();
2022
const slotDemoSrc = SlotDemoSrc.trim();
2123
const readonlyAndDisabledDemoSrc = ReadonlyAndDisabledDemoSrc.trim();
2224
const linterAndCrossBindingDemoSrc = LinterAndCrossBindingDemoSrc.trim();
25+
const keyMapDemoSrc = KeyMapDemoSrc.trim();
2326
</script>
2427

2528
<template>
@@ -211,5 +214,37 @@ const linterAndCrossBindingDemoSrc = LinterAndCrossBindingDemoSrc.trim();
211214
</div>
212215
</div>
213216
</section>
217+
<section class="mb-5">
218+
<h2>Key Map Demo</h2>
219+
<p>
220+
This is a sample that allows you to define your own keymap. The
221+
<code>keymap</code>
222+
prop is an array of objects that define the keymap.
223+
</p>
224+
<p>
225+
The
226+
<code>run</code>
227+
function is called when the keymap is matched. If it returns
228+
<code>true</code>
229+
, the default behavior of the keymap is not executed.
230+
</p>
231+
<div class="row">
232+
<div class="col-sm">
233+
<code-mirror
234+
v-model="keyMapDemoSrc"
235+
:dark="dark"
236+
:lang="vue()"
237+
basic
238+
wrap
239+
readonly
240+
/>
241+
</div>
242+
<div class="col-sm">
243+
<h3>Demo</h3>
244+
<p>Press Shift+Ctrl+Enter to see the console log.</p>
245+
<key-map-demo />
246+
</div>
247+
</div>
248+
</section>
214249
</div>
215250
</template>

src-docs/components/KeyMapDemo.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script lang="ts" setup>
2+
import { ref } from 'vue';
3+
4+
import CodeMirror from 'vue-codemirror6';
5+
6+
const temp = ref('Press Shift+Ctrl+Enter here to see the console log.');
7+
</script>
8+
9+
<template>
10+
<code-mirror
11+
v-model="temp"
12+
tab
13+
basic
14+
:keymap="[
15+
{
16+
key: 'Shift-Ctrl-Enter',
17+
run: () => {
18+
console.log('Shift+Ctrl+Enter');
19+
return true;
20+
},
21+
},
22+
]"
23+
/>
24+
</template>

src-docs/components/ReadonlyAndDisabledDemo.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ defineProps({ dark: Boolean });
3838
<label class="form-check-label" for="disabled">Disabled</label>
3939
</div>
4040
<code-mirror :dark="dark" basic :readonly="isReadonly" :disabled="isDisabled">
41-
<pre>
42-
色は匂へど 散りぬるを
41+
<pre
42+
>色は匂へど 散りぬるを
4343
我が世誰そ 常ならむ
4444
有為の奥山 今日越えて
4545
浅き夢見じ 酔ひもせず</pre

0 commit comments

Comments
 (0)