🐛 Fixed the issue of highlightActiveLine and selected background color conflicts
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
drawSelection,
|
drawSelection,
|
||||||
dropCursor,
|
dropCursor,
|
||||||
EditorView,
|
EditorView,
|
||||||
|
highlightActiveLine,
|
||||||
highlightActiveLineGutter,
|
highlightActiveLineGutter,
|
||||||
highlightSpecialChars,
|
highlightSpecialChars,
|
||||||
keymap,
|
keymap,
|
||||||
@@ -12,22 +13,17 @@ import {
|
|||||||
rectangularSelection,
|
rectangularSelection,
|
||||||
} from '@codemirror/view';
|
} from '@codemirror/view';
|
||||||
import {Compartment, EditorState, Extension} from '@codemirror/state';
|
import {Compartment, EditorState, Extension} from '@codemirror/state';
|
||||||
import {baseDark} from "@/editor/theme/base-dark";
|
import {baseDark, customHighlightActiveLine} from "@/editor/theme/base-dark";
|
||||||
import {
|
import {
|
||||||
bracketMatching,
|
bracketMatching,
|
||||||
defaultHighlightStyle,
|
defaultHighlightStyle,
|
||||||
foldGutter,
|
foldGutter,
|
||||||
foldKeymap,
|
foldKeymap,
|
||||||
indentOnInput,
|
indentOnInput,
|
||||||
syntaxHighlighting,
|
indentUnit,
|
||||||
indentUnit
|
syntaxHighlighting
|
||||||
} from '@codemirror/language';
|
} from '@codemirror/language';
|
||||||
import {
|
import {defaultKeymap, history, historyKeymap, indentSelection,} from '@codemirror/commands';
|
||||||
defaultKeymap,
|
|
||||||
history,
|
|
||||||
historyKeymap,
|
|
||||||
indentSelection,
|
|
||||||
} from '@codemirror/commands';
|
|
||||||
import {highlightSelectionMatches, searchKeymap} from '@codemirror/search';
|
import {highlightSelectionMatches, searchKeymap} from '@codemirror/search';
|
||||||
import {autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap} from '@codemirror/autocomplete';
|
import {autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap} from '@codemirror/autocomplete';
|
||||||
import {lintKeymap} from '@codemirror/lint';
|
import {lintKeymap} from '@codemirror/lint';
|
||||||
@@ -80,8 +76,8 @@ const tabHandler = (view: EditorView): boolean => {
|
|||||||
const spaces = ' '.repeat(currentTabSize);
|
const spaces = ' '.repeat(currentTabSize);
|
||||||
|
|
||||||
// 在光标位置插入空格
|
// 在光标位置插入空格
|
||||||
const { state, dispatch } = view;
|
const {state, dispatch} = view;
|
||||||
dispatch(state.update(state.replaceSelection(spaces), { scrollIntoView: true }));
|
dispatch(state.update(state.replaceSelection(spaces), {scrollIntoView: true}));
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,6 +126,8 @@ const createEditor = () => {
|
|||||||
rectangularSelection(),
|
rectangularSelection(),
|
||||||
crosshairCursor(),
|
crosshairCursor(),
|
||||||
highlightSelectionMatches(),
|
highlightSelectionMatches(),
|
||||||
|
customHighlightActiveLine,
|
||||||
|
highlightActiveLine(),
|
||||||
keymap.of([
|
keymap.of([
|
||||||
...closeBracketsKeymap,
|
...closeBracketsKeymap,
|
||||||
...defaultKeymap,
|
...defaultKeymap,
|
||||||
@@ -209,8 +207,8 @@ const updateTabConfig = () => {
|
|||||||
|
|
||||||
// 更新Tab键映射
|
// 更新Tab键映射
|
||||||
const tabKeymap = editorStore.enableTabIndent
|
const tabKeymap = editorStore.enableTabIndent
|
||||||
? keymap.of([{ key: "Tab", run: tabHandler }])
|
? keymap.of([{key: "Tab", run: tabHandler}])
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
view.dispatch({
|
view.dispatch({
|
||||||
effects: tabKeyCompartment.reconfigure(tabKeymap)
|
effects: tabKeyCompartment.reconfigure(tabKeymap)
|
||||||
@@ -240,7 +238,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
// 添加滚轮事件监听
|
// 添加滚轮事件监听
|
||||||
if (editorElement.value) {
|
if (editorElement.value) {
|
||||||
editorElement.value.addEventListener('wheel', handleWheel, { passive: false });
|
editorElement.value.addEventListener('wheel', handleWheel, {passive: false});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -9,10 +9,11 @@ export const config = {
|
|||||||
background: '#252B37',
|
background: '#252B37',
|
||||||
foreground: '#9BB586',
|
foreground: '#9BB586',
|
||||||
selection: '#1A5888',
|
selection: '#1A5888',
|
||||||
|
selectionMatch: 'rgba(26, 88, 136, 0.5)',
|
||||||
cursor: '#F8F8F2',
|
cursor: '#F8F8F2',
|
||||||
dropdownBackground: '#282A36',
|
dropdownBackground: '#282A36',
|
||||||
dropdownBorder: '#191A21',
|
dropdownBorder: '#191A21',
|
||||||
activeLine: '#2E333F',
|
activeLine: 'rgba(46, 51, 63, 0.6)',
|
||||||
lineNumber: '#676d7c',
|
lineNumber: '#676d7c',
|
||||||
lineNumberActive: '#F8F8F2',
|
lineNumberActive: '#F8F8F2',
|
||||||
lineNumberBackground: '#212731',
|
lineNumberBackground: '#212731',
|
||||||
@@ -42,7 +43,10 @@ export const draculaTheme = EditorView.theme({
|
|||||||
'.cm-content': {caretColor: config.cursor},
|
'.cm-content': {caretColor: config.cursor},
|
||||||
|
|
||||||
'.cm-cursor, .cm-dropCursor': {borderLeftColor: config.cursor},
|
'.cm-cursor, .cm-dropCursor': {borderLeftColor: config.cursor},
|
||||||
'&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': {backgroundColor: config.selection},
|
|
||||||
|
'&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': {
|
||||||
|
backgroundColor: `${config.selection} !important`
|
||||||
|
},
|
||||||
|
|
||||||
'.cm-panels': {backgroundColor: config.dropdownBackground, color: config.foreground},
|
'.cm-panels': {backgroundColor: config.dropdownBackground, color: config.foreground},
|
||||||
'.cm-panels.cm-panels-top': {borderBottom: '2px solid black'},
|
'.cm-panels.cm-panels-top': {borderBottom: '2px solid black'},
|
||||||
@@ -57,7 +61,11 @@ export const draculaTheme = EditorView.theme({
|
|||||||
},
|
},
|
||||||
|
|
||||||
'.cm-activeLine': {backgroundColor: config.activeLine},
|
'.cm-activeLine': {backgroundColor: config.activeLine},
|
||||||
'.cm-selectionMatch': {backgroundColor: config.selection},
|
|
||||||
|
'.cm-selectionMatch': {
|
||||||
|
backgroundColor: `${config.selectionMatch} !important`,
|
||||||
|
borderRadius: '2px'
|
||||||
|
},
|
||||||
|
|
||||||
'&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket': {
|
'&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket': {
|
||||||
backgroundColor: config.matchingBracket,
|
backgroundColor: config.matchingBracket,
|
||||||
@@ -123,6 +131,12 @@ export const draculaHighlightStyle = HighlightStyle.define([
|
|||||||
{tag: t.strikethrough, textDecoration: 'line-through'},
|
{tag: t.strikethrough, textDecoration: 'line-through'},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
export const customHighlightActiveLine = EditorView.theme({
|
||||||
|
'.cm-activeLine': {
|
||||||
|
backgroundColor: config.activeLine,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
export const baseDark: Extension = [
|
export const baseDark: Extension = [
|
||||||
draculaTheme,
|
draculaTheme,
|
||||||
syntaxHighlighting(draculaHighlightStyle),
|
syntaxHighlighting(draculaHighlightStyle),
|
||||||
|
Reference in New Issue
Block a user