mirror of
https://github.com/zadam/trilium.git
synced 2025-11-26 02:24:23 +01:00
fix(text): classic toolbar sometimes not showing
This commit is contained in:
parent
664d28f105
commit
c76f368fa0
@ -445,6 +445,7 @@ type EventMappings = {
|
||||
error: string;
|
||||
};
|
||||
searchRefreshed: { ntxId?: string | null };
|
||||
textEditorRefreshed: { ntxId?: string | null, editor: CKTextEditor };
|
||||
hoistedNoteChanged: {
|
||||
noteId: string;
|
||||
ntxId: string | null;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { useTriliumOption } from "../react/hooks";
|
||||
import { useRef } from "preact/hooks";
|
||||
import { useTriliumEvent, useTriliumOption } from "../react/hooks";
|
||||
import { TabContext } from "./ribbon-interface";
|
||||
|
||||
/**
|
||||
@ -10,10 +11,22 @@ import { TabContext } from "./ribbon-interface";
|
||||
*
|
||||
* ! The toolbar is not only used in the ribbon, but also in the quick edit feature.
|
||||
*/
|
||||
export default function FormattingToolbar({ hidden }: TabContext) {
|
||||
export default function FormattingToolbar({ hidden, ntxId }: TabContext) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const [ textNoteEditorType ] = useTriliumOption("textNoteEditorType");
|
||||
|
||||
useTriliumEvent("textEditorRefreshed", ({ ntxId: eventNtxId, editor }) => {
|
||||
if (eventNtxId !== ntxId) return;
|
||||
const toolbar = editor.ui.view.toolbar?.element;
|
||||
if (toolbar && containerRef.current) {
|
||||
containerRef.current.replaceChildren(toolbar);
|
||||
}
|
||||
});
|
||||
|
||||
return (textNoteEditorType === "ckeditor-classic" &&
|
||||
<div className={`classic-toolbar-widget ${hidden ? "hidden-ext" : ""}`} />
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`classic-toolbar-widget ${hidden ? "hidden-ext" : ""}`}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
@ -251,6 +251,7 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
|
||||
}
|
||||
|
||||
initialized.current.resolve();
|
||||
parentComponent?.triggerEvent("textEditorRefreshed", { ntxId, editor });
|
||||
}}
|
||||
/>}
|
||||
|
||||
@ -304,19 +305,8 @@ function onNotificationWarning(data, evt) {
|
||||
|
||||
function setupClassicEditor(editor: CKTextEditor, parentComponent: Component | undefined) {
|
||||
if (!parentComponent) return;
|
||||
const $classicToolbarWidget = findClassicToolbar(parentComponent);
|
||||
|
||||
$classicToolbarWidget.empty();
|
||||
if ($classicToolbarWidget.length) {
|
||||
const toolbarView = (editor as ClassicEditor).ui.view.toolbar;
|
||||
if (toolbarView.element) {
|
||||
$classicToolbarWidget[0].appendChild(toolbarView.element);
|
||||
}
|
||||
}
|
||||
|
||||
if (utils.isMobile()) {
|
||||
$classicToolbarWidget.addClass("visible");
|
||||
|
||||
// Reposition all dropdowns to point upwards instead of downwards.
|
||||
// See https://ckeditor.com/docs/ckeditor5/latest/examples/framework/bottom-toolbar-editor.html for more info.
|
||||
const toolbarView = (editor as ClassicEditor).ui.view.toolbar;
|
||||
@ -333,24 +323,6 @@ function setupClassicEditor(editor: CKTextEditor, parentComponent: Component | u
|
||||
}
|
||||
}
|
||||
|
||||
function findClassicToolbar(parentComponent: Component): JQuery<HTMLElement> {
|
||||
const $widget = $(parentComponent.$widget);
|
||||
|
||||
if (!utils.isMobile()) {
|
||||
const $parentSplit = $widget.parents(".note-split.type-text");
|
||||
|
||||
if ($parentSplit.length) {
|
||||
// The editor is in a normal tab.
|
||||
return $parentSplit.find("> .ribbon-container .classic-toolbar-widget");
|
||||
} else {
|
||||
// The editor is in a popup.
|
||||
return $widget.closest(".modal-body").find(".classic-toolbar-widget");
|
||||
}
|
||||
} else {
|
||||
return $("body").find(".classic-toolbar-widget");
|
||||
}
|
||||
}
|
||||
|
||||
function EditableTextTouchBar({ watchdogRef, refreshTouchBarRef }: { watchdogRef: RefObject<EditorWatchdog | null>, refreshTouchBarRef: RefObject<() => void> }) {
|
||||
const [ headingSelectedIndex, setHeadingSelectedIndex ] = useState<number>();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user