mirror of
https://github.com/docmost/docmost.git
synced 2026-05-20 08:34:04 +08:00
switch to default codeblock tab handling
This commit is contained in:
@@ -311,6 +311,8 @@ export const mainExtensions = [
|
|||||||
view: CodeBlockView,
|
view: CodeBlockView,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
lowlight,
|
lowlight,
|
||||||
|
enableTabIndentation: true,
|
||||||
|
tabSize: 2,
|
||||||
HTMLAttributes: {
|
HTMLAttributes: {
|
||||||
spellcheck: false,
|
spellcheck: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { CodeBlockOptions } from "@tiptap/extension-code-block";
|
import type { CodeBlockOptions } from '@tiptap/extension-code-block';
|
||||||
import CodeBlock from "@tiptap/extension-code-block";
|
import CodeBlock from '@tiptap/extension-code-block';
|
||||||
|
|
||||||
import { LowlightPlugin } from "./lowlight-plugin.js";
|
import { LowlightPlugin } from './lowlight-plugin.js';
|
||||||
import { ReactNodeViewRenderer } from "@tiptap/react";
|
import { ReactNodeViewRenderer } from '@tiptap/react';
|
||||||
|
|
||||||
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
||||||
/**
|
/**
|
||||||
@@ -12,7 +12,7 @@ export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
|||||||
view: any;
|
view: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TAB_CHAR = "\u00A0\u00A0";
|
const TAB_CHAR = '\u00A0\u00A0';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This extension allows you to highlight code blocks with lowlight.
|
* This extension allows you to highlight code blocks with lowlight.
|
||||||
@@ -25,7 +25,7 @@ export const CustomCodeBlock = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|||||||
return {
|
return {
|
||||||
...this.parent?.(),
|
...this.parent?.(),
|
||||||
lowlight: {},
|
lowlight: {},
|
||||||
languageClassPrefix: "language-",
|
languageClassPrefix: 'language-',
|
||||||
exitOnTripleEnter: true,
|
exitOnTripleEnter: true,
|
||||||
exitOnArrowDown: true,
|
exitOnArrowDown: true,
|
||||||
defaultLanguage: null,
|
defaultLanguage: null,
|
||||||
@@ -37,20 +37,8 @@ export const CustomCodeBlock = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|||||||
addKeyboardShortcuts() {
|
addKeyboardShortcuts() {
|
||||||
return {
|
return {
|
||||||
...this.parent?.(),
|
...this.parent?.(),
|
||||||
Tab: () => {
|
'Mod-a': () => {
|
||||||
if (this.editor.isActive("codeBlock")) {
|
if (this.editor.isActive('codeBlock')) {
|
||||||
this.editor
|
|
||||||
.chain()
|
|
||||||
.command(({ tr }) => {
|
|
||||||
tr.insertText(TAB_CHAR);
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.run();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Mod-a": () => {
|
|
||||||
if (this.editor.isActive("codeBlock")) {
|
|
||||||
const { state } = this.editor;
|
const { state } = this.editor;
|
||||||
const { $from } = state.selection;
|
const { $from } = state.selection;
|
||||||
|
|
||||||
@@ -60,7 +48,7 @@ export const CustomCodeBlock = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|||||||
|
|
||||||
for (depth = $from.depth; depth > 0; depth--) {
|
for (depth = $from.depth; depth > 0; depth--) {
|
||||||
const node = $from.node(depth);
|
const node = $from.node(depth);
|
||||||
if (node.type.name === "codeBlock") {
|
if (node.type.name === 'codeBlock') {
|
||||||
codeBlockNode = node;
|
codeBlockNode = node;
|
||||||
codeBlockPos = $from.start(depth) - 1;
|
codeBlockPos = $from.start(depth) - 1;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user