diff --git a/src/glkote/web/input.ts b/src/glkote/web/input.ts index 40e1ff9..4a2f4fd 100644 --- a/src/glkote/web/input.ts +++ b/src/glkote/web/input.ts @@ -15,6 +15,7 @@ import {is_pinch_zoomed} from '../../common/misc.js' import * as protocol from '../../common/protocol.js' import {apply_text_run_styles, type Window} from './windows.js' +import type Metrics from './metrics.js' const MAX_HISTORY_LENGTH = 25 @@ -22,9 +23,11 @@ export class TextInput { el: JQuery history_index = 0 is_line = false + metrics: Metrics window: Window constructor(window: Window) { + this.metrics = window.manager.glkote.metrics_calculator this.window = window // We use a textarea rather than an input because mobile Chrome shows an extra bar which can't be removed @@ -54,6 +57,7 @@ export class TextInput { } private onblur() { + this.metrics.on_keyboard_change_focus() scroll_window() } diff --git a/src/glkote/web/metrics.ts b/src/glkote/web/metrics.ts index 784fcb0..0f6a0d5 100644 --- a/src/glkote/web/metrics.ts +++ b/src/glkote/web/metrics.ts @@ -173,6 +173,7 @@ export default class Metrics { this.on_gameport_resize() return } + this.glkote.warning('on_gameport_resize 3') const oldmetrics = Object.assign({}, this.metrics) await this.measure() if (metrics_differ(this.metrics, oldmetrics)) { @@ -180,6 +181,19 @@ export default class Metrics { } }, 200, {leading: false}) + on_keyboard_change_focus() { + const gameport = this.glkote.dom.gameport() + + // And then set the outer height to the viewport height, accounting for any padding or margin + gameport.outerHeight(visualViewport!.height, true) + + // Safari might have scrolled weirdly, so try to put it right + window.scrollTo(0, 0) + + // Measure and send the new metrics + this.on_gameport_resize() + } + on_visualViewport_resize = () => { // Don't do anything if the window is pinch zoomed if (is_pinch_zoomed()){ diff --git a/src/glkote/web/web.ts b/src/glkote/web/web.ts index 5e74058..d0aee1d 100644 --- a/src/glkote/web/web.ts +++ b/src/glkote/web/web.ts @@ -47,7 +47,7 @@ export default class WebGlkOte extends GlkOte.GlkOteBase implements GlkOte.GlkOt prefix: '', windowport_id: 'windowport', }) - private metrics_calculator: Metrics + metrics_calculator: Metrics private showing_error = false private showing_loading = true private transcript_recorder?: TranscriptRecorder diff --git a/src/glkote/web/windows.ts b/src/glkote/web/windows.ts index 418d050..d039c77 100644 --- a/src/glkote/web/windows.ts +++ b/src/glkote/web/windows.ts @@ -723,7 +723,7 @@ export default class Windows extends Map { blorb?: Blorb // Note will be set after this is constructed, in WebGlkOte.init canvasResizeObserver?: ResizeObserver // Will only be created if the browser's ResizeObserver supports devicePixelContentBoxSize private dom: DOM - private glkote: WebGlkOte + glkote: WebGlkOte history: string[] = [] private metrics: protocol.NormalisedMetrics send_event: EventFunc