mirror of
https://github.com/zadam/trilium.git
synced 2026-02-27 00:53:35 +01:00
Merge d1a442640d2ab9529bab1a705da06d850c6e81cd into c3b4c2f7d468e109c05040c50307b11ff4068274
This commit is contained in:
commit
8dba8d6496
1
.gitignore
vendored
1
.gitignore
vendored
@ -36,6 +36,7 @@ Thumbs.db
|
|||||||
vite.config.*.timestamp*
|
vite.config.*.timestamp*
|
||||||
vitest.config.*.timestamp*
|
vitest.config.*.timestamp*
|
||||||
test-output
|
test-output
|
||||||
|
**/__screenshots__/
|
||||||
|
|
||||||
apps/*/data*
|
apps/*/data*
|
||||||
apps/*/out
|
apps/*/out
|
||||||
|
|||||||
@ -17,6 +17,15 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@smithy/middleware-retry": "4.4.29",
|
"@smithy/middleware-retry": "4.4.29",
|
||||||
"@types/jquery": "3.5.33"
|
"@types/jquery": "3.5.33",
|
||||||
|
"@vitest/browser": "4.0.17",
|
||||||
|
"@vitest/coverage-istanbul": "4.0.17",
|
||||||
|
"vite-plugin-svgo": "2.0.0",
|
||||||
|
"vitest": "4.0.17",
|
||||||
|
"webdriverio": "9.23.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "vitest",
|
||||||
|
"test:debug": "vitest --inspect-brk --no-file-parallelism --browser.headless=false"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import CodeBlockLanguageDropdown from "./plugins/code_block_language_dropdown.js
|
|||||||
import MoveBlockUpDownPlugin from "./plugins/move_block_updown.js";
|
import MoveBlockUpDownPlugin from "./plugins/move_block_updown.js";
|
||||||
import ScrollOnUndoRedoPlugin from "./plugins/scroll_on_undo_redo.js"
|
import ScrollOnUndoRedoPlugin from "./plugins/scroll_on_undo_redo.js"
|
||||||
import InlineCodeNoSpellcheck from "./plugins/inline_code_no_spellcheck.js";
|
import InlineCodeNoSpellcheck from "./plugins/inline_code_no_spellcheck.js";
|
||||||
|
import DisableMentionInCodeBlock from "./plugins/disable_mention_in_codeblock.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor.
|
* Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor.
|
||||||
@ -53,6 +54,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
|
|||||||
MoveBlockUpDownPlugin,
|
MoveBlockUpDownPlugin,
|
||||||
ScrollOnUndoRedoPlugin,
|
ScrollOnUndoRedoPlugin,
|
||||||
InlineCodeNoSpellcheck,
|
InlineCodeNoSpellcheck,
|
||||||
|
DisableMentionInCodeBlock,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
import { Plugin } from "ckeditor5";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables the mention feature inside code blocks.
|
||||||
|
* This prevents the autocomplete popup from appearing when typing `@` or `/` within code blocks.
|
||||||
|
*/
|
||||||
|
export default class DisableMentionInCodeBlock extends Plugin {
|
||||||
|
public static get pluginName() {
|
||||||
|
return "DisableMentionInCodeBlock" as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
const editor = this.editor;
|
||||||
|
const schema = editor.model.schema;
|
||||||
|
|
||||||
|
// Disallow mention attribute inside code blocks
|
||||||
|
schema.addAttributeCheck((context, attributeName) => {
|
||||||
|
if (attributeName === 'mention' && context.endsWith('codeBlock $text')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
65
packages/ckeditor5/tests/disable_mention_in_codeblock.ts
Normal file
65
packages/ckeditor5/tests/disable_mention_in_codeblock.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import { ClassicEditor, CodeBlock, Mention } from 'ckeditor5';
|
||||||
|
import DisableMentionInCodeBlock from '../src/plugins/disable_mention_in_codeblock.js';
|
||||||
|
import { describe, beforeEach, it, afterEach, expect } from "vitest";
|
||||||
|
|
||||||
|
describe( 'DisableMentionInCodeBlock', () => {
|
||||||
|
let editorElement: HTMLDivElement, editor: ClassicEditor;
|
||||||
|
|
||||||
|
beforeEach( async () => {
|
||||||
|
editorElement = document.createElement( 'div' );
|
||||||
|
document.body.appendChild( editorElement );
|
||||||
|
|
||||||
|
return ClassicEditor
|
||||||
|
.create( editorElement, {
|
||||||
|
plugins: [ CodeBlock, Mention, DisableMentionInCodeBlock ],
|
||||||
|
licenseKey: "GPL"
|
||||||
|
} )
|
||||||
|
.then( newEditor => {
|
||||||
|
editor = newEditor;
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
|
afterEach( () => {
|
||||||
|
editorElement.remove();
|
||||||
|
|
||||||
|
return editor.destroy();
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should be loaded', () => {
|
||||||
|
expect( editor.plugins.get( DisableMentionInCodeBlock ) ).to.instanceOf( DisableMentionInCodeBlock );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'has proper name', () => {
|
||||||
|
expect( DisableMentionInCodeBlock.pluginName ).to.equal( 'DisableMentionInCodeBlock' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should prevent mention attribute inside code blocks', () => {
|
||||||
|
const schema = editor.model.schema;
|
||||||
|
|
||||||
|
// Test that mention attribute is disallowed in code block context
|
||||||
|
const context = schema.createContext( [ 'codeBlock', '$text' ] );
|
||||||
|
const isAllowed = schema.checkAttribute( context, 'mention' );
|
||||||
|
|
||||||
|
expect( isAllowed ).to.be.false;
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should allow mention attribute outside code blocks', () => {
|
||||||
|
const schema = editor.model.schema;
|
||||||
|
|
||||||
|
// Test that mention attribute is still allowed in regular paragraphs
|
||||||
|
const context = schema.createContext( [ 'paragraph', '$text' ] );
|
||||||
|
const isAllowed = schema.checkAttribute( context, 'mention' );
|
||||||
|
|
||||||
|
expect( isAllowed ).to.be.true;
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should allow mention attribute in list items', () => {
|
||||||
|
const schema = editor.model.schema;
|
||||||
|
|
||||||
|
// Test that mention attribute is still allowed in list items
|
||||||
|
const context = schema.createContext( [ 'listItem', '$text' ] );
|
||||||
|
const isAllowed = schema.checkAttribute( context, 'mention' );
|
||||||
|
|
||||||
|
expect( isAllowed ).to.be.true;
|
||||||
|
} );
|
||||||
|
} );
|
||||||
43
packages/ckeditor5/vitest.config.ts
Normal file
43
packages/ckeditor5/vitest.config.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* @license Copyright (c) 2023-2024, CKSource Holding sp. z o.o. All rights reserved.
|
||||||
|
* For licensing, see LICENSE.md.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { defineConfig } from 'vitest/config';
|
||||||
|
import svg from 'vite-plugin-svgo';
|
||||||
|
import { webdriverio } from "@vitest/browser-webdriverio";
|
||||||
|
|
||||||
|
export default defineConfig( {
|
||||||
|
plugins: [
|
||||||
|
svg()
|
||||||
|
],
|
||||||
|
test: {
|
||||||
|
browser: {
|
||||||
|
enabled: true,
|
||||||
|
provider: webdriverio(),
|
||||||
|
headless: true,
|
||||||
|
ui: false,
|
||||||
|
instances: [ { browser: 'chrome' } ]
|
||||||
|
},
|
||||||
|
include: [
|
||||||
|
'tests/**/*.[jt]s'
|
||||||
|
],
|
||||||
|
exclude: [
|
||||||
|
'tests/setup.ts'
|
||||||
|
],
|
||||||
|
globals: true,
|
||||||
|
watch: false,
|
||||||
|
coverage: {
|
||||||
|
thresholds: {
|
||||||
|
lines: 100,
|
||||||
|
functions: 100,
|
||||||
|
branches: 100,
|
||||||
|
statements: 100
|
||||||
|
},
|
||||||
|
provider: 'istanbul',
|
||||||
|
include: [
|
||||||
|
'src'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
572
pnpm-lock.yaml
generated
572
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user