Skip to content

Commit 6d74d93

Browse files
Fixed presentation mode gets lost when pressing back on the first node. Added unclamped zooming option for presentation mode. Fixed no animation if zoom gets clamped.
1 parent 7df6cba commit 6d74d93

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

src/@types/Canvas.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export interface Canvas {
110110
handlePaste(): void
111111
requestSave(): void
112112

113+
onResize(): void
114+
113115
// Custom
114116
isClearing?: boolean
115117
isCopying?: boolean

src/canvas-extensions/presentation-canvas-extension.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,29 +252,32 @@ export default class PresentationCanvasExtension extends CanvasExtension {
252252
private async animateNodeTransition(canvas: Canvas, fromNode: CanvasNode|undefined, toNode: CanvasNode) {
253253
const useCustomZoomFunction = this.plugin.settings.getSetting('zoomToSlideWithoutPadding')
254254
const animationDurationMs = this.plugin.settings.getSetting('slideTransitionAnimationDuration') * 1000
255+
256+
const toNodeBBox = CanvasHelper.getSmallestAllowedZoomBBox(canvas, toNode.getBBox())
255257

256258
if (animationDurationMs > 0 && fromNode) {
257259
const animationIntensity = this.plugin.settings.getSetting('slideTransitionAnimationIntensity')
258260

259-
const currentNodeBBoxEnlarged = BBoxHelper.scaleBBox(fromNode.getBBox(), animationIntensity)
261+
const fromNodeBBox = CanvasHelper.getSmallestAllowedZoomBBox(canvas, fromNode.getBBox())
262+
263+
const currentNodeBBoxEnlarged = BBoxHelper.scaleBBox(fromNodeBBox, animationIntensity)
260264
if (useCustomZoomFunction) CanvasHelper.zoomToRealBBox(canvas, currentNodeBBoxEnlarged)
261265
else canvas.zoomToBbox(currentNodeBBoxEnlarged)
262266

263267
await sleep(animationDurationMs / 2)
264268

265269
if (fromNode.getData().id !== toNode.getData().id) {
266270
// Add 0.1 to fix obsidian bug that causes the animation to skip if the bbox is the same
267-
const nextNodeBBoxEnlarged = BBoxHelper.scaleBBox(toNode.getBBox(), animationIntensity + 0.1)
271+
const nextNodeBBoxEnlarged = BBoxHelper.scaleBBox(toNodeBBox, animationIntensity + 0.1)
268272
if (useCustomZoomFunction) CanvasHelper.zoomToRealBBox(canvas, nextNodeBBoxEnlarged)
269273
else canvas.zoomToBbox(nextNodeBBoxEnlarged)
270274

271275
await sleep(animationDurationMs / 2)
272276
}
273277
}
274278

275-
let nodeBBox = toNode.getBBox()
276-
if (useCustomZoomFunction) CanvasHelper.zoomToRealBBox(canvas, nodeBBox)
277-
else canvas.zoomToBbox(nodeBBox)
279+
if (useCustomZoomFunction) CanvasHelper.zoomToRealBBox(canvas, toNodeBBox)
280+
else canvas.zoomToBbox(toNodeBBox)
278281
}
279282

280283
private async startPresentation(canvas: Canvas, tryContinue: boolean = false) {
@@ -304,6 +307,10 @@ export default class PresentationCanvasExtension extends CanvasExtension {
304307
// Lock canvas
305308
canvas.setReadonly(true)
306309

310+
// Disable zoom clamping
311+
if (this.plugin.settings.getSetting('useUnclampedZoomWhilePresenting'))
312+
canvas.screenshotting = true
313+
307314
// Register event handler for keyboard navigation
308315
canvas.wrapperEl.onkeydown = (e: any) => {
309316
if (this.plugin.settings.getSetting('useArrowKeysToChangeSlides')) {
@@ -361,6 +368,10 @@ export default class PresentationCanvasExtension extends CanvasExtension {
361368

362369
// Unlock canvas
363370
canvas.setReadonly(false)
371+
372+
// Re-enable zoom clamping
373+
if (this.plugin.settings.getSetting('useUnclampedZoomWhilePresenting'))
374+
canvas.screenshotting = false
364375

365376
// Exit fullscreen mode
366377
canvas.wrapperEl.classList.remove('presentation-mode')
@@ -420,10 +431,7 @@ export default class PresentationCanvasExtension extends CanvasExtension {
420431
if (!fromNode) return
421432

422433
const toNodeId = this.visitedNodeIds.last()
423-
if (!toNodeId) return
424-
425-
let toNode = canvas.nodes.get(toNodeId)
426-
if (!toNode) return
434+
let toNode = toNodeId ? canvas.nodes.get(toNodeId) : null
427435

428436
// Fall back to same node if there are no more nodes before
429437
if (!toNode) {

src/settings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface AdvancedCanvasPluginSettingsValues {
8181
useArrowKeysToChangeSlides: boolean
8282
usePgUpPgDownKeysToChangeSlides: boolean
8383
zoomToSlideWithoutPadding: boolean
84+
useUnclampedZoomWhilePresenting: boolean
8485
slideTransitionAnimationDuration: number
8586
slideTransitionAnimationIntensity: number
8687

@@ -159,6 +160,7 @@ export const DEFAULT_SETTINGS_VALUES: AdvancedCanvasPluginSettingsValues = {
159160
useArrowKeysToChangeSlides: true,
160161
usePgUpPgDownKeysToChangeSlides: true,
161162
zoomToSlideWithoutPadding: true,
163+
useUnclampedZoomWhilePresenting: false,
162164
slideTransitionAnimationDuration: 0.5,
163165
slideTransitionAnimationIntensity: 1.25,
164166

@@ -470,6 +472,11 @@ export const SETTINGS = {
470472
description: 'When enabled, the canvas will zoom to the slide without padding.',
471473
type: 'boolean'
472474
},
475+
useUnclampedZoomWhilePresenting: {
476+
label: 'Use unclamped zoom while presenting',
477+
description: 'When enabled, the zoom will not be clamped while presenting.',
478+
type: 'boolean'
479+
},
473480
slideTransitionAnimationDuration: {
474481
label: 'Slide transition animation duration',
475482
description: 'The duration of the slide transition animation in seconds. Set to 0 to disable the animation.',

src/utils/canvas-helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ export default class CanvasHelper {
165165

166166
static readonly MAX_ALLOWED_ZOOM = 1
167167
static getSmallestAllowedZoomBBox(canvas: Canvas, bbox: BBox): BBox {
168+
if (canvas.screenshotting) return bbox // Zoom is not limited when taking screenshots
169+
168170
if (canvas.canvasRect.width === 0 || canvas.canvasRect.height === 0) return bbox
169171

170172
const widthZoom = canvas.canvasRect.width / (bbox.maxX - bbox.minX)

0 commit comments

Comments
 (0)