Skip to content

Commit

Permalink
feat: reset button (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangmo8 authored Feb 13, 2025
1 parent 5215280 commit bf19155
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
39 changes: 39 additions & 0 deletions website/src/components/ResetConfig.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script lang="ts" setup>
import IconReset from '../icons/Reset.vue'
const state = defineModel()
const config = `
# YAML Rule is more powerful!
# https://ast-grep.github.io/guide/rule-config.html#rule
rule:
any:
- pattern: console.log($A)
- pattern: console.debug($A)
fix:
logger.log($A)
`.trim()
const onReset = () => {
state.value.config = config

Check failure on line 17 in website/src/components/ResetConfig.vue

View workflow job for this annotation

GitHub Actions / build

'state.value' is of type 'unknown'.
state.value.query = 'console.log($MATCH)'

Check failure on line 18 in website/src/components/ResetConfig.vue

View workflow job for this annotation

GitHub Actions / build

'state.value' is of type 'unknown'.
state.value.rewrite = 'logger.log($MATCH)'

Check failure on line 19 in website/src/components/ResetConfig.vue

View workflow job for this annotation

GitHub Actions / build

'state.value' is of type 'unknown'.
}
</script>

<template>
<button class="reset" title="Reset your config" @click="onReset">
<IconReset />
</button>
</template>

<style scoped>
.reset {
width: 2em;
height: 2em;
border-radius: 50%;
padding: 0px;
display: flex;
justify-content: center;
align-items: center;
}
</style>
11 changes: 10 additions & 1 deletion website/src/components/editors/Monaco.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ watch(isDark, () => {
monaco.editor.setTheme(isDark.value ? 'vs-dark' : 'vs')
})
watch(
() => props.modelValue,
(value) => {
if (editor.value?.getValue() === value) return
editor.value?.setValue(value || '')
},
{ immediate: true },
)
const transformHighlight = (match: number[]) => {
const [sr, sc, er, ec] = match
return {
Expand Down Expand Up @@ -193,4 +202,4 @@ onBeforeUnmount(() => {
.monaco-match-span {
background-color: var(--theme-highlight3);
}
</style>
</style>
8 changes: 8 additions & 0 deletions website/src/icons/Reset.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<path d="M19.933 13.041a8 8 0 1 1-9.925-8.788c3.899-1 7.935 1.007 9.425 4.747" />
<path d="M20 4v5h-5" />
</g>
</svg>
</template>

0 comments on commit bf19155

Please sign in to comment.