Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Pan the canvas by dragging, and past the slide's edges (#200)

nyblnetec07a97f6d2d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5f421e37..7e3b65f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,20 @@ pre-1.0.
## [Unreleased]
+- **Pan the canvas by dragging, and past the slide's edges.** The scrollbars
+ were the only way to move a zoomed slide, which puts the control at the edge
+ of the screen while the work is in the middle of it. **Hold space and drag**
+ to pan — the gesture nearly every canvas tool uses — or drag with the middle
+ mouse button if yours has one. On a trackpad a two-finger scroll already
+ panned once you were zoomed in, and still does.
+
+ Scrolling also used to stop dead at the slide's edges, so at high zoom a
+ corner element could never be moved off the corner of the screen to work on
+ it. There is now half a screen of room beyond every edge once you zoom past
+ fit — enough for any point on the slide to reach the middle — and none at all
+ while the whole slide fits, so a view that needs no scrollbars still has
+ none. Asked for by gcgbarbosa.
+
- **Fit height to text.** A text box that is too short lets its content spill
over whatever sits below it, and one that is too tall throws off its
alignment against everything beside it — neither is visible in the numbers.
diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.ts
index 902b2b08..8103fbb6 100644
--- a/slides/src/editor/canvas.ts
+++ b/slides/src/editor/canvas.ts
@@ -43,6 +43,10 @@ export class SlideCanvas {
* progress and was deferred so it wouldn't tear the edited node out from
* under the caret; flushed when the edit commits. */
private pendingRender = false
+ /** space is down and the canvas is armed to pan (see the keydown handler) */
+ private spaceHeld = false
+ /** a pan drag is in flight — keeps the grabbing cursor through a space release */
+ private panning = false
private pathEditor!: PathEditor
private lineEditor!: LineEditor
private bezierEditor!: BezierEditor
@@ -88,6 +92,54 @@ export class SlideCanvas {
this.onSlideNav(dir)
}, { passive: false })
+ // Middle-button drag pans. Until now the scrollbars were the only way to
+ // move a zoomed slide, which puts the control at the edge of the screen
+ // while the work is in the middle of it. Middle-drag is what design tools
+ // do, and unlike space-drag it cannot collide with typing a space.
+ //
+ // Capture phase, because Selecto is bound to this same scroller and would
+ // otherwise read the press as the start of a marquee.
+ this.scroller.addEventListener('mousedown', (ev) => {
+ // Middle button, or left button while space is held — the two gestures
+ // every canvas tool offers. Space is the one most hands already know;
+ // middle-drag is the one that works when a hand is on the mouse, and the
+ // one #166 asked for. Neither exists on an Apple trackpad, which is why
+ // a plain two-finger scroll still pans once the slide is zoomed past fit.
+ // canGrabSpace is re-checked HERE, not just when space armed the pan: a
+ // keyup can be missed (a native dialog, focus leaving mid-hold), and a
+ // canvas stuck in pan mode would swallow the click that starts a text
+ // edit. The press itself is the last honest moment to ask.
+ if (ev.button !== 1 && !(ev.button === 0 && this.spaceHeld && this.canGrabSpace())) return
+ ev.preventDefault() // suppress the OS autoscroll widget
+ ev.stopPropagation()
+ this.startPan(ev)
+ }, true)
+ // X11 pastes the selection on middle-click release; the drag consumed it
+ this.scroller.addEventListener('auxclick', (ev) => {
+ if (ev.button === 1) ev.preventDefault()
+ })
+
+ // Space arms the pan. It is unbound in the editor otherwise, but it DOES
+ // page a scroll container by default, so the keydown has to be swallowed
+ // while we own it. Never while text is being edited or a panel field has
+ // focus — there a space is a space.
+ window.addEventListener('keydown', (ev) => {
+ if (ev.key !== ' ' || ev.repeat || this.spaceHeld || !this.canGrabSpace()) return
+ ev.preventDefault()
+ this.spaceHeld = true
+ this.scroller.style.cursor = 'grab'
+ })
+ window.addEventListener('keyup', (ev) => {
+ if (ev.key !== ' ' || !this.spaceHeld) return
+ this.spaceHeld = false
+ if (!this.panning) this.scroller.style.cursor = ''
+ })
+ // Losing the window with space down would otherwise leave it stuck armed
+ window.addEventListener('blur', () => {
+ this.spaceHeld = false
+ if (!this.panning) this.scroller.style.cursor = ''
+ })
+
// Control box lives INSIDE the scaled host with rootContainer at body:
// Moveable then works in slide-local coordinates (e.left/e.top are model
// px), and `zoom` compensates the handles' visual size (set in relayout).
@@ -211,6 +263,52 @@ export class SlideCanvas {
this.render()
}
+ // --- panning ----------------------------------------------------------------
+
+ /**
+ * Is space free to mean "pan" right now? Not while any text is being edited
+ * on the canvas, and not while a panel field, the title or any other input
+ * has focus — in all of those a space is a character the user typed.
+ */
+ private canGrabSpace(): boolean {
+ if (this.editing || this.editingCell || this.isPathEditing) return false
+ const el = document.activeElement as HTMLElement | null
+ if (!el) return true
+ if (el.isContentEditable) return false
+ const tag = el.tagName
+ return tag !== 'INPUT' && tag !== 'TEXTAREA' && tag !== 'SELECT'
+ }
+
+ /**
+ * Drag the canvas from wherever it is now. Shared by both gestures so they
+ * cannot drift apart.
+ *
+ * The move/up listeners live on `window`: a pan that stops the moment the
+ * pointer crosses the panel edge would be useless precisely when panning
+ * matters, which is when the slide is bigger than the viewport.
+ */
+ private startPan(ev: MouseEvent) {
+ const fromX = ev.clientX
+ const fromY = ev.clientY
+ const atLeft = this.scroller.scrollLeft
+ const atTop = this.scroller.scrollTop
+ this.panning = true
+ this.scroller.style.cursor = 'grabbing'
+ const move = (m: MouseEvent) => {
+ this.scroller.scrollLeft = atLeft - (m.clientX - fromX)
+ this.scroller.scrollTop = atTop - (m.clientY - fromY)
+ }
+ const up = () => {
+ window.removeEventListener('mousemove', move, true)
+ window.removeEventListener('mouseup', up, true)
+ this.panning = false
+ // still armed if space is down, so keep the open hand rather than reset
+ this.scroller.style.cursor = this.spaceHeld ? 'grab' : ''
+ }
+ window.addEventListener('mousemove', move, true)
+ window.addEventListener('mouseup', up, true)
+ }
+
// --- layout & rendering ---------------------------------------------------
relayout() {
@@ -222,6 +320,19 @@ export class SlideCanvas {
this.scale = this.fitScale * this.zoom
this.stage.style.width = `${width * this.scale}px`
this.stage.style.height = `${height * this.scale}px`
+ // Pan room. Scrolling used to stop dead at the slide's edges, so at high
+ // zoom a corner element could never be moved off the corner of the screen
+ // to be worked on. Half a viewport of padding once the stage outgrows the
+ // window is exactly enough for any point on the slide to reach the middle.
+ //
+ // None at all while the whole slide fits: padding there would put
+ // scrollbars on a view that needs none, and — because the plain-wheel
+ // slide-nav stands down whenever the canvas is pannable — would silently
+ // cost the wheel gesture that walks slides. clientWidth is the padding
+ // box, so writing padding here cannot disturb the fitScale computed above.
+ const padX = width * this.scale > availW ? Math.round(this.scroller.clientWidth / 2) : 0
+ const padY = height * this.scale > availH ? Math.round(this.scroller.clientHeight / 2) : 0
+ this.scroller.style.padding = padX || padY ? `${padY}px ${padX}px` : ''
this.scaleHost.style.transform = `scale(${this.scale})`
this.moveable.zoom = 1 / this.scale
this.moveable.updateRect()
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index f9933be1..7ee57265 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -2367,6 +2367,11 @@ export class Editor {
['C', t('Comment mode')],
['?', t('This help')],
])
+ section(colL, t('Canvas'), [
+ [t('Space-drag'), t('Pan the canvas, including past the edges of the slide')],
+ [t('Middle-drag'), t('Pan as well, if your mouse has a middle button')],
+ [`${mod}-${t('scroll')}`, t('Zoom in and out')],
+ ])
section(colR, t('Lines & curves'), [
[t('Shape ▾'), t('Draw a line, curved line or connector — then drag on the canvas')],
[t('Drag a point'), t('Move an endpoint or anchor; drag the body to move the whole line')],
diff --git a/slides/src/i18n/de.ts b/slides/src/i18n/de.ts
index 1bbd6342..847e4fb8 100644
--- a/slides/src/i18n/de.ts
+++ b/slides/src/i18n/de.ts
@@ -730,4 +730,11 @@ export const de: Catalog = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": "{name} ist eine leere Kopie von Bento, keine gespeicherte Präsentation. Öffnen Sie die Datei einzeln, um eine zu beginnen.",
"Fit height to text": "Höhe an Text anpassen",
"The text needs {need}px and the box is {have}px": "Der Text braucht {need}px, das Feld ist {have}px hoch",
+ "Canvas": "Arbeitsfläche",
+ "Middle-drag": "Mit mittlerer Taste ziehen",
+ "scroll": "Scrollen",
+ "Pan the canvas, including past the edges of the slide": "Arbeitsfläche verschieben — auch über die Ränder der Folie hinaus",
+ "Zoom in and out": "Vergrößern und verkleinern",
+ "Space-drag": "Leertaste + ziehen",
+ "Pan as well, if your mouse has a middle button": "Verschiebt ebenfalls, wenn die Maus eine mittlere Taste hat",
}
diff --git a/slides/src/i18n/es.ts b/slides/src/i18n/es.ts
index 1224f934..0482fea0 100644
--- a/slides/src/i18n/es.ts
+++ b/slides/src/i18n/es.ts
@@ -730,4 +730,11 @@ export const es: Catalog = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": "{name} es una copia vacía de Bento, no una presentación guardada. Ábrela por su cuenta para empezar una.",
"Fit height to text": "Ajustar alto al texto",
"The text needs {need}px and the box is {have}px": "El texto necesita {need}px y la caja mide {have}px",
+ "Canvas": "Lienzo",
+ "Middle-drag": "Arrastrar con el botón central",
+ "scroll": "rueda",
+ "Pan the canvas, including past the edges of the slide": "Desplazar el lienzo, incluso más allá de los bordes de la diapositiva",
+ "Zoom in and out": "Acercar y alejar",
+ "Space-drag": "Espacio + arrastrar",
+ "Pan as well, if your mouse has a middle button": "También desplaza, si tu ratón tiene botón central",
}
diff --git a/slides/src/i18n/fr.ts b/slides/src/i18n/fr.ts
index cfe894d2..237e1c84 100644
--- a/slides/src/i18n/fr.ts
+++ b/slides/src/i18n/fr.ts
@@ -730,4 +730,11 @@ export const fr: Catalog = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": "{name} est une copie vierge de Bento, pas une présentation enregistrée. Ouvrez-la seule pour en commencer une.",
"Fit height to text": "Ajuster la hauteur au texte",
"The text needs {need}px and the box is {have}px": "Le texte nécessite {need}px et la boîte fait {have}px",
+ "Canvas": "Plan de travail",
+ "Middle-drag": "Glisser avec le bouton du milieu",
+ "scroll": "molette",
+ "Pan the canvas, including past the edges of the slide": "Déplacer le plan de travail, y compris au-delà des bords de la diapositive",
+ "Zoom in and out": "Zoomer et dézoomer",
+ "Space-drag": "Espace + glisser",
+ "Pan as well, if your mouse has a middle button": "Déplace aussi, si votre souris a un bouton du milieu",
}
diff --git a/slides/src/i18n/it.ts b/slides/src/i18n/it.ts
index 595e506e..a1d57e5c 100644
--- a/slides/src/i18n/it.ts
+++ b/slides/src/i18n/it.ts
@@ -730,4 +730,11 @@ export const it: Catalog = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": "{name} è una copia vuota di Bento, non una presentazione salvata. Aprila da sola per iniziarne una.",
"Fit height to text": "Adatta altezza al testo",
"The text needs {need}px and the box is {have}px": "Il testo richiede {need}px e la casella è di {have}px",
+ "Canvas": "Area di lavoro",
+ "Middle-drag": "Trascina col tasto centrale",
+ "scroll": "scorrimento",
+ "Pan the canvas, including past the edges of the slide": "Sposta l’area di lavoro, anche oltre i bordi della diapositiva",
+ "Zoom in and out": "Ingrandisci e riduci",
+ "Space-drag": "Spazio + trascina",
+ "Pan as well, if your mouse has a middle button": "Sposta anche, se il mouse ha il tasto centrale",
}
diff --git a/slides/src/i18n/ja.ts b/slides/src/i18n/ja.ts
index 531e2cc0..702c09ae 100644
--- a/slides/src/i18n/ja.ts
+++ b/slides/src/i18n/ja.ts
@@ -730,4 +730,11 @@ export const ja: Catalog = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": "{name} は保存済みのデッキではなく、空の Bento です。単独で開いて作成してください。",
"Fit height to text": "高さをテキストに合わせる",
"The text needs {need}px and the box is {have}px": "テキストには {need}px 必要で、ボックスは {have}px です",
+ "Canvas": "キャンバス",
+ "Middle-drag": "中ボタンドラッグ",
+ "scroll": "スクロール",
+ "Pan the canvas, including past the edges of the slide": "キャンバスを移動 — スライドの端を越えて動かせます",
+ "Zoom in and out": "拡大・縮小",
+ "Space-drag": "スペース+ドラッグ",
+ "Pan as well, if your mouse has a middle button": "中ボタンのあるマウスでも移動できます",
}
diff --git a/slides/src/i18n/packed.ts b/slides/src/i18n/packed.ts
index 5016d56d..f4f2f310 100644
--- a/slides/src/i18n/packed.ts
+++ b/slides/src/i18n/packed.ts
@@ -736,4 +736,11 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": ["{name} は保存済みのデッキではなく、空の Bento です。単独で開いて作成してください。","{name} 是一个空的 Bento 副本,不是已保存的演示文稿。请单独打开它以创建。","{name} 是一個空的 Bento 副本,不是已儲存的簡報。請單獨開啟它以建立。","{name} es una copia vacía de Bento, no una presentación guardada. Ábrela por su cuenta para empezar una.","{name} est une copie vierge de Bento, pas une présentation enregistrée. Ouvrez-la seule pour en commencer une.","{name} ist eine leere Kopie von Bento, keine gespeicherte Präsentation. Öffnen Sie die Datei einzeln, um eine zu beginnen.","{name} è una copia vuota di Bento, non una presentazione salvata. Aprila da sola per iniziarne una.","{name} é uma cópia vazia do Bento, não uma apresentação guardada. Abra-a sozinha para começar uma."],
"Fit height to text": ["高さをテキストに合わせる","高度适应文本","高度符合文字","Ajustar alto al texto","Ajuster la hauteur au texte","Höhe an Text anpassen","Adatta altezza al testo","Ajustar altura ao texto"],
"The text needs {need}px and the box is {have}px": ["テキストには {need}px 必要で、ボックスは {have}px です","文本需要 {need}px,文本框为 {have}px","文字需要 {need}px,文字方塊為 {have}px","El texto necesita {need}px y la caja mide {have}px","Le texte nécessite {need}px et la boîte fait {have}px","Der Text braucht {need}px, das Feld ist {have}px hoch","Il testo richiede {need}px e la casella è di {have}px","O texto precisa de {need}px e a caixa tem {have}px"],
+ "Canvas": ["キャンバス","画布","畫布","Lienzo","Plan de travail","Arbeitsfläche","Area di lavoro","Tela"],
+ "Middle-drag": ["中ボタンドラッグ","中键拖动","中鍵拖曳","Arrastrar con el botón central","Glisser avec le bouton du milieu","Mit mittlerer Taste ziehen","Trascina col tasto centrale","Arrastar com o botão do meio"],
+ "scroll": ["スクロール","滚动","捲動","rueda","molette","Scrollen","scorrimento","rolagem"],
+ "Pan the canvas, including past the edges of the slide": ["キャンバスを移動 — スライドの端を越えて動かせます","平移画布,可以移动到幻灯片边缘之外","平移畫布,可以移動到投影片邊緣之外","Desplazar el lienzo, incluso más allá de los bordes de la diapositiva","Déplacer le plan de travail, y compris au-delà des bords de la diapositive","Arbeitsfläche verschieben — auch über die Ränder der Folie hinaus","Sposta l’area di lavoro, anche oltre i bordi della diapositiva","Deslocar a tela, inclusive para além das bordas do slide"],
+ "Zoom in and out": ["拡大・縮小","放大与缩小","放大與縮小","Acercar y alejar","Zoomer et dézoomer","Vergrößern und verkleinern","Ingrandisci e riduci","Ampliar e reduzir"],
+ "Space-drag": ["スペース+ドラッグ","空格键+拖动","空白鍵+拖曳","Espacio + arrastrar","Espace + glisser","Leertaste + ziehen","Spazio + trascina","Espaço + arrastar"],
+ "Pan as well, if your mouse has a middle button": ["中ボタンのあるマウスでも移動できます","如果鼠标有中键,也可以平移","如果滑鼠有中鍵,也可以平移","También desplaza, si tu ratón tiene botón central","Déplace aussi, si votre souris a un bouton du milieu","Verschiebt ebenfalls, wenn die Maus eine mittlere Taste hat","Sposta anche, se il mouse ha il tasto centrale","Também desloca, se o rato tiver botão do meio"],
}
diff --git a/slides/src/i18n/pt.ts b/slides/src/i18n/pt.ts
index eb0e9a76..20d063bd 100644
--- a/slides/src/i18n/pt.ts
+++ b/slides/src/i18n/pt.ts
@@ -728,4 +728,11 @@ export const pt: Catalog = {
"Corner arrows": "Setas de canto",
"Fit height to text": "Ajustar altura ao texto",
"The text needs {need}px and the box is {have}px": "O texto precisa de {need}px e a caixa tem {have}px",
+ "Canvas": "Tela",
+ "Middle-drag": "Arrastar com o botão do meio",
+ "scroll": "rolagem",
+ "Pan the canvas, including past the edges of the slide": "Deslocar a tela, inclusive para além das bordas do slide",
+ "Zoom in and out": "Ampliar e reduzir",
+ "Space-drag": "Espaço + arrastar",
+ "Pan as well, if your mouse has a middle button": "Também desloca, se o rato tiver botão do meio",
}
diff --git a/slides/src/i18n/zh-Hans.ts b/slides/src/i18n/zh-Hans.ts
index 849c9935..2f5aeaa7 100644
--- a/slides/src/i18n/zh-Hans.ts
+++ b/slides/src/i18n/zh-Hans.ts
@@ -730,4 +730,11 @@ export const zhHans: Catalog = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": "{name} 是一个空的 Bento 副本,不是已保存的演示文稿。请单独打开它以创建。",
"Fit height to text": "高度适应文本",
"The text needs {need}px and the box is {have}px": "文本需要 {need}px,文本框为 {have}px",
+ "Canvas": "画布",
+ "Middle-drag": "中键拖动",
+ "scroll": "滚动",
+ "Pan the canvas, including past the edges of the slide": "平移画布,可以移动到幻灯片边缘之外",
+ "Zoom in and out": "放大与缩小",
+ "Space-drag": "空格键+拖动",
+ "Pan as well, if your mouse has a middle button": "如果鼠标有中键,也可以平移",
}
diff --git a/slides/src/i18n/zh-Hant.ts b/slides/src/i18n/zh-Hant.ts
index 3299e70e..96b68f32 100644
--- a/slides/src/i18n/zh-Hant.ts
+++ b/slides/src/i18n/zh-Hant.ts
@@ -730,4 +730,11 @@ export const zhHant: Catalog = {
"{name} is an empty copy of Bento, not a saved deck. Open it on its own to start one.": "{name} 是一個空的 Bento 副本,不是已儲存的簡報。請單獨開啟它以建立。",
"Fit height to text": "高度符合文字",
"The text needs {need}px and the box is {have}px": "文字需要 {need}px,文字方塊為 {have}px",
+ "Canvas": "畫布",
+ "Middle-drag": "中鍵拖曳",
+ "scroll": "捲動",
+ "Pan the canvas, including past the edges of the slide": "平移畫布,可以移動到投影片邊緣之外",
+ "Zoom in and out": "放大與縮小",
+ "Space-drag": "空白鍵+拖曳",
+ "Pan as well, if your mouse has a middle button": "如果滑鼠有中鍵,也可以平移",
}