♻️ Refactor code
This commit is contained in:
@@ -143,16 +143,14 @@ const blockLayer = layer({
|
||||
return;
|
||||
}
|
||||
|
||||
// 只对最后一个块进行特殊处理
|
||||
// 对最后一个块进行特殊处理,让它直接延伸到底部
|
||||
if (idx === blocks.length - 1) {
|
||||
// 计算需要为最后一个块添加多少额外高度,但要更保守
|
||||
const editorHeight = view.dom.clientHeight;
|
||||
const contentBottom = toCoordsBottom - view.documentTop + view.documentPadding.top;
|
||||
|
||||
// 只有当内容不足以填满视口时,才添加额外高度
|
||||
// 让最后一个块直接延伸到编辑器底部
|
||||
if (contentBottom < editorHeight) {
|
||||
let extraHeight = editorHeight - contentBottom - view.defaultLineHeight - 16; // 保留合理的底部边距
|
||||
extraHeight = Math.max(0, extraHeight); // 确保不为负数
|
||||
const extraHeight = editorHeight - contentBottom-10;
|
||||
toCoordsBottom += extraHeight;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import {getCodeBlockLanguageExtension} from './lang-parser';
|
||||
import {createLanguageDetection} from './language-detection';
|
||||
import {EditorOptions, SupportedLanguage} from './types';
|
||||
import {lineNumbers} from '@codemirror/view';
|
||||
import './styles.css'
|
||||
|
||||
/**
|
||||
* 代码块扩展配置选项
|
||||
@@ -47,14 +46,6 @@ export interface CodeBlockOptions {
|
||||
defaultAutoDetect?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认编辑器选项
|
||||
*/
|
||||
const defaultEditorOptions: EditorOptions = {
|
||||
defaultBlockToken: 'text',
|
||||
defaultBlockAutoDetect: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取块内行号信息
|
||||
*/
|
||||
|
||||
@@ -48,14 +48,12 @@ export function getBlocksFromSyntaxTree(state: EditorState): Block[] | null {
|
||||
|
||||
// 解析整个分隔符文本来获取语言和自动检测标记
|
||||
const delimiterText = doc.sliceString(child.from, child.to);
|
||||
console.log('🔍 [解析器] 分隔符文本:', delimiterText);
|
||||
|
||||
|
||||
// 使用正则表达式解析分隔符
|
||||
const match = delimiterText.match(/∞∞∞([a-zA-Z0-9_-]+)(-a)?\n/);
|
||||
if (match) {
|
||||
language = match[1] || 'text';
|
||||
auto = match[2] === '-a';
|
||||
console.log(`🔍 [解析器] 解析结果: 语言=${language}, 自动=${auto}`);
|
||||
} else {
|
||||
// 回退到逐个解析子节点
|
||||
child.node.firstChild?.cursor().iterate(langChild => {
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
/* 块层样式 */
|
||||
.code-blocks-layer {
|
||||
width: 100%;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.code-blocks-layer .block-even,
|
||||
.code-blocks-layer .block-odd {
|
||||
width: 100%;
|
||||
box-sizing: content-box;
|
||||
left: 0;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.code-blocks-layer .block-even:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
/* 块开始装饰 */
|
||||
.code-block-start {
|
||||
height: 12px;
|
||||
position: relative;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.code-block-start.first {
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
/* 默认块样式*/
|
||||
.code-blocks-layer .block-even {
|
||||
background: #252B37 !important;
|
||||
border-top: 1px solid #1e222a;
|
||||
}
|
||||
|
||||
.code-blocks-layer .block-odd {
|
||||
background: #213644 !important;
|
||||
border-top: 1px solid #1e222a;
|
||||
}
|
||||
|
||||
/* 浅色主题块样式 */
|
||||
:root[data-theme="light"] .code-blocks-layer .block-even {
|
||||
background: #ffffff !important;
|
||||
border-top: 1px solid #dfdfdf;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .code-blocks-layer .block-odd {
|
||||
background: #f4f8f4 !important;
|
||||
border-top: 1px solid #dfdfdf;
|
||||
}
|
||||
|
||||
/* 确保深色主题样式 */
|
||||
:root[data-theme="dark"] .code-blocks-layer .block-even {
|
||||
background: #252B37 !important;
|
||||
border-top: 1px solid #1e222a;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] .code-blocks-layer .block-odd {
|
||||
background: #213644 !important;
|
||||
border-top: 1px solid #1e222a;
|
||||
}
|
||||
|
||||
/* 空块选择样式 */
|
||||
.code-block-empty-selected {
|
||||
background-color: #0865a9aa !important;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .code-block-empty-selected {
|
||||
background-color: #77baff8c !important;
|
||||
}
|
||||
|
||||
/* 选择样式 */
|
||||
.cm-activeLine.code-empty-block-selected {
|
||||
background-color: #0865a9aa;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .cm-activeLine.code-empty-block-selected {
|
||||
background-color: #77baff8c;
|
||||
}
|
||||
|
||||
/* 光标样式 */
|
||||
.cm-cursor, .cm-dropCursor {
|
||||
border-left-width: 2px;
|
||||
padding-top: 4px;
|
||||
margin-top: -2px;
|
||||
}
|
||||
|
||||
/* 内容区域样式 */
|
||||
.cm-content {
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
/* 装订线样式 */
|
||||
.cm-gutters {
|
||||
padding: 0 2px 0 4px;
|
||||
user-select: none;
|
||||
background-color: transparent;
|
||||
color: rgba(255, 255, 255, 0.15);
|
||||
border: none;
|
||||
}
|
||||
|
||||
.cm-activeLineGutter {
|
||||
background-color: transparent;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
/* 浅色主题装订线 */
|
||||
:root[data-theme="light"] .cm-gutters {
|
||||
background-color: transparent;
|
||||
color: rgba(0, 0, 0, 0.25);
|
||||
border: none;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .cm-activeLineGutter {
|
||||
background-color: transparent;
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
/* 活动行样式 */
|
||||
.cm-activeLine {
|
||||
background-color: rgba(255, 255, 255, 0.04);
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .cm-activeLine {
|
||||
background-color: rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
/* 选择背景 */
|
||||
.cm-selectionBackground {
|
||||
background-color: #225377aa;
|
||||
}
|
||||
|
||||
.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground {
|
||||
background-color: #0865a9aa;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .cm-selectionBackground {
|
||||
background: #b2c2ca85;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground {
|
||||
background: #77baff8c;
|
||||
}
|
||||
|
||||
/* 编辑器焦点样式 */
|
||||
.cm-editor.cm-focused {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* 折叠装订线样式 */
|
||||
.cm-foldGutter {
|
||||
margin-left: 0px;
|
||||
}
|
||||
|
||||
.cm-foldGutter .cm-gutterElement {
|
||||
opacity: 0;
|
||||
transition: opacity 400ms;
|
||||
}
|
||||
|
||||
.cm-gutters:hover .cm-gutterElement {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* 匹配括号样式 */
|
||||
.cm-focused .cm-matchingBracket,
|
||||
.cm-focused .cm-nonmatchingBracket {
|
||||
outline: 0.5px solid #8fbcbb;
|
||||
}
|
||||
|
||||
.cm-focused .cm-matchingBracket {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.cm-focused .cm-nonmatchingBracket {
|
||||
outline: 0.5px solid #bc8f8f;
|
||||
}
|
||||
|
||||
/* 搜索匹配样式 */
|
||||
.cm-searchMatch {
|
||||
background-color: transparent;
|
||||
outline: 1px solid #8fbcbb;
|
||||
}
|
||||
|
||||
.cm-searchMatch.cm-searchMatch-selected {
|
||||
background-color: #d8dee9;
|
||||
color: #2e3440;
|
||||
}
|
||||
|
||||
/* 选择匹配样式 */
|
||||
.cm-selectionMatch {
|
||||
background-color: #50606D;
|
||||
}
|
||||
|
||||
/* 折叠占位符样式 */
|
||||
.cm-foldPlaceholder {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
/* 工具提示样式 */
|
||||
.cm-tooltip {
|
||||
border: none;
|
||||
background-color: #3b4252;
|
||||
}
|
||||
|
||||
.cm-tooltip .cm-tooltip-arrow:before {
|
||||
border-top-color: transparent;
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
|
||||
.cm-tooltip .cm-tooltip-arrow:after {
|
||||
border-top-color: #3b4252;
|
||||
border-bottom-color: #3b4252;
|
||||
}
|
||||
|
||||
/* 自动完成工具提示 */
|
||||
.cm-tooltip-autocomplete > ul > li[aria-selected] {
|
||||
background-color: rgba(255, 255, 255, 0.04);
|
||||
color: #4c566a;
|
||||
}
|
||||
Reference in New Issue
Block a user