feat: improve code editor formatting behavior
- Disable auto-formatting while in editing mode - Format CSS only when exiting editing mode - Auto-disable editing mode when switching tabs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
de5d12c0fa
commit
0df5d7c6e9
2 changed files with 23 additions and 3 deletions
|
|
@ -24,7 +24,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed, watch, inject } from 'vue';
|
||||||
import { useStylesheetStore } from '../stores/stylesheet';
|
import { useStylesheetStore } from '../stores/stylesheet';
|
||||||
import hljs from 'highlight.js/lib/core';
|
import hljs from 'highlight.js/lib/core';
|
||||||
import css from 'highlight.js/lib/languages/css';
|
import css from 'highlight.js/lib/languages/css';
|
||||||
|
|
@ -33,6 +33,7 @@ import 'highlight.js/styles/atom-one-dark.css';
|
||||||
hljs.registerLanguage('css', css);
|
hljs.registerLanguage('css', css);
|
||||||
|
|
||||||
const stylesheetStore = useStylesheetStore();
|
const stylesheetStore = useStylesheetStore();
|
||||||
|
const activeTab = inject('activeTab');
|
||||||
const isEditable = ref(false);
|
const isEditable = ref(false);
|
||||||
let debounceTimer = null;
|
let debounceTimer = null;
|
||||||
|
|
||||||
|
|
@ -52,6 +53,23 @@ const handleInput = (event) => {
|
||||||
stylesheetStore.content = newContent;
|
stylesheetStore.content = newContent;
|
||||||
}, 500);
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Sync editing mode with store
|
||||||
|
watch(isEditable, async (newValue, oldValue) => {
|
||||||
|
stylesheetStore.isEditing = newValue;
|
||||||
|
|
||||||
|
// Format when exiting editing mode
|
||||||
|
if (oldValue && !newValue) {
|
||||||
|
await stylesheetStore.formatContent();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Disable editing mode when changing tabs
|
||||||
|
watch(activeTab, (newTab) => {
|
||||||
|
if (newTab !== 'code' && isEditable.value) {
|
||||||
|
isEditable.value = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import parserPostcss from 'prettier/plugins/postcss';
|
||||||
|
|
||||||
export const useStylesheetStore = defineStore('stylesheet', () => {
|
export const useStylesheetStore = defineStore('stylesheet', () => {
|
||||||
const content = ref('');
|
const content = ref('');
|
||||||
|
const isEditing = ref(false);
|
||||||
let formatTimer = null;
|
let formatTimer = null;
|
||||||
let isFormatting = false;
|
let isFormatting = false;
|
||||||
|
|
||||||
|
|
@ -30,9 +31,9 @@ export const useStylesheetStore = defineStore('stylesheet', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Watch content and format after 500ms of inactivity
|
// Watch content and format after 500ms of inactivity (only when not editing)
|
||||||
watch(content, () => {
|
watch(content, () => {
|
||||||
if (isFormatting) return;
|
if (isFormatting || isEditing.value) return;
|
||||||
|
|
||||||
clearTimeout(formatTimer);
|
clearTimeout(formatTimer);
|
||||||
formatTimer = setTimeout(() => {
|
formatTimer = setTimeout(() => {
|
||||||
|
|
@ -65,6 +66,7 @@ export const useStylesheetStore = defineStore('stylesheet', () => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content,
|
content,
|
||||||
|
isEditing,
|
||||||
loadStylesheet,
|
loadStylesheet,
|
||||||
updateProperty,
|
updateProperty,
|
||||||
extractValue,
|
extractValue,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue