<template>
    <!-- :indent-with-tab="true" 是否自动获取焦点-->
    <div class="codemirrorDiv">
        <codemirror :modelValue="pythonCode" placeholder="" style="height: 100%" :autofocus="true" 
        :tabSize="2" :extensions="extensions" :indent-with-tab="true" />
        <!-- <div v-if="codeMirrorShow" class="codeMirrorMask"></div> -->
    </div>
</template>

<script setup>
import { Codemirror } from "vue-codemirror";
import { python } from "@codemirror/lang-python";
// import { oneDark } from "@codemirror/theme-one-dark";
import { EditorView } from "@codemirror/view"
import { ref } from "vue";
let myTheme = EditorView.theme({
    // 输入的字体颜色
    "&": {
        color: "#0052D9",
        backgroundColor: "#FFFFFF"
    },
    ".cm-content": {
        caretColor: "#0052D9",
    },
    // 激活背景色
    // ".cm-activeLine": {
    //     backgroundColor: "#FAFAFA"
    // },
    // 激活序列的背景色
    ".cm-activeLineGutter": {
        backgroundColor: "#FAFAFA"
    },
    //光标的颜色
    "&.cm-focused .cm-cursor": {
        borderLeftColor: "#FAFAFA"
    },
    // 选中的状态
    "&.cm-focused .cm-selectionBackground, ::selection": {
        backgroundColor: "#FAFAFA",
        color: '#FFFFFF'
    },
    // 左侧侧边栏的颜色
    ".cm-gutters": {
        backgroundColor: "#FFFFFF",
        color: "#ddd", //侧边栏文字颜色
        border: "none"
    },
    // ".cm-activeLine": {
    //     backgroundColor: "#2c4fcd"
    // },
}, {
    dark: false,
})
const extensions =[python(), myTheme];
// 接受的参数
const props = defineProps({
    pythonCode: {
        type: String,
        require: true,
        default: ""
    },
    codeMirrorShow: {
        type: Boolean,
        require: true,
        default: true
    }
})
const innerPythonCode = ref(props.pythonCode)

</script>
<style scoped>
.codemirrorDiv {
    position: relative;
    width: 100%;
    height: 100%;

    .codemirror-container {
        /* 设置背景色 */
        background-color: #f5f5f5;
        /* 设置字体颜色 */
        color: #333;
    }
}

.codeMirrorMask {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    background: rgba(0, 0, 0, 0);
}
</style>