Skip to content

Commit

Permalink
In mobile Chrome buffer windows weren't scrolled correctly after open…
Browse files Browse the repository at this point in the history
…ing the virtual keyboard. After the new window metrics have been applied, we must rescroll buffer windows to the bottom

Set #gameport to overflow: clip
  • Loading branch information
curiousdannii committed Dec 24, 2023
1 parent 080f126 commit 3f568eb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/glkote/web/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {KEY_CODE_DOWN, KEY_CODE_RETURN, KEY_CODE_UP, KEY_CODES_TO_NAMES, OFFSCRE
import * as protocol from '../../common/protocol.js'

import {is_pinch_zoomed} from './shared.js'
import {Window, apply_text_run_styles} from './windows.js'
import {apply_text_run_styles, BufferWindow, Window} from './windows.js'

const MAX_HISTORY_LENGTH = 25

Expand Down Expand Up @@ -60,7 +60,7 @@ export class TextInput {
private onfocus() {
// Ensure a buffer window is scrolled down
if (this.window.type === 'buffer' && !is_pinch_zoomed()) {
this.window.frameel.scrollTop(this.window.innerel.height()!)
this.scroll_to_bottom()
}
// Scroll the browser window over the next 600ms
scroll_window()
Expand Down Expand Up @@ -199,6 +199,10 @@ export class TextInput {
}
}

private scroll_to_bottom = () => {
(this.window as BufferWindow).scroll_to_bottom()
}

private submit_char(val: string) {
this.window.send_text_event({
type: 'char',
Expand Down
4 changes: 2 additions & 2 deletions src/glkote/web/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export default class Metrics {
window.scrollTo(0, 0)
if (input_is_active) {
const window: Window = $(document.activeElement!).data('window')
if (window && window.type === 'buffer') {
window.frameel.scrollTop(window.innerel.height()!)
if (window?.type === 'buffer') {
window.scroll_to_bottom()
}
}

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 @@ -155,7 +155,7 @@ export default class WebGlkOte extends GlkOte.GlkOteBase implements GlkOte.GlkOt
for (const win of this.windows.values()) {
// Scroll all buffer windows
if (win.type === 'buffer') {
win.frameel.scrollTop(win.innerel.height()!)
win.scroll_to_bottom()
}
}

Expand Down
22 changes: 20 additions & 2 deletions src/glkote/web/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ const inline_alignment_classes: Record<string, string> = {
marginright: 'ImageMarginRight',
}

class BufferWindow extends TextualWindow {
export class BufferWindow extends TextualWindow {
type = 'buffer' as const
innerel: JQuery<HTMLElement>
private is_scrolled_down = true
lastline?: JQuery<HTMLElement>
updatescrolltop = 0
visibleheight: number
Expand All @@ -338,6 +339,7 @@ class BufferWindow extends TextualWindow {
role: 'log',
tabindex: -1,
})
.on('scroll', this.onscroll)
this.innerel = create('div', 'BufferWindowInner')
.append(this.textinput.el)
.appendTo(this.frameel)
Expand All @@ -363,6 +365,19 @@ class BufferWindow extends TextualWindow {
}
}

// When the frame element is scrolled, update whether it's scrolled to the bottom
private onscroll = () => {
const frameel = this.frameel[0]
this.is_scrolled_down = frameel.scrollHeight - frameel.scrollTop - frameel.clientHeight < 1
}

// Scroll to the bottom, unless `after_metrics_change` is set, in which case only scroll if we *should* be at the bottom (used after updating metrics)
scroll_to_bottom(after_metrics_change?: boolean) {
if (!after_metrics_change || this.is_scrolled_down) {
this.frameel.scrollTop(this.innerel.height()!)
}
}

update(data: protocol.BufferWindowContentUpdate) {
if (data.clear) {
this.innerel.children('.BufferLine').remove()
Expand Down Expand Up @@ -875,7 +890,10 @@ export default class Windows extends Map<number, Window> {
top: update.top,
width: update.width,
})
win.measure_height()
if (win.type === 'buffer') {
win.measure_height()
win.scroll_to_bottom(true)
}
}

const windowstoclose: Window[] = []
Expand Down

0 comments on commit 3f568eb

Please sign in to comment.