mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
refactor(mermaid): recenter on new note
This commit is contained in:
parent
28c51cb38a
commit
b8a560354f
@ -41,12 +41,12 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
|
|
||||||
const blob = await note?.getBlob();
|
const blob = await note?.getBlob();
|
||||||
const content = blob?.content || "";
|
const content = blob?.content || "";
|
||||||
this.refreshPreview(content);
|
this.refreshPreview(content, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
getData(): { content: string; } {
|
getData(): { content: string; } {
|
||||||
const data = super.getData();
|
const data = super.getData();
|
||||||
this.refreshPreview(data.content);
|
this.refreshPreview(data.content, false);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,12 +54,13 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
* Triggers an update of the preview pane with the provided content.
|
* Triggers an update of the preview pane with the provided content.
|
||||||
*
|
*
|
||||||
* @param content the content that will be passed to `renderSvg` for rendering. It is not the SVG content.
|
* @param content the content that will be passed to `renderSvg` for rendering. It is not the SVG content.
|
||||||
|
* @param recenter `true` to reposition the pan/zoom to fit the image and to center it.
|
||||||
*/
|
*/
|
||||||
async refreshPreview(content: string) {
|
async refreshPreview(content: string, recenter: boolean) {
|
||||||
if (this.note) {
|
if (this.note) {
|
||||||
const svg = await this.renderSvg(content);
|
const svg = await this.renderSvg(content);
|
||||||
this.$renderContainer.html(svg);
|
this.$renderContainer.html(svg);
|
||||||
await this.#setupPanZoom();
|
await this.#setupPanZoom(!recenter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,11 +79,14 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
*/
|
*/
|
||||||
abstract renderSvg(content: string): Promise<string>;
|
abstract renderSvg(content: string): Promise<string>;
|
||||||
|
|
||||||
async #setupPanZoom() {
|
/**
|
||||||
|
* @param preservePanZoom `true` to keep the pan/zoom settings of the previous image, or `false` to re-center it.
|
||||||
|
*/
|
||||||
|
async #setupPanZoom(preservePanZoom: boolean) {
|
||||||
// Clean up
|
// Clean up
|
||||||
let pan = null;
|
let pan = null;
|
||||||
let zoom = null;
|
let zoom = null;
|
||||||
if (this.zoomInstance) {
|
if (preservePanZoom && this.zoomInstance) {
|
||||||
// Store pan and zoom for same note, when the user is editing the note.
|
// Store pan and zoom for same note, when the user is editing the note.
|
||||||
pan = this.zoomInstance.getPan();
|
pan = this.zoomInstance.getPan();
|
||||||
zoom = this.zoomInstance.getZoom();
|
zoom = this.zoomInstance.getZoom();
|
||||||
@ -106,7 +110,7 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
|
|||||||
controlIconsEnabled: true
|
controlIconsEnabled: true
|
||||||
});
|
});
|
||||||
|
|
||||||
if (pan && zoom) {
|
if (preservePanZoom && pan && zoom) {
|
||||||
// Restore the pan and zoom.
|
// Restore the pan and zoom.
|
||||||
zoomInstance.zoom(zoom);
|
zoomInstance.zoom(zoom);
|
||||||
zoomInstance.pan(pan);
|
zoomInstance.pan(pan);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user