Skip to content

Commit

Permalink
Try TextInput.blur calling on_gameport_resize
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Oct 24, 2024
1 parent c9f9e13 commit e0e3b85
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/glkote/web/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ 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

export class TextInput {
el: JQuery<HTMLElement>
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
Expand Down Expand Up @@ -54,6 +57,7 @@ export class TextInput {
}

private onblur() {
this.metrics.on_keyboard_change_focus()
scroll_window()
}

Expand Down
14 changes: 14 additions & 0 deletions src/glkote/web/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,27 @@ 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)) {
this.glkote.send_event({type: 'arrange'})
}
}, 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()){
Expand Down
2 changes: 1 addition & 1 deletion src/glkote/web/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/glkote/web/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ export default class Windows extends Map<number, Window> {
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
Expand Down

0 comments on commit e0e3b85

Please sign in to comment.