Skip to content

Build your personal knowledge base with Trilium Notes

fix #12253

Adorian Doranea45e5ee321c
diff --git a/apps/client/src/widgets/note_tree.spec.ts b/apps/client/src/widgets/note_tree.spec.ts
index a756d86e5f..5a58d7d703 100644
--- a/apps/client/src/widgets/note_tree.spec.ts
+++ b/apps/client/src/widgets/note_tree.spec.ts
@@ -255,13 +255,15 @@ describe("the drop marker's distance from the row boundary", () => {
});
});
-describe("files dropped on the tree", () => {
+describe("drags onto the tree", () => {
+ const target = { data: { noteId: "target", noteType: "text" } };
+
afterEach(() => {
vi.restoreAllMocks();
});
- /** Drives the fancytree drop handler the widget registers, with nothing live behind the tree. */
- async function dropFiles(files: File[]) {
+ /** The fancytree drag-and-drop handlers the widget registers, with no live tree behind them. */
+ async function getDndHandlers() {
const widget = new NoteTreeWidget();
let treeOptions: Fancytree.FancytreeOptions | undefined;
vi.spyOn(widget, "prepareRootNode").mockReturnValue({ key: "root" } as never);
@@ -276,18 +278,31 @@ describe("files dropped on the tree", () => {
await new Promise((resolve) => setTimeout(resolve));
widget.initFancyTree();
- const dnd = treeOptions?.dnd5 as { dragDrop(node: unknown, data: unknown): Promise<void> };
- await dnd.dragDrop(
- { data: { noteId: "target", noteType: "text" } },
- { hitMode: "over", dataTransfer: { files, getData: () => "" } }
- );
+ return treeOptions?.dnd5 as {
+ dragEnter(node: unknown, data: unknown): unknown;
+ dragDrop(node: unknown, data: unknown): Promise<void>;
+ };
}
- it("tags the upload \"auto\", so an archive the importer recognizes is not imported as a plain zip", async () => {
+ it("tags dropped files \"auto\", so the importer can recognize an archive", async () => {
const file = new File(["zip bytes"], "MyVault.zip");
- await dropFiles([file]);
+ const dnd = await getDndHandlers();
+ await dnd.dragDrop(target, {
+ hitMode: "over",
+ dataTransfer: { files: [ file ], getData: () => "" }
+ });
const { uploadFiles } = await import("../services/import.js");
expect(uploadFiles).toHaveBeenCalledWith("notes", "target", [file], expect.objectContaining({ format: "auto" }));
});
+
+ it("refuses content dragged out of a text note, which carries no notes", async () => {
+ vi.spyOn(hoistedNoteService, "getHoistedNoteId").mockReturnValue("root");
+ const dnd = await getDndHandlers();
+ const dragOf = (...types: string[]) => ({ dataTransfer: { types } });
+
+ const editorTypes = [ "text/plain", "text/html", "application/ckeditor5-dragging-uid" ];
+ expect(dnd.dragEnter(target, dragOf(...editorTypes))).toBe(false);
+ expect(dnd.dragEnter(target, dragOf("text/plain", "text/html"))).toBe(true);
+ });
});
diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts
index 8d51f243ec..cb61aaf7ef 100644
--- a/apps/client/src/widgets/note_tree.ts
+++ b/apps/client/src/widgets/note_tree.ts
@@ -449,7 +449,11 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
dragEnter: (node, data) => {
publishDropMarkerShift(node);
- if (node.data.noteType === "search") {
+ // Content dragged out of a text note lists no notes, and its editor deletes
+ // the content once a drop accepts it as a move.
+ if (data.dataTransfer.types.includes("application/ckeditor5-dragging-uid")) {
+ return false;
+ } else if (node.data.noteType === "search") {
return false;
} else if (node.data.noteId === "_lbRoot") {
return false;
diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.json
index a23eedebf6..a6558d179b 100644
--- a/apps/server/src/assets/help/help_content.json
+++ b/apps/server/src/assets/help/help_content.json
@@ -127,7 +127,7 @@
"_help_QxEyIjRBizuC": "<p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Developer-specific%20formatting/Code%20blocks_image.jpg\"></p><p>The code blocks feature allows entering pieces of code in text notes.</p><p>Note that this feature is meant for generally small snippets of code. For larger files such as an entire log, see the&nbsp;<a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a>&nbsp;note type instead.</p><h2>Inserting a code block</h2><ul><li>Via the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, look for the&nbsp;<span class=\"tn-icon cke cke-code-block\"></span> button.<ul><li>Pressing directly on the icon will insert a code block with the language that was selected most recently. If this is the first time a code block is inserted, the language will be “Auto-detected” by default.</li><li>Pressing the arrow next to the icon, which will show a popup with the available languages.</li></ul></li><li>Type <code>```</code> (as in Markdown).<ul><li>Note that it's not possible to specify the language, as it will default to the last selected language.</li></ul></li><li>Paste several lines of code copied from Visual Studio Code.<ul><li>The code block uses the language of the file in Visual Studio Code.</li><li>If that language is not in the list of languages, the code block uses <em>Auto-detected</em>.</li><li>The colors of the Visual Studio Code theme are removed.</li><li>A single line becomes inline code instead of a code block.</li><li>In Firefox, the code block always uses <em>Auto-detected</em>. Firefox can't read the language from Visual Studio Code.</li></ul></li></ul><h2>Exiting out of the code block</h2><ul><li>To exit out of a code block and enter a normal paragraph, move the cursor at the end of the code block and press Enter twice.</li><li>Similarly, to insert a paragraph above the note block, move the cursor at the beginning of the code block and press Enter twice.</li></ul><aside class=\"admonition note\"><p>If you've pasted a code block with a more complex HTML structure, exiting out of the code block by pressing Enter multiple times might not work. In that case the best approach is to delete the code block entirely and use Ctrl+Shift+V (paste as plain text).</p></aside><h2>Syntax highlighting &amp; color schemes</h2><p>Since TriliumNext v0.90.12, Trilium will try to offer syntax highlighting to the code block. Note that the syntax highlighting mechanism is slightly different than the one in&nbsp;<a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a>&nbsp;notes as different technologies are involved.</p><p>Interaction:</p><ul><li>When the language is set to <em>Auto-detected</em> (by default), Trilium will try to identify the programming language (or similar) that corresponds to the given snippet of text and highlight it. Only the languages enabled in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em> → <em>Available MIME types in the dropdown</em> are considered. If this is problematic, consider changing the language of the code block manually.</li><li>When the language is set to <em>Plain text</em>, there will be no syntax highlighting.</li></ul><p>Note that when editing a text note, syntax highlighting is automatically disabled if the code block is too big (somewhere around 500 lines). In&nbsp;<a class=\"reference-link\" href=\"#root/_help_CoFPLs3dRlXc\">Read-Only Notes</a>, in print and on a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, a code block of more than 500 lines or 50,000 characters is shown without syntax highlighting. These limits are not configurable.</p><p>In order to configure this new feature, a section has been added in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>Appearance</em> to control the syntax highlighting. There the color scheme can be chosen, from a builtin selection of themes from Highlight.js. <em>VS Code (Light)</em> and <em>VS Code (Dark)</em> use the same colors as the default themes of <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> notes, so a code block and a code note color the same code alike.</p><ul><li>It is possible to disable the syntax highlighting for all the notes by selecting “No syntax highlighting” in the “Color scheme” option.</li><li>Word wrapping is disabled by default, but can be configured from the same section.</li><li>The tab width can also be adjusted from Options.</li></ul><aside class=\"admonition note\"><p><strong>Context regarding syntax highlighting</strong></p><p>In order to achieve the syntax highlight, the Highlight.js library is being used. Do note that support for syntax highlighting in code blocks is not a supported feature of the text editor we are using CKEditor), but rather a hack which makes use of the highlights API (used for highlighting search results for example). Nevertheless, we haven't noticed any major issues during the development of the feature, but feel free to report any issues you might have.</p><p>Most of the work to achieve the syntax highlight itself was already done by <a href=\"https://github.com/antoniotejada\">antoniotejada</a> in <a href=\"https://github.com/antoniotejada/Trilium-SyntaxHighlightWidget\">https://github.com/antoniotejada/Trilium-SyntaxHighlightWidget</a>. On our side we added customization but also additional functionality.</p></aside><h3>Migrating from existing syntax highlight plugins</h3><p>If you are already using a syntax highlighting plugin such as the <a href=\"https://github.com/antoniotejada/Trilium-SyntaxHighlightWidget\">Trilium-SyntaxHighlightWidget</a> we are basing off of, it is important to disable that plugin before upgrading in order for it not to conflict with our implementation.</p><p>Should you encounter any issues after the migration, try running Trilium in safe mode.</p><h2>Changing the language of a code block</h2><p>Simply click anywhere inside the code block and press again the code block button in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>:<br><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Developer-specific%20formatting/Code%20blocks_image.png\"></p><h2>Adjusting the list of languages</h2><p>The code blocks feature shares the list of languages with the&nbsp;<a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a>&nbsp;note type.</p><p>The supported languages, and the order in which they are listed, can be adjusted by going to <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em> → <em>Available MIME types in the dropdown</em>. See <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> for how to add, remove and reorder them.</p><p>Note that the list of languages is not immediately refreshed, you'd have to manually <a href=\"#root/_help_s8alTXmpFR61\">refresh the application</a>.</p><h2>Text replacements and ligatures</h2><p><a class=\"reference-link\" href=\"#root/_help_oI7GoyilXXAr\">Automatic replacements</a>&nbsp;are a feature of text notes which converts some character sequences into another and some of them interfere with programming text, such as the conversion of quotes. While in a code block, the automatic replacements <strong>are not effect</strong>. The only way the automatic replacements can interfere is if the text is typed/pasted before being put in a code block.</p><p>A different feature is <em>programming ligatures</em>, which is simply a display affordance which turns <code>!=</code> into <code>≠</code> or <code>-&gt;</code> as <code>→</code> . These come from the <a href=\"#root/_help_w4rMEhJsALlA\">font</a>. The underlying text is not actually changed, and copying it out gives you back <code>!=</code> and <code>-&gt;</code>.</p><p>Ligatures can be disabled in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a><em>→ Appearance → Fonts → Programming ligatures.</em></p>",
"_help_AgjCISero73a": "<figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:199/187;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Footnotes_image.png\" width=\"199\" height=\"187\"></figure><p>Footnotes are a good place to insert references to a paragraph or details that are displayed at the bottom of the note.</p><h2>Interaction</h2><ul><li>To insert a new footnote, press&nbsp;<span class=\"tn-icon cke cke-trilium-insert-footnote\"></span> (or press the right arrow and select <em>New footnote</em>).</li><li>To insert a reference to an existing footnote, press the right arrow and select <em>Insert footnote</em>, followed by the number of the footnote to insert.</li><li>Hovering over a reference (e.g. <code>[1]</code>) will display the content of the footnote in a tooltip for easy reference.</li><li>Clicking on a reference in the text (e.g. <code>[1]</code>) will navigate to the corresponding footnote.</li><li>Similarly, clicking on the <code>^</code> button of a footnote will navigate to the corresponding reference in the text.</li></ul>",
"_help_5wZallV2Qo1t": "<figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:220/76;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Format%20Painter_image.png\" width=\"220\" height=\"76\"></figure><p>The Format Painter is a feature in text notes that allows users to copy the formatting of text (such as <strong>bold</strong>, <em>italic</em>, <del>Strikethrough</del>, etc.) and apply it to other parts of the document. It helps maintain consistent formatting and accelerates the creation of rich content.</p><h2>Usage Instructions</h2><p>Click the text that you want to copy the formatting from and use the <em>Copy formatting</em> toolbar button (<span class=\"tn-icon cke cke-paint-roller\"></span>) to copy the style. Then select the target text with your mouse, or click a word, to apply the formatting.</p><ul><li><strong>To copy the formatting</strong>: Place the cursor inside text with some formatting and click the <em>Copy formatting</em> toolbar button. The mouse cursor changes to indicate the painter is armed.</li><li><strong>To paint with the copied formatting</strong>: Select the target text with your mouse. The formatting is applied when you release the button, and the painter disarms — the cursor returns to normal. Clicking or tapping a word applies it to the whole word.</li><li><strong>To paint a selection made otherwise</strong>, such as with the keyboard or the selection handles of a touch screen: select the target text, then use the toolbar button again, which reads <em>Apply formatting</em> once the selection has moved. On a phone, the formatting row stays open while the painter is armed, so the button stays in reach.</li><li><strong>To cancel without painting</strong>: Click the toolbar button again before selecting other text, or press <kbd>Escape</kbd>.</li></ul><h2>Limitations</h2><ol><li>Painting with block-level formatting (like headings or image styles) is not supported yet. This is because, in&nbsp;<a class=\"reference-link\" href=\"#root/_help_MI26XDLSAlCD\">CKEditor</a>, they are considered a part of the content rather than text formatting.</li><li>A click outside a word, such as between two spaces or at the end of a line, only primes the caret, so text you type there takes the copied formatting.</li><li>The painter is one-shot; each paint requires copying the formatting again.</li></ol>",
- "_help_nRhnJkTT8cPs": "<p>Trilium allows two different editing experiences for text notes, based on your preference.</p><p>The type of formatting toolbar can be changed by going to&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;and then looking for the&nbsp;<a class=\"reference-link\" href=\"#root/_hidden/_options/_optionsTextNotes\">Text Notes</a>&nbsp;section. In it, look for the <em>Formatting toolbar</em> category.</p><h2>Floating</h2><p>The floating bar is a more minimalist option, in which the formatting is hidden behind two different popups.</p><h3>Block-level popup</h3><p>The first popup is the block-level popup. This will appear to the left of the current paragraph you are currently editing, as a sequence of dots:<br><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Formatting%20toolbar_image.jpg\"></p><p>Clicking this popup will reveal the formatting options that are specific to the entire paragraph, such as setting a heading, lists, tables, etc.</p><p>The dots are also a drag handle: drag them to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note. Right-clicking them copies a reference to the paragraph or to the selected paragraphs, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>.</p><figure class=\"image\"><img style=\"aspect-ratio:1404/156;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Formatting%20toolbar_image.png\" width=\"1404\" height=\"156\"></figure><h3>Inline popup</h3><p>The inline popup appears automatically when selecting a text:</p><figure class=\"image\"><img style=\"aspect-ratio:1008/154;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Formatting%20toolbar_image.png\" width=\"1008\" height=\"154\"></figure><p>All the options here apply only to the selected portion of text, such as changing the font size, or making the text bold.</p><h2>Fixed</h2><p>The fixed formatting offers a more traditional editing paradigm, usually useful if a lot of formatting is needed.</p><p>All the options are combined into a single toolbar that will appear at the above the note. When using&nbsp;<a class=\"reference-link\" href=\"#root/_help_luNhaphA37EO\">Split View</a>, a single toolbar will be available to save space and it acts on the active note.</p><p>The sequence of dots to the left of the current paragraph is still shown, but only as a drag handle: drag it to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note. Clicking it does not open a popup, and right-clicking it copies a reference to the block, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>. The drag handle is not shown in the mobile layout.</p><figure class=\"image\"><img style=\"aspect-ratio:1440/60;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Formatting%20toolbar_image.png\" width=\"1440\" height=\"60\"></figure><p>By default, if the toolbar does not fit on the screen, the rest of the options will be grouped into a single option at the end. It is possible to display items on multiple lines by checking the corresponding option in the <em>Formatting toolbar</em> section.</p>",
+ "_help_nRhnJkTT8cPs": "<p>Trilium allows two different editing experiences for text notes, based on your preference.</p><p>The type of formatting toolbar can be changed by going to&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;and then looking for the&nbsp;<a class=\"reference-link\" href=\"#root/_hidden/_options/_optionsTextNotes\">Text Notes</a>&nbsp;section. In it, look for the <em>Formatting toolbar</em> category.</p><h2>Floating</h2><p>The floating bar is a more minimalist option, in which the formatting is hidden behind two different popups.</p><h3>Block-level popup</h3><p>The first popup is the block-level popup. This will appear to the left of the current paragraph you are currently editing, as a sequence of dots:<br><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Formatting%20toolbar_image.jpg\"></p><p>Clicking this popup will reveal the formatting options that are specific to the entire paragraph, such as setting a heading, lists, tables, etc.</p><p>The dots are also a drag handle: drag them to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note. Right-clicking them copies a reference to the paragraph or to the selected paragraphs, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>.</p><figure class=\"image\"><img style=\"aspect-ratio:1404/156;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Formatting%20toolbar_image.png\" width=\"1404\" height=\"156\"></figure><h3>Inline popup</h3><p>The inline popup appears automatically when selecting a text:</p><figure class=\"image\"><img style=\"aspect-ratio:1008/154;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Formatting%20toolbar_image.png\" width=\"1008\" height=\"154\"></figure><p>All the options here apply only to the selected portion of text, such as changing the font size, or making the text bold.</p><h2>Fixed</h2><p>The fixed formatting offers a more traditional editing paradigm, usually useful if a lot of formatting is needed.</p><p>All the options are combined into a single toolbar that will appear at the above the note. When using&nbsp;<a class=\"reference-link\" href=\"#root/_help_luNhaphA37EO\">Split View</a>, a single toolbar will be available to save space and it acts on the active note.</p><p>The sequence of dots to the left of the current paragraph is still shown, but only as a drag handle: drag it to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note. Releasing it above the first paragraph or below the last one moves it to the start or the end of the note. Clicking it does not open a popup, and right-clicking it copies a reference to the block, see&nbsp;<a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>. The drag handle is not shown in the mobile layout.</p><figure class=\"image\"><img style=\"aspect-ratio:1440/60;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Formatting%20toolbar_image.png\" width=\"1440\" height=\"60\"></figure><p>By default, if the toolbar does not fit on the screen, the rest of the options will be grouped into a single option at the end. It is possible to display items on multiple lines by checking the corresponding option in the <em>Formatting toolbar</em> section.</p>",
"_help_Gr6xFaF6ioJ5": "<h2>Headings</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:255/284;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_General%20formatting_image.png\" width=\"255\" height=\"284\"></figure><p>Trilium provides headings to define sections within text. Headings are numbered from 2 to 6.</p><p>The reason why Heading 1 is missing from the list is that it is being reserved for the title of note.</p><p>To turn a heading back into a normal text, select <em>Paragraph</em> from the list.</p><p>Apart from using the UI, it is also possible to quickly insert headings using the Markdown-like shortcuts:</p><ul><li><code>##</code> for Heading 2</li><li><code>###</code> for Heading 3</li><li><code>####</code> for Heading 4</li><li><code>#####</code> for Heading 5</li><li><code>######</code> for Heading 6</li></ul><h2>Font size</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:363/249;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/General%20formatting_image.png\" width=\"363\" height=\"249\"></figure><p>One way to highlight a portion of text is to increase the size of the font.</p><p>To do so, select some text and choose an option from the <em>Font size</em> (<span class=\"tn-icon cke cke-font-size\"></span>) selector (as pictured to the right).</p><p>Unlike other text editors such as Microsoft Word, the font size is relative (i.e. “Tiny”, “Small” instead of a number like 12).</p><p>Avoid using this feature just to simply make all text bigger. In that case it's generally better to adjust the font size for all notes in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;or by zooming.</p><h2>Bold, italic, underline, strike-through</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:215/71;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/3_General%20formatting_image.png\" width=\"215\" height=\"71\"></figure><p>Text can be formatted as <strong>Bold,</strong> <em>Italic,</em> Underline or <del>Strike-through</del> via the dedicated buttons (<span class=\"tn-icon cke cke-bold\"></span>, <span class=\"tn-icon cke cke-italic\"></span>, <span class=\"tn-icon cke cke-underline\"></span>, <span class=\"tn-icon cke cke-strikethrough\"></span>) in the formatting toolbar.</p><p>This formatting can be easily removed using the <em>Remove formatting</em> (<span class=\"tn-icon cke cke-remove-format\"></span>) item.</p><p>The following keyboard shortcuts can be used here:</p><ul><li><kbd>Ctrl</kbd>+<kbd>B</kbd> for bold</li><li><kbd>Ctrl</kbd>+<kbd>I</kbd> for italic</li><li><kbd>Ctrl</kbd>+<kbd>U</kbd> for underline</li></ul><p>Alternatively, Markdown-like formatting can be used:</p><ul><li><strong>Bold</strong>: Type <code>**text**</code> or <code>__text__</code></li><li><em>Italic</em>: Type <code>*text*</code> or <code>_text_</code></li><li><del>Strikethrough</del>: Type <code>~~text~~</code></li></ul><h2>Superscript, subscript</h2><p>This allows writing superscript or subscript text.</p><p>This is mostly useful for units of measure (e.g. cm3 for cubic centimeters) and chemical notations (e.g. NaHCO3)</p><p>For mathematical formulas, prefer the&nbsp;<a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a>&nbsp;feature instead.</p><h2>Font color and background color</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:167/204;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_General%20formatting_image.png\" width=\"167\" height=\"204\"></figure><p>Selected text can be colored with one of the predefined colors from a palette or any color can be selected using the color picker (<span class=\"tn-icon cke cke-color-palette\"></span>).</p><p>Once there is at least one color defined in the document, it will appear in the list for easy reuse.</p><p>Colors adapt to the <a href=\"#root/_help_Wy267RK4M69c\">theme</a>. Trilium shows each color in a lighter or darker shade that suits the current theme, so the text stays readable after switching between light and dark themes. The hue stays the same: red text is red in both themes, only lighter or darker. This applies to the palette, the color picker and the document colors alike, and to shared notes too. Printed notes and PDF exports always use the shades of light themes, which suit white paper. The note itself keeps the color as it was picked, so an exported note shows it unchanged.</p><p>Colors applied with older versions of Trilium are shown exactly as they were picked, until the note is next edited.</p><p>Older browsers that can't adapt colors show them exactly as they were picked.</p><p>When you paste text copied from a web page in Chrome, Edge or a Chromium-based app (such as Visual Studio Code), Trilium removes the page's styling:</p><ul><li>Text and background colors.</li><li>Fonts and font sizes.</li><li>Table borders, backgrounds and spacing.</li></ul><p>The following formatting is preserved:</p><ul><li>Bold, italic, underline and strikethrough.</li><li>Subscript and superscript.</li><li>Links, code and tables.</li></ul><p>Colors are preserved when pasting from Word, Google Docs or another note.</p><p>To remove either the background or foreground color of a text, select the corresponding formatting button (<span class=\"tn-icon cke cke-font-color\"></span> or <span class=\"tn-icon cke cke-font-background\"></span>) and press <em>Remove color</em> (<span class=\"tn-icon cke cke-eraser\"></span>) or use the <em>Remove formatting</em> (<span class=\"tn-icon cke cke-remove-format\"></span>) toolbar item.</p><h2>Remove formatting</h2><p>The&nbsp;<span class=\"tn-icon cke cke-remove-format\"></span> <em>Remove formatting</em> button is a quick way to eliminate the general formatting styling of a particular text.</p><p>Simply select the text and press the button to remove the formatting (bold, italic, colors, sizes, etc.). If the text does not have any removable formatting, the button will appear disabled.</p><p>Note that heading styles are not taken into consideration, these must be manually changed back to a paragraph according to the <em>Headings</em> section.</p><p>When pasting content that comes with undesired formatting, an alternative to pasting and then removing formatting is pasting as plain text via <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>V</kbd>.</p><h2>Format painter</h2><p>The&nbsp;<a class=\"reference-link\" href=\"#root/_help_5wZallV2Qo1t\">Format Painter</a>&nbsp;allows users to copy the formatting of text (such as bold, italic, Strikethrough, etc.) and apply it to other parts of the document. It helps maintain consistent formatting and accelerates the creation of rich content.</p><h2>Support for Markdown</h2><p>When exported to&nbsp;<a class=\"reference-link\" href=\"#root/_help_Oau6X9rCuegd\">Markdown</a>, most of the general formatting is maintained such as headings, bold, italic, underline, etc.</p>",
"_help_AxshuNRegLAv": "<aside class=\"admonition note\"><p>This page has been relocated to&nbsp;<a class=\"reference-link\" href=\"#root/_help_2dcGDhp9WFKb\">Outline tab</a>.</p></aside>",
"_help_mT0HEkOsz6i1": "<p>Trilium supports storing and displaying images. Supported formats are PNG, JPEG, GIF, BMP, WebP, AVIF and SVG.</p><p>An image can be uploaded in the form of note's <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> or as a standalone <a href=\"#root/_help_kBrnXNG3Hplm\">note</a> placed into the <a href=\"#root/_help_kBrnXNG3Hplm\">note tree</a>. Its reference can be copied into a text note, in order to display it in the text itself.</p><h2>Uploading images</h2><p>To add an image to the note:</p><ul><li>Simply drag it from file explorer onto the note editor inside Trilium and the image will be uploaded.</li><li>Alternatively, in the&nbsp;<a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, press the <span class=\"tn-icon cke cke-paper-clip\"></span><em>Attach file</em> button and select <em>Image</em>.</li><li>On the&nbsp;<a class=\"reference-link\" href=\"#root/_help_RDslemsQ6gCp\">Mobile Frontend</a>, the same menu also offers <em>Camera</em>, which takes a photo and inserts it.</li><li>You can also copy and paste an image from web (see section below).</li></ul><aside class=\"admonition tip\"><p>To link a picture instead of displaying it, attach it with <em>Attach file as a link</em>, from the <span class=\"tn-icon cke cke-paper-clip\"></span><em>Attach file</em> button. See&nbsp;<a class=\"reference-link\" href=\"#root/_help_0vhv7lsOLy82\">Attachments</a>.</p></aside><h2>Clipboard &amp; automatic download of images</h2><p>Trilium has a special handling for images copied to and pasted from the clipboard.</p><ul><li>For a mix of text and images, the images are downloaded automatically by the server (or desktop app, depending on what is being used).<ul><li>This means that the image must be publicly accessible and reachable from wherever Trilium is running. Inaccessible images will end up as broken images.</li></ul></li><li>If a single image is pasted into Trilium, it will prefer the image that comes in the clipboard. This makes it possible to copy images that Trilium would not otherwise be able to reach, such as Google Chat, Slack, etc.</li><li>When a text with images is copied from Trilium and pasted in another app (such as Microsoft Word or LibreOffice Writer), the images will be preserved.</li></ul><p>The automatic download of images is enabled by default and can be toggled from&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>Media</em> → <em>Download images automatically.</em></p><h2>Configuring the images</h2><p>Clicking on an image will reveal a popup with multiple options:<br><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Images_image.png\"></p><h3>Alignment</h3><p>The first button of the popup, <em>Image position</em>, shows the icon of the image's current position. It opens a menu that groups the positions by how text runs around the image:</p><figure class=\"table\"><table><thead><tr><th>Icon</th><th>Option</th><th>Preview</th><th>Description</th></tr></thead><tbody><tr><td><span class=\"tn-icon cke cke-object-inline\"></span></td><td><em>In line</em></td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Images_image.jpg\"></td><td>The image sits inside a paragraph, like a large character, and moves with the text around it. Use drag &amp; drop or cut-paste to move it around.</td></tr><tr><td><span class=\"tn-icon cke cke-object-center\"></span></td><td><em>Break text</em> → <em>Align left</em>, <em>Align center</em> or <em>Align right</em></td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Images_image.jpg\"> <img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Images_image.jpg\"></td><td>The image is displayed on a line of its own, at the left, in the center or at the right; text continues above and below it but not beside it.</td></tr><tr><td><span class=\"tn-icon cke cke-object-inline-right\"></span></td><td><em>Wrap text</em> → <em>Align left</em> or <em>Align right</em></td><td><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/3_Images_image.jpg\"></td><td>The image is displayed at the left or the right, and the text flows beside it.</td></tr></tbody></table></figure><h3>Drawing over an image</h3><p>To draw or write over an image, press the <span class=\"tn-icon bx bxs-pen\"></span> <em>Convert image to a drawing canvas</em> button of its toolbar. The image becomes a drawing canvas that shows all of it, locked in place. See the drawing canvases section of <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>.</p><h2>Compression</h2><p>Since Trilium isn't really meant to be primary storage for image data, it attempts to compress and resize (with pretty aggressive settings) uploaded images before storing them to the database. You may then notice some quality degradation. Basic quality settings is available in&nbsp;<a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a>&nbsp;→ <em>Media</em>.</p><p>If you want to save images in their original resolution, it is recommended to save them as attachment to note (look for the contextual menu in&nbsp;<a class=\"reference-link\" href=\"#root/_help_8YBEPzcpUgxw\">Note menu</a>&nbsp;→ <em>Import files</em>).</p><h2>Aligning images side-by-side</h2><p>There are generally two ways to display images side by side:</p><ul><li>If they are roughly the same size, simply make the two images in-line, according to the alignment section above. The images can be dragged &amp; dropped onto the same line.</li><li>If they are on different size, create a <a href=\"#root/_help_NdowYOC1GFKS\">table</a> with invisible borders.</li></ul>",
diff --git a/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.md b/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.md
index 0f05cb15e3..c153a228a0 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.md
@@ -32,7 +32,7 @@ The fixed formatting offers a more traditional editing paradigm, usually useful
All the options are combined into a single toolbar that will appear at the above the note. When using <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/UI%20Elements/Split%20View.md">Split View</a>, a single toolbar will be available to save space and it acts on the active note.
-The sequence of dots to the left of the current paragraph is still shown, but only as a drag handle: drag it to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note. Clicking it does not open a popup, and right-clicking it copies a reference to the block, see <a class="reference-link" href="Block%20references.md">Block references</a>. The drag handle is not shown in the mobile layout.
+The sequence of dots to the left of the current paragraph is still shown, but only as a drag handle: drag it to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note. Releasing it above the first paragraph or below the last one moves it to the start or the end of the note. Clicking it does not open a popup, and right-clicking it copies a reference to the block, see <a class="reference-link" href="Block%20references.md">Block references</a>. The drag handle is not shown in the mobile layout.
<figure class="image"><img style="aspect-ratio:1440/60;" src="Formatting toolbar_image.png" width="1440" height="60"></figure>
diff --git a/packages/ckeditor5/src/plugins/block_drag_handle.spec.ts b/packages/ckeditor5/src/plugins/block_drag_handle.spec.ts
index eeff42bd32..f1966f2c0d 100644
--- a/packages/ckeditor5/src/plugins/block_drag_handle.spec.ts
+++ b/packages/ckeditor5/src/plugins/block_drag_handle.spec.ts
@@ -191,6 +191,32 @@ describe("BlockDragHandle", () => {
}
});
+ it("moves blocks dropped above or below the others to the start or end", async () => {
+ const cases = [ {
+ at: (editable: DOMRect, above: DOMRect) => ({
+ clientX: editable.left - 50, clientY: above.top + 10
+ }),
+ data: "<p>second</p><p>first</p><p>third</p>"
+ }, {
+ at: (editable: DOMRect, _above: DOMRect, below: DOMRect) => ({
+ clientX: editable.left + 20, clientY: below.bottom - 10
+ }),
+ data: "<p>first</p><p>third</p><p>second</p>"
+ } ];
+ for (const { at, data } of cases) {
+ const { editor, button } = await createEditor(
+ "<paragraph>first</paragraph><paragraph>sec[]ond</paragraph>"
+ + "<paragraph>third</paragraph>"
+ );
+ const { above, below } = placeInScrollingContainer(editor);
+ const editableRect = getEditable(editor).getBoundingClientRect();
+
+ const isAccepted = drop(button, startDrag(button), at(editableRect, above, below));
+ expect(isAccepted).toBe(true);
+ expect(editor.getData()).toBe(data);
+ }
+ });
+
it("leaves drops over another pane on either side to that pane", async () => {
const { editor, button } = await createEditor(
"<paragraph>fi[]rst</paragraph><paragraph>second</paragraph>"
@@ -215,6 +241,69 @@ describe("BlockDragHandle", () => {
expect(editor.getData()).toBe("<p>first</p><p>second</p>");
});
+ it("ends a drag that no drop takes, with the blocks where they were", async () => {
+ const { editor, button } = await createEditor(
+ "<paragraph>fi[]rst</paragraph><paragraph>second</paragraph>"
+ + "<paragraph>third</paragraph>"
+ );
+ const beside = (index: number) => ({
+ clientX: getEditable(editor).getBoundingClientRect().left - 50,
+ clientY: getBlock(editor, index).getBoundingClientRect().bottom - 2
+ });
+
+ // The second marker update is still pending when the drag ends.
+ const dataTransfer = startDrag(button);
+ expect(dragOver(dataTransfer, beside(1))).toBe(true);
+ expect(dragOver(dataTransfer, beside(2))).toBe(true);
+ endDrag(button, dataTransfer, "none");
+ await new Promise((resolve) => setTimeout(resolve, 100));
+ expect(editor.model.markers.has("drop-target")).toBe(false);
+ expect(editor.getData()).toBe("<p>first</p><p>second</p><p>third</p>");
+ });
+
+ it("moves the blocks into another editor that takes the drop", async () => {
+ const { editor, button } = await createEditor(
+ "<paragraph>fi[]rst</paragraph><paragraph>second</paragraph>"
+ );
+ const other = await createTestEditor([ Essentials, Paragraph ]);
+ setModelData(other.model, "<paragraph>other</paragraph>");
+ const otherBlockRect = getBlock(other, 0).getBoundingClientRect();
+ const isAccepted = drop(button, startDrag(button), {
+ clientX: otherBlockRect.left + 5,
+ clientY: otherBlockRect.bottom - 2
+ });
+ expect(isAccepted).toBe(true);
+ expect(other.getData()).toContain("first");
+ expect(editor.getData()).toBe("<p>second</p>");
+ });
+
+ it("takes the drop marker away where releasing would not drop", async () => {
+ const { editor, button } = await createEditor(
+ "<paragraph>fi[]rst</paragraph><paragraph>second</paragraph>"
+ );
+ const editableRect = getEditable(editor).getBoundingClientRect();
+ const buttonRect = button.getBoundingClientRect();
+ const beside = {
+ clientX: editableRect.left - 50,
+ clientY: getBlock(editor, 1).getBoundingClientRect().bottom - 2
+ };
+ const belowEditable = { ...beside, clientY: editableRect.bottom + 50 };
+ const overHandle = {
+ clientX: buttonRect.left + buttonRect.width / 2,
+ clientY: buttonRect.top + buttonRect.height / 2
+ };
+
+ const dataTransfer = startDrag(button);
+ for (const point of [ belowEditable, overHandle ]) {
+ expect(dragOver(dataTransfer, beside)).toBe(true);
+ expect(editor.model.markers.has("drop-target")).toBe(true);
+ expect(dragOver(dataTransfer, point)).toBe(false);
+ await expect.poll(() => editor.model.markers.has("drop-target")).toBe(false);
+ }
+ endDrag(button, dataTransfer, "none");
+ expect(editor.getData()).toBe("<p>first</p><p>second</p>");
+ });
+
it("mirrors the handle and its drops in a right-to-left editor", async () => {
const { editor, button } = await createEditor(
"<paragraph>fi[]rst</paragraph><paragraph>second</paragraph>",
@@ -302,6 +391,30 @@ async function createEditor(
return { editor, button };
}
+/**
+ * Moves the editor into a scrolling container, between an element above it and one below it, as
+ * a note's title and the space after its content surround it. Returns the two elements' rectangles.
+ */
+function placeInScrollingContainer(editor: ClassicEditor) {
+ const editorElement = editor.ui.view.element;
+ if (!editorElement) {
+ throw new Error("The editor is not rendered.");
+ }
+
+ const scrollable = document.createElement("div");
+ const above = document.createElement("div");
+ const below = document.createElement("div");
+ scrollable.style.setProperty("overflow-y", "auto");
+ above.style.setProperty("height", "40px");
+ below.style.setProperty("height", "40px");
+ editorElement.before(scrollable);
+ scrollable.append(above, editorElement, below);
+ scrollable.scrollIntoView();
+ onTestFinished(() => scrollable.remove());
+
+ return { above: above.getBoundingClientRect(), below: below.getBoundingClientRect() };
+}
+
/** Whether `button` is left of the editable, level with the first line of the block at `index`. */
function isBesideBlock(editor: ClassicEditor, button: HTMLElement, index: number) {
const buttonRect = button.getBoundingClientRect();
@@ -336,10 +449,27 @@ function drop(
const dragover = new DragEvent("dragover", dropInit);
target.dispatchEvent(dragover);
target.dispatchEvent(new DragEvent("drop", dropInit));
- button.dispatchEvent(new DragEvent("dragend", { bubbles: true, dataTransfer }));
+ endDrag(button, dataTransfer, dragover.defaultPrevented ? "move" : "none");
return dragover.defaultPrevented;
}
+/** Drags over `point`, on the element there. Returns whether the dragover was accepted. */
+function dragOver(dataTransfer: DataTransfer, point: { clientX: number; clientY: number }) {
+ const target = document.elementFromPoint(point.clientX, point.clientY) ?? document;
+ const dragover = new DragEvent("dragover", {
+ bubbles: true, cancelable: true, dataTransfer, ...point
+ });
+ target.dispatchEvent(dragover);
+ return dragover.defaultPrevented;
+}
+
+/** Ends the drag at `button`, with the drop effect that the browser reports for its end. */
+function endDrag(button: HTMLElement, dataTransfer: DataTransfer, dropEffect: "none" | "move") {
+ // A constructed `DataTransfer` ignores `dropEffect` writes.
+ Object.defineProperty(dataTransfer, "dropEffect", { value: dropEffect });
+ button.dispatchEvent(new DragEvent("dragend", { bubbles: true, dataTransfer }));
+}
+
function getEditable(editor: ClassicEditor) {
const editable = editor.ui.getEditableElement();
if (!editable) {
diff --git a/packages/ckeditor5/src/plugins/block_drag_handle.ts b/packages/ckeditor5/src/plugins/block_drag_handle.ts
index ee19bc313e..1e73a724f0 100644
--- a/packages/ckeditor5/src/plugins/block_drag_handle.ts
+++ b/packages/ckeditor5/src/plugins/block_drag_handle.ts
@@ -1,6 +1,7 @@
import {
- BlockButtonView, ClipboardObserver, DomEmitterMixin, DragDrop, env, IconDragIndicator,
- type Model, type ModelElement, ModelLiveRange, type ModelRange, Plugin, Rect
+ BlockButtonView, ClipboardObserver, DomEmitterMixin, DragDrop, env,
+ findClosestScrollableAncestor, IconDragIndicator, type Model, type ModelElement,
+ ModelLiveRange, type ModelRange, Plugin, Rect
} from "ckeditor5";
/**
@@ -65,9 +66,8 @@ export default class BlockDragHandle extends Plugin {
this.domEmitter.listenTo(document, "drop", (_evt, domEvent: DragEvent) => {
this.forwardDrag(domEvent);
});
- this.domEmitter.listenTo(document, "dragend", () => {
- this.isDragging = false;
- this.update();
+ this.domEmitter.listenTo(document, "dragend", (_evt, domEvent: DragEvent) => {
+ this.endDrag(domEvent);
}, { useCapture: true });
}
@@ -192,34 +192,43 @@ export default class BlockDragHandle extends Plugin {
}
/**
- * Passes a `dragover` or `drop` in the margin beside the blocks, over an element that holds
- * the editable, to the editing view: 100px into the content from the pointer and within the
- * editable. The editing view takes a drop over the content itself, and another pane its own.
+ * Passes a `dragover` or `drop` around the blocks to the editing view, 100px into the content
+ * from the pointer and within the editable: over an element that holds the editable, or
+ * anywhere in its scrolling container, where a drop above or below the blocks lands at their
+ * start or end. The editing view takes a drop over the content itself. Anywhere else, the
+ * editing view gets a `dragleave`, which removes the drop marker.
*/
private forwardDrag(domEvent: DragEvent) {
const domEditable = this.editor.ui.getEditableElement();
const pointedNode = domEvent.target;
if (!this.isDragging || !domEditable || !(pointedNode instanceof Node)
- || !pointedNode.contains(domEditable)) {
+ || (pointedNode !== domEditable && domEditable.contains(pointedNode))) {
return;
}
const isLtr = this.editor.locale.contentLanguageDirection === "ltr";
const editableRect = domEditable.getBoundingClientRect();
- const clientX = Math.min(
- Math.max(domEvent.clientX + (isLtr ? 100 : -100), editableRect.left + 1),
+ const clientX = clamp(
+ domEvent.clientX + (isLtr ? 100 : -100),
+ editableRect.left + 1,
editableRect.right - 1
);
- const clientY = domEvent.clientY;
- const target = document.elementFromPoint(clientX, clientY);
- if (!target || !domEditable.contains(target)) {
- return;
- }
+ // Without a scrolling ancestor, the closest one is the body, which holds the other panes.
+ const scrollable = findClosestScrollableAncestor(domEditable);
+ const isInScrollable = !!scrollable && scrollable !== document.body
+ && scrollable.contains(pointedNode);
+ const clientY = isInScrollable
+ ? clamp(domEvent.clientY, editableRect.top + 1, editableRect.bottom - 1)
+ : domEvent.clientY;
+ const target = isInScrollable || pointedNode.contains(domEditable)
+ ? document.elementFromPoint(clientX, clientY)
+ : null;
+ const isBesideBlocks = !!target && domEditable.contains(target);
const forwardedEvent = {
- type: domEvent.type,
+ type: isBesideBlocks ? domEvent.type : "dragleave",
dataTransfer: domEvent.dataTransfer,
- target,
+ target: isBesideBlocks ? target : domEditable,
clientX,
clientY,
preventDefault: () => domEvent.preventDefault(),
@@ -227,6 +236,21 @@ export default class BlockDragHandle extends Plugin {
} as unknown as DragEvent;
this.editor.editing.view.getObserver(ClipboardObserver)?.onDomEvent(forwardedEvent);
}
+
+ /**
+ * Passes the `dragend` of a drag from the handle to the editing view, which does not get it
+ * because the handle is outside the editable. `DragDrop` ends the drag on it: it removes the
+ * drop marker, and deletes the dragged blocks when a drop outside this editor moved them.
+ */
+ private endDrag(domEvent: DragEvent) {
+ if (this.isDragging) {
+ this.isDragging = false;
+ this.editor.editing.view.getObserver(ClipboardObserver)?.onDomEvent(domEvent);
+ }
+
+ this.update();
+ }
+
}
interface BlockTarget {
@@ -234,6 +258,10 @@ interface BlockTarget {
domEditable: HTMLElement;
}
+function clamp(value: number, min: number, max: number) {
+ return Math.min(Math.max(value, min), max);
+}
+
/** The block that the handle drags for `block`: the whole collapsible for its title. */
function getDraggedBlock(block: ModelElement) {
return block.is("element", "summary") ? block.parent as ModelElement : block;