Skip to content

Commit bf19155

Browse files
authored
feat: reset button (ast-grep#682)
1 parent 5215280 commit bf19155

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script lang="ts" setup>
2+
import IconReset from '../icons/Reset.vue'
3+
4+
const state = defineModel()
5+
const config = `
6+
# YAML Rule is more powerful!
7+
# https://ast-grep.github.io/guide/rule-config.html#rule
8+
rule:
9+
any:
10+
- pattern: console.log($A)
11+
- pattern: console.debug($A)
12+
fix:
13+
logger.log($A)
14+
`.trim()
15+
16+
const onReset = () => {
17+
state.value.config = config
18+
state.value.query = 'console.log($MATCH)'
19+
state.value.rewrite = 'logger.log($MATCH)'
20+
}
21+
</script>
22+
23+
<template>
24+
<button class="reset" title="Reset your config" @click="onReset">
25+
<IconReset />
26+
</button>
27+
</template>
28+
29+
<style scoped>
30+
.reset {
31+
width: 2em;
32+
height: 2em;
33+
border-radius: 50%;
34+
padding: 0px;
35+
display: flex;
36+
justify-content: center;
37+
align-items: center;
38+
}
39+
</style>

website/src/components/editors/Monaco.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ watch(isDark, () => {
9898
monaco.editor.setTheme(isDark.value ? 'vs-dark' : 'vs')
9999
})
100100
101+
watch(
102+
() => props.modelValue,
103+
(value) => {
104+
if (editor.value?.getValue() === value) return
105+
editor.value?.setValue(value || '')
106+
},
107+
{ immediate: true },
108+
)
109+
101110
const transformHighlight = (match: number[]) => {
102111
const [sr, sc, er, ec] = match
103112
return {
@@ -193,4 +202,4 @@ onBeforeUnmount(() => {
193202
.monaco-match-span {
194203
background-color: var(--theme-highlight3);
195204
}
196-
</style>
205+
</style>

website/src/icons/Reset.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<template>
2+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
3+
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
4+
<path d="M19.933 13.041a8 8 0 1 1-9.925-8.788c3.899-1 7.935 1.007 9.425 4.747" />
5+
<path d="M20 4v5h-5" />
6+
</g>
7+
</svg>
8+
</template>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy