You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-13 00:10:37 +02:00
Desktop: Improved handling of dark and light theme auto-switch
This commit is contained in:
@ -515,7 +515,7 @@ function AceEditor(props: NoteBodyEditorProps, ref: any) {
|
|||||||
cancelled = true;
|
cancelled = true;
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
};
|
};
|
||||||
}, [props.content, props.contentMarkupLanguage, props.visiblePanes, props.resourceInfos]);
|
}, [props.content, props.contentMarkupLanguage, props.visiblePanes, props.resourceInfos, props.markupToHtml]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!webviewReady) return;
|
if (!webviewReady) return;
|
||||||
|
@ -136,7 +136,8 @@ function styles_(props:NoteBodyEditorProps) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let loadedAssetFiles_:string[] = [];
|
let loadedCssFiles_:string[] = [];
|
||||||
|
let loadedJsFiles_:string[] = [];
|
||||||
let dispatchDidUpdateIID_:any = null;
|
let dispatchDidUpdateIID_:any = null;
|
||||||
let changeId_:number = 1;
|
let changeId_:number = 1;
|
||||||
|
|
||||||
@ -442,7 +443,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
return () => {
|
return () => {
|
||||||
document.head.removeChild(element);
|
document.head.removeChild(element);
|
||||||
};
|
};
|
||||||
}, [editorReady]);
|
}, [editorReady, props.theme]);
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------
|
||||||
// Enable or disable the editor
|
// Enable or disable the editor
|
||||||
@ -460,7 +461,8 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!scriptLoaded) return;
|
if (!scriptLoaded) return;
|
||||||
|
|
||||||
loadedAssetFiles_ = [];
|
loadedCssFiles_ = [];
|
||||||
|
loadedJsFiles_ = [];
|
||||||
|
|
||||||
function contextMenuItemNameWithNamespace(name:string) {
|
function contextMenuItemNameWithNamespace(name:string) {
|
||||||
// For unknown reasons, TinyMCE converts all context menu names to
|
// For unknown reasons, TinyMCE converts all context menu names to
|
||||||
@ -681,6 +683,25 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
// -----------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
const loadDocumentAssets = (editor:any, pluginAssets:any[]) => {
|
const loadDocumentAssets = (editor:any, pluginAssets:any[]) => {
|
||||||
|
// Note: The way files are cached is not correct because it assumes there's only one version
|
||||||
|
// of each file. However, when the theme change, a new CSS file, specific to the theme, is
|
||||||
|
// created. That file should not be loaded on top of the previous one, but as a replacement.
|
||||||
|
// Otherwise it would do this:
|
||||||
|
// - Try to load CSS for theme 1 => OK
|
||||||
|
// - Try to load CSS for theme 2 => OK
|
||||||
|
// - Try to load CSS for theme 1 => Skip because the file is in cache. As a result, theme 2
|
||||||
|
// incorrectly stay.
|
||||||
|
// The fix would be to make allAssets() return a name and a version for each asset. Then the loading
|
||||||
|
// code would check this and either append the CSS or replace.
|
||||||
|
|
||||||
|
let docHead_ = null;
|
||||||
|
|
||||||
|
function docHead() {
|
||||||
|
if (docHead_) return docHead_;
|
||||||
|
docHead_ = editor.getDoc().getElementsByTagName('head')[0];
|
||||||
|
return docHead_;
|
||||||
|
}
|
||||||
|
|
||||||
const cssFiles = [
|
const cssFiles = [
|
||||||
'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
|
'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
|
||||||
`gui/note-viewer/pluginAssets/highlight.js/${theme.codeThemeCss}`,
|
`gui/note-viewer/pluginAssets/highlight.js/${theme.codeThemeCss}`,
|
||||||
@ -688,20 +709,31 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
pluginAssets
|
pluginAssets
|
||||||
.filter((a:any) => a.mime === 'text/css')
|
.filter((a:any) => a.mime === 'text/css')
|
||||||
.map((a:any) => a.path)
|
.map((a:any) => a.path)
|
||||||
).filter((path:string) => !loadedAssetFiles_.includes(path));
|
).filter((path:string) => !loadedCssFiles_.includes(path));
|
||||||
|
|
||||||
const jsFiles = [].concat(
|
const jsFiles = [].concat(
|
||||||
pluginAssets
|
pluginAssets
|
||||||
.filter((a:any) => a.mime === 'application/javascript')
|
.filter((a:any) => a.mime === 'application/javascript')
|
||||||
.map((a:any) => a.path)
|
.map((a:any) => a.path)
|
||||||
).filter((path:string) => !loadedAssetFiles_.includes(path));
|
).filter((path:string) => !loadedJsFiles_.includes(path));
|
||||||
|
|
||||||
for (const cssFile of cssFiles) loadedAssetFiles_.push(cssFile);
|
for (const cssFile of cssFiles) loadedCssFiles_.push(cssFile);
|
||||||
for (const jsFile of jsFiles) loadedAssetFiles_.push(jsFile);
|
for (const jsFile of jsFiles) loadedJsFiles_.push(jsFile);
|
||||||
|
|
||||||
console.info('loadDocumentAssets: files to load', cssFiles, jsFiles);
|
console.info('loadDocumentAssets: files to load', cssFiles, jsFiles);
|
||||||
|
|
||||||
if (cssFiles.length) editor.dom.loadCSS(cssFiles.join(','));
|
if (cssFiles.length) {
|
||||||
|
for (const cssFile of cssFiles) {
|
||||||
|
const script = editor.dom.create('link', {
|
||||||
|
rel: 'stylesheet',
|
||||||
|
type: 'text/css',
|
||||||
|
href: cssFile,
|
||||||
|
class: 'jop-tinymce-css',
|
||||||
|
});
|
||||||
|
|
||||||
|
docHead().appendChild(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (jsFiles.length) {
|
if (jsFiles.length) {
|
||||||
const editorElementId = editor.dom.uniqueId();
|
const editorElementId = editor.dom.uniqueId();
|
||||||
@ -713,7 +745,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
src: jsFile,
|
src: jsFile,
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.getDoc().getElementsByTagName('head')[0].appendChild(script);
|
docHead().appendChild(script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user