86 Commits

Author SHA1 Message Date
Hajime Hoshi 1a4c38c37d exp/textinput: add Field.ChangedAt for change detection
ChangedAt returns the time of the most recent observable state change —
text, selection, focus, or composition. Useful for cache invalidation,
autosave throttling, idle detection, and similar change-detection tasks.

The value is strictly monotonically increasing: back-to-back mutations
on coarse-clock platforms are clamped forward by 1ns so each mutation
yields a unique timestamp usable as a cache key.

No-op mutations (SetSelection to the current selection, empty
ReplaceText over a zero-width range, Focus/Blur that don't change focus,
Undo/Redo with nothing to apply) do not advance ChangedAt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 15:26:49 +09:00
Hajime Hoshi db24fb7c6b exp/textinput: clear queued states when text field is unfocused
The session's state queue buffers input events that arrive between
a commit-end and the next session start, which is needed when multiple
keys are pressed simultaneously (#3382). However, when a text field
was unfocused, keystroke events continued to be queued by the platform
layer and were replayed when a field was next focused, causing
unexpected text to appear.

Clear the queued states in Field.cleanUp(), which is called when a
field is blurred. This preserves the queue for simultaneous keypresses
within a focused field while discarding stale input from unfocused
periods.

Also refactor textInput to move the session field and theTextInput
variable to the cross-platform textinput.go, with each platform
defining only a textInputImpl with platform-specific fields.

Updates #3382
Closes #3429

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 02:52:51 +09:00
Hajime Hoshi d43f1ba7c3 all: rename objc.Class variables from classFooBar to class_FooBar
Rename all objc.Class variable names to use underscore-separated
convention matching the ObjC class names: class_NSFoo for "NSFoo",
class_GCController for "GCController", etc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 21:38:01 +09:00
Hajime Hoshi b02728fa73 all: rename objc.SEL variables from selFooBar to sel_fooBar
Rename all objc.SEL variable names to use underscore-separated
convention matching the ObjC selector names: sel_fooBar for
"fooBar", sel_fooBar_bazQux for "fooBar:bazQux:".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 21:33:19 +09:00
Hajime Hoshi b2e88b02ae exp/textinput: add Field.SetBounds and Field.Handled, process input via internal hook
Replace the per-frame HandleInputWithBounds call with SetBounds (call only
when bounds change) and Handled (query whether input was consumed). Input
processing now runs automatically via an internal hook on before-update,
so users no longer need to drive it every tick.

Deprecate HandleInput and HandleInputWithBounds in favor of the new API.

Closes #3420

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 23:14:28 +09:00
Hajime Hoshi 7cd654bf54 exp/textinput: add Field.HasText
Closes #3419

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 15:30:05 +09:00
TotallyGamerJet 3fa4cad5bb exp/textinput: convert to purego (#3410)
Updates #1162
2026-03-13 00:28:43 +09:00
Hajime Hoshi 3a9e3846cf exp/textinput: bug fix: wrong conversion from UTF-8 to UTF-16 2026-03-12 13:40:56 +09:00
Hajime Hoshi e4d7d9fe7e exp/textinput: refactoring 2026-02-24 02:27:56 +09:00
Hajime Hoshi 0199c97e6e ebiten: add RunOnMainThread
This change implements RunOnMainThread for most platforms.

Android and consoles don't support RunOnMainThread (yet).

Closes #3385
2026-02-24 00:26:53 +09:00
Hajime Hoshi 32aab7cea2 exp/textinput: bug fix: text cursor position was wrong on Windows
Closes #3389
2026-02-14 23:49:49 +09:00
Hajime Hoshi 59b985ac0a exp/textinput: implement input buffers for all the platforms
Closes #3382
2026-02-14 23:10:48 +09:00
Hajime Hoshi d319d09882 exp/textinput: bug fix: handle WM_IME_ENDCOMPOSITION
Closes #3388
2026-02-14 21:51:51 +09:00
Hajime Hoshi c0e65cd9b9 exp/textinput: bug fix: queue text inputs when the session is nil
Closes #3382
2026-02-11 00:40:00 +09:00
Hajime Hoshi 09bf4baf91 exp/textinput: add Field.ResetText
Updates guigui-gui/guigui#279
2026-01-07 01:11:30 +09:00
Hajime Hoshi cdf963da2d Revert "exp/textinput: initialize a piece table by replacing"
This reverts commit fe93e453bb.

Reason: explicit reseetting would make more sense.
For example, with the current commit, a text input's first input by
a user is treated as the initial state, and this is not expected.

Updates guigui-gui/guigui#279
2026-01-06 14:30:15 +09:00
Hajime Hoshi fe93e453bb exp/textinput: initialize a piece table by replacing
If the first operation is 'replace', disable undoing this.

Updates guigui-gui/guigui#279
2026-01-06 14:26:08 +09:00
Hajime Hoshi 2d63575ba0 exp/textinput: refactoring 2026-01-06 14:01:21 +09:00
Hajime Hoshi f3afbdf3fe exp/textinput: add comments
Updates #3367
2026-01-04 22:13:01 +09:00
Hajime Hoshi f706903ef1 exp/textinput: adjust undo/redo granularity
This change also updates Undo and Redo to update the selection for
better UX.

Closes #3367
2026-01-04 04:23:38 +09:00
Hajime Hoshi 6be823d2de exp/textinput: add Field.{Undo,Redo,CanUndo,CanRedo}
Updates #3367
2026-01-03 18:45:55 +09:00
Hajime Hoshi 989f9ac5d4 exp/textinput: add Field.ReplaceText{,AtSelection}
Closes #3365
2026-01-03 00:31:50 +09:00
Hajime Hoshi f679635d4e exp/textinput: add Field.WriteText{,ForRendering} and TextLengthInBytes
Updates #3365
2026-01-02 23:31:53 +09:00
Hajime Hoshi 58ed6ab79a exp/textinput: refactoring 2026-01-02 17:14:40 +09:00
Hajime Hoshi 24376cd4f0 exp/textinput: bug fix: go-vet failed 2026-01-02 17:14:40 +09:00
Hajime Hoshi bade455dc7 exp/textinput: add pieceTable
Updates #3365
2026-01-02 17:07:02 +09:00
Hajime Hoshi f0f0bb339d all: use errors.Join to catch all possible errors
Closes #3332
2025-10-17 23:39:13 +09:00
Hajime Hoshi cc905a0c39 exp/textinput: bug fix: do not ignore a keyup event even if isComposing=true
When an IME starts, the key events can be fired like this:

  1. `keydown` code=KeyA isComposing=false
  2. `compositionstart`
  3. `keyup` code=KeyA isComposing=true

Before this change, KeyA's keyup event was not treated in this case,
and the key was considered to be pressed forever.

This change fixes this issue by always treating keyup events even
if isComposing=true.

Closes #3328
2025-10-11 23:34:37 +09:00
Hajime Hoshi 150189a985 exp/textinput: add comments
Updates #3324
2025-10-05 13:31:32 +09:00
Hajime Hoshi 861b2b6b81 exp/textinput: bug fix: a rendered text was not updated when a compositing text is empty
Closes #3324
2025-10-05 13:30:53 +09:00
Hajime Hoshi 7cdf125cbb exp/textinput: adjust selection range at Set(TextAnd)Selection 2025-09-26 21:55:47 +09:00
Hajime Hoshi 61426ac72d text/v2, exp/textinput: bug fix: RuneLen could return -1 for errors 2025-06-09 01:32:21 +09:00
Hajime Hoshi 6a54d4dec0 exp/textinput: reimplement firstRectForCharacterRange 2025-05-13 13:59:15 +09:00
Hajime Hoshi 8ce47a0c47 exp/textinput: bug fix: wrong implementation of markedRange length 2025-05-13 03:04:55 +09:00
Hajime Hoshi 3256e256e2 exp/textinput: bug fix: wrong implentation of NSTextInputClient
Closes #3238
2025-05-12 23:48:49 +09:00
Hajime Hoshi dde281b93b exp/textinput: clarify the bounds for HandleInputWithBounds 2025-05-12 22:52:45 +09:00
Hajime Hoshi c112eb1752 exp/textinput: adjust positions for macOS 2025-05-12 22:46:07 +09:00
Hajime Hoshi 6bd9021a91 exp/textinput: add HandleInputWithBounds
Closes #3233
2025-05-12 22:09:00 +09:00
Hajime Hoshi bba2a83aa6 exp/textinput: handle popup to choose accents on macOS
Updates #3233
2025-05-12 21:20:05 +09:00
Hajime Hoshi a09581385c exp/textinput: add more tests 2025-05-12 19:12:17 +09:00
Hajime Hoshi 0c5d184630 exp/textinput: performance improvement of string functions 2025-05-12 19:10:51 +09:00
Hajime Hoshi 6eba9d6f5f exp/textinput: implement NSTextInputClient methods correctly
Updates #3233
2025-05-12 18:43:40 +09:00
Hajime Hoshi 50c72dda8e exp/textinput: use int64_t instead of int to assure 64bit length 2025-05-12 18:00:00 +09:00
Hajime Hoshi 6f294b23ec exp/textinput: refactoring
Updates #3233
2025-05-12 17:17:55 +09:00
Hajime Hoshi 608c6e3d2d exp/textinput: refactoring
Updates #3233
2025-05-12 15:12:57 +09:00
Hajime Hoshi 9ce989b5c7 exp/textinput: refactoring 2025-05-12 04:13:19 +09:00
Hajime Hoshi 0e6572443f exp/textinput: unexport State and Start
macOS requires the information of the current selection to implement
IME correctly, then the user must use Field. Field is no longer just
a wrapper API.

As this package is experimental, it is OK to have a breaking change,
though this is not ideal.

Updates #3233
2025-05-12 00:57:05 +09:00
Hajime Hoshi 5ed0a9bd4a exp/textinput: refactoring 2025-05-10 23:47:09 +09:00
Hajime Hoshi 0a20b41203 exp/textinput: bug fix: DEL char should not be inserted
Closes #3212
2025-04-21 02:52:31 +09:00
Hajime Hoshi dc741eaeed exp/textinput: bug fix: compilation failure on Linux 2025-03-24 23:02:27 +09:00