fix
This commit is contained in:
@@ -196,7 +196,7 @@ watch(
|
|||||||
placement="bottom-end"
|
placement="bottom-end"
|
||||||
scrollable
|
scrollable
|
||||||
:show-arrow="false"
|
:show-arrow="false"
|
||||||
style="max-height: 600px;"
|
style="max-height: 600px"
|
||||||
:show="showResult"
|
:show="showResult"
|
||||||
@clickoutside="showResult = false"
|
@clickoutside="showResult = false"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ interface FlowchartEditorInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 通过inject获取FlowchartEditor组件的引用
|
// 通过inject获取FlowchartEditor组件的引用
|
||||||
const flowchartEditorRef = inject<Ref<FlowchartEditorInstance | null>>("flowchartEditorRef")
|
const flowchartEditorRef =
|
||||||
|
inject<Ref<FlowchartEditorInstance | null>>("flowchartEditorRef")
|
||||||
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
|
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
|
||||||
|
|
||||||
// 基础组合式函数
|
// 基础组合式函数
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { cpp } from "@codemirror/lang-cpp"
|
import { cpp } from "@codemirror/lang-cpp"
|
||||||
import { python } from "@codemirror/lang-python"
|
import { python } from "@codemirror/lang-python"
|
||||||
import { EditorView } from "@codemirror/view"
|
import { bracketMatching } from "@codemirror/language"
|
||||||
import { Codemirror } from "vue-codemirror"
|
import { Codemirror } from "vue-codemirror"
|
||||||
import { autocompletion } from "@codemirror/autocomplete"
|
import {
|
||||||
import { LANGUAGE } from "utils/types"
|
autocompletion,
|
||||||
|
closeBrackets,
|
||||||
|
completeAnyWord,
|
||||||
|
} from "@codemirror/autocomplete"
|
||||||
|
import type { LANGUAGE } from "utils/types"
|
||||||
import { oneDark } from "../themes/oneDark"
|
import { oneDark } from "../themes/oneDark"
|
||||||
import { smoothy } from "../themes/smoothy"
|
import { smoothy } from "../themes/smoothy"
|
||||||
|
import { styleTheme } from "shared/extensions/baseTheme"
|
||||||
import { enhanceCompletion } from "shared/extensions/autocompletion"
|
import { enhanceCompletion } from "shared/extensions/autocompletion"
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -30,14 +35,6 @@ const code = defineModel<string>("value")
|
|||||||
|
|
||||||
const isDark = useDark()
|
const isDark = useDark()
|
||||||
|
|
||||||
const styleTheme = EditorView.baseTheme({
|
|
||||||
"& .cm-scroller": { "font-family": "Monaco" },
|
|
||||||
"&.cm-editor.cm-focused": { outline: "none" },
|
|
||||||
"&.cm-editor .cm-tooltip.cm-tooltip-autocomplete ul": {
|
|
||||||
"font-family": "Monaco",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const langExtension = computed(() => {
|
const langExtension = computed(() => {
|
||||||
return ["Python2", "Python3"].includes(props.language) ? python() : cpp()
|
return ["Python2", "Python3"].includes(props.language) ? python() : cpp()
|
||||||
})
|
})
|
||||||
@@ -45,8 +42,10 @@ const langExtension = computed(() => {
|
|||||||
const extensions = computed(() => [
|
const extensions = computed(() => [
|
||||||
styleTheme,
|
styleTheme,
|
||||||
langExtension.value,
|
langExtension.value,
|
||||||
|
bracketMatching(),
|
||||||
|
closeBrackets(),
|
||||||
autocompletion({
|
autocompletion({
|
||||||
override: [enhanceCompletion(props.language)],
|
override: [enhanceCompletion(props.language), completeAnyWord],
|
||||||
}),
|
}),
|
||||||
isDark.value ? oneDark : smoothy,
|
isDark.value ? oneDark : smoothy,
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { cpp } from "@codemirror/lang-cpp"
|
import { cpp } from "@codemirror/lang-cpp"
|
||||||
import { python } from "@codemirror/lang-python"
|
import { python } from "@codemirror/lang-python"
|
||||||
|
import { bracketMatching } from "@codemirror/language"
|
||||||
import { EditorView } from "@codemirror/view"
|
import { EditorView } from "@codemirror/view"
|
||||||
import { Codemirror } from "vue-codemirror"
|
import { Codemirror } from "vue-codemirror"
|
||||||
import { autocompletion } from "@codemirror/autocomplete"
|
import {
|
||||||
|
autocompletion,
|
||||||
|
closeBrackets,
|
||||||
|
completeAnyWord,
|
||||||
|
} from "@codemirror/autocomplete"
|
||||||
import type { Extension } from "@codemirror/state"
|
import type { Extension } from "@codemirror/state"
|
||||||
import { LANGUAGE } from "utils/types"
|
import type { LANGUAGE } from "utils/types"
|
||||||
import { oneDark } from "../themes/oneDark"
|
import { oneDark } from "../themes/oneDark"
|
||||||
import { smoothy } from "../themes/smoothy"
|
import { smoothy } from "../themes/smoothy"
|
||||||
|
import { styleTheme } from "shared/extensions/baseTheme"
|
||||||
import { useCodeSync, SYNC_ERROR_CODES } from "../composables/sync"
|
import { useCodeSync, SYNC_ERROR_CODES } from "../composables/sync"
|
||||||
import { useBreakpoints } from "../composables/breakpoints"
|
import { useBreakpoints } from "../composables/breakpoints"
|
||||||
import { enhanceCompletion } from "shared/extensions/autocompletion"
|
import { enhanceCompletion } from "shared/extensions/autocompletion"
|
||||||
@@ -50,14 +56,6 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const { isDesktop } = useBreakpoints()
|
const { isDesktop } = useBreakpoints()
|
||||||
|
|
||||||
const styleTheme = EditorView.baseTheme({
|
|
||||||
"& .cm-scroller": { "font-family": "Monaco" },
|
|
||||||
"&.cm-editor.cm-focused": { outline: "none" },
|
|
||||||
"&.cm-editor .cm-tooltip.cm-tooltip-autocomplete ul": {
|
|
||||||
"font-family": "Monaco",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const langExtension = computed((): Extension => {
|
const langExtension = computed((): Extension => {
|
||||||
return ["Python2", "Python3"].includes(props.language) ? python() : cpp()
|
return ["Python2", "Python3"].includes(props.language) ? python() : cpp()
|
||||||
})
|
})
|
||||||
@@ -65,9 +63,11 @@ const langExtension = computed((): Extension => {
|
|||||||
const extensions = computed(() => [
|
const extensions = computed(() => [
|
||||||
styleTheme,
|
styleTheme,
|
||||||
langExtension.value,
|
langExtension.value,
|
||||||
|
bracketMatching(),
|
||||||
|
closeBrackets(),
|
||||||
isDark.value ? oneDark : smoothy,
|
isDark.value ? oneDark : smoothy,
|
||||||
autocompletion({
|
autocompletion({
|
||||||
override: [enhanceCompletion(props.language)],
|
override: [enhanceCompletion(props.language), completeAnyWord],
|
||||||
}),
|
}),
|
||||||
getInitialExtension(),
|
getInitialExtension(),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type {
|
|||||||
CompletionSource,
|
CompletionSource,
|
||||||
} from "@codemirror/autocomplete"
|
} from "@codemirror/autocomplete"
|
||||||
import type { EditorView } from "@codemirror/view"
|
import type { EditorView } from "@codemirror/view"
|
||||||
import { LANGUAGE } from "utils/types"
|
import type { LANGUAGE } from "utils/types"
|
||||||
import { c } from "./c"
|
import { c } from "./c"
|
||||||
import { python } from "./python"
|
import { python } from "./python"
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export function enhanceCompletion(language: LANGUAGE): CompletionSource {
|
|||||||
context: CompletionContext,
|
context: CompletionContext,
|
||||||
): Promise<CompletionResult | null> {
|
): Promise<CompletionResult | null> {
|
||||||
const word = context.matchBefore(/\w+/)
|
const word = context.matchBefore(/\w+/)
|
||||||
if (!word) return null
|
if (!word && !context.explicit) return null
|
||||||
|
|
||||||
const trulyLanguage = language.startsWith("Python") ? "python" : "c"
|
const trulyLanguage = language.startsWith("Python") ? "python" : "c"
|
||||||
const completions: Completion[] = (
|
const completions: Completion[] = (
|
||||||
@@ -63,7 +63,7 @@ export function enhanceCompletion(language: LANGUAGE): CompletionSource {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
from: word.from,
|
from: word ? word.from : context.pos,
|
||||||
options: completions,
|
options: completions,
|
||||||
validFor: /^\w+$/,
|
validFor: /^\w+$/,
|
||||||
}
|
}
|
||||||
|
|||||||
9
src/shared/extensions/baseTheme.ts
Normal file
9
src/shared/extensions/baseTheme.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { EditorView } from "@codemirror/view"
|
||||||
|
|
||||||
|
export const styleTheme = EditorView.baseTheme({
|
||||||
|
"& .cm-scroller": { "font-family": "Monaco" },
|
||||||
|
"&.cm-editor.cm-focused": { outline: "none" },
|
||||||
|
"&.cm-editor .cm-tooltip.cm-tooltip-autocomplete ul": {
|
||||||
|
"font-family": "Monaco",
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -82,7 +82,7 @@ export const createTheme = ({
|
|||||||
".cm-cursor, .cm-dropCursor": {
|
".cm-cursor, .cm-dropCursor": {
|
||||||
borderLeftColor: settings.caret,
|
borderLeftColor: settings.caret,
|
||||||
},
|
},
|
||||||
"&.cm-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection":
|
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":
|
||||||
{
|
{
|
||||||
backgroundColor: settings.selection,
|
backgroundColor: settings.selection,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
import { tags as t } from "@lezer/highlight"
|
import { tags as t } from "@lezer/highlight"
|
||||||
|
import { EditorView } from "@codemirror/view"
|
||||||
|
import type { Extension } from "@codemirror/state"
|
||||||
import { createTheme } from "./createTheme"
|
import { createTheme } from "./createTheme"
|
||||||
|
|
||||||
|
const tooltipTheme = EditorView.theme({
|
||||||
|
".cm-tooltip": {
|
||||||
|
border: "1px solid #e0e0e0",
|
||||||
|
backgroundColor: "#f8f8f8",
|
||||||
|
},
|
||||||
|
".cm-tooltip-autocomplete": {
|
||||||
|
"& > ul > li[aria-selected]": {
|
||||||
|
backgroundColor: "#e8e8e8",
|
||||||
|
color: "#000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
// Author: Kenneth Reitz
|
// Author: Kenneth Reitz
|
||||||
export const smoothy = createTheme({
|
const smoothyBase = createTheme({
|
||||||
variant: "light",
|
variant: "light",
|
||||||
settings: {
|
settings: {
|
||||||
background: "#FFFFFF",
|
background: "#FFFFFF",
|
||||||
@@ -81,3 +96,5 @@ export const smoothy = createTheme({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const smoothy: Extension = [smoothyBase, tooltipTheme]
|
||||||
|
|||||||
Reference in New Issue
Block a user