Skip to content

Commit

Permalink
Don't measure a window's height above keyboard after every rearrange …
Browse files Browse the repository at this point in the history
…event, but only after submitting a keyboard event

Don't disable inputs immediately after submitting an input event (I'd hoped this would solve the issue. It didn't, but it still seems correct so I've kept it.)
  • Loading branch information
curiousdannii committed Dec 26, 2023
1 parent 9c45e35 commit 4d08f0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
13 changes: 4 additions & 9 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 {apply_text_run_styles, BufferWindow, Window} from './windows.js'
import {apply_text_run_styles, Window} from './windows.js'

const MAX_HISTORY_LENGTH = 25

Expand All @@ -32,12 +32,12 @@ export class TextInput {
this.el = $('<textarea>', {
'aria-hidden': 'true',
autocapitalize: 'off',
blur: () => this.onblur(),
class: 'Input',
data: {
window,
},
on: {
blur: () => this.onblur(),
focus: () => this.onfocus(),
input: (ev: any) => this.oninput(ev),
keydown: (ev: JQuery.KeyDownEvent) => this.onkeydown(ev),
Expand All @@ -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.scroll_to_bottom()
this.window.scroll_to_bottom()
}
// Scroll the browser window over the next 600ms
scroll_window()
Expand Down Expand Up @@ -170,7 +170,7 @@ export class TextInput {
refocus() {
if (this.window.type === 'buffer') {
const updateheight = this.window.innerel.outerHeight()! - this.window.updatescrolltop
if (updateheight > this.window.visibleheight) {
if (updateheight > this.window.height_above_keyboard) {
return
}
}
Expand All @@ -191,18 +191,13 @@ export class TextInput {
top: '',
width: '',
})
.prop('disabled', true)
.val('')
const inputparent = this.window.type === 'buffer' ? this.window.innerel : this.window.frameel
if (!this.el.parent().is(inputparent)) {
this.el.appendTo(inputparent)
}
}

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
19 changes: 8 additions & 11 deletions src/glkote/web/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ abstract class WindowBase {
ev.window = this.id
this.manager.send_event(ev)
}

update_textinput() {
this.textinput.update()
}
}

// Apply text run styles, accounting for reverse mode
Expand Down Expand Up @@ -326,11 +322,12 @@ const inline_alignment_classes: Record<string, string> = {

export class BufferWindow extends TextualWindow {
type = 'buffer' as const
/** How much height is available with the keyboard active */
height_above_keyboard: number
innerel: JQuery<HTMLElement>
private is_scrolled_down = true
lastline?: JQuery<HTMLElement>
updatescrolltop = 0
visibleheight: number

constructor(options: WindowConstructorOptions) {
super(options)
Expand All @@ -343,18 +340,18 @@ export class BufferWindow extends TextualWindow {
this.innerel = create('div', 'BufferWindowInner')
.append(this.textinput.el)
.appendTo(this.frameel)
this.visibleheight = this.frameel.height()!
this.height_above_keyboard = this.frameel.height()!
}

/** Measure the height of the window that is currently visible (excluding virtual keyboards for example) */
measure_height() {
this.visibleheight = this.frameel.height()!
this.height_above_keyboard = this.frameel.height()!
}

protected onclick(_: JQuery.ClickEvent) {
if (this.inputs?.type && no_text_selected()) {
// Check that we've scrolled to the bottom (if there is actually text in this window)
if (this.lastline && this.visibleheight) {
if (this.lastline && this.height_above_keyboard) {
const rect = this.lastline[0].getBoundingClientRect()
if (rect.bottom < 0 || rect.top > document.documentElement.clientHeight) {
return false
Expand Down Expand Up @@ -767,8 +764,8 @@ export default class Windows extends Map<number, Window> {
if (!update && win.inputs) {
if (win.textinput.el.is(':focus')) {
this.active_window = win
win.textinput.el.trigger('blur')
}
win.textinput.el.prop('disabled', true)
delete win.inputs
}
}
Expand Down Expand Up @@ -891,7 +888,7 @@ export default class Windows extends Map<number, Window> {
width: update.width,
})
if (win.type === 'buffer') {
win.measure_height()
//win.measure_height()
win.scroll_to_bottom(true)
}
}
Expand Down Expand Up @@ -941,7 +938,7 @@ export default class Windows extends Map<number, Window> {
win.inputs = update
if (update.type){
if (update.gen !== oldgen) {
win.update_textinput()
win.textinput.update()
}
}
}
Expand Down

0 comments on commit 4d08f0d

Please sign in to comment.