Skip to content

Commit df7a0bb

Browse files
committed
Document undocumented methods; deprecate on_clicked and add on_click
1 parent ef00a96 commit df7a0bb

5 files changed

Lines changed: 17 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# v0.0.23 - 16 February 2025
22

3-
* Made `@text_keys` instance variable instead of local
4-
* Wrote up notes on special keyboard handling with filtering example
3+
* Exposed `@text_keys` as an instance variable instead of a local.
4+
* Wrote up notes on custom keyboard handling with a filtering example.
5+
* Documented `#delete_forward` and `#delete_back` methods.
6+
* Deprecated `on_clicked` and added `on_click` in it's place.
7+
* Documented `focused` argument and `#focused?` aliases for `focussed` and `#focussed?`
58

69
# v0.0.22 - 9 February 2025
710

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ The argument list below will list `prompt_color` but not the individual `prompt_
8282
* `word_wrap` - if the control should wrap (Boolean), default false
8383
* `readonly` - initial input read only state (Boolean), default false
8484
* `focussed` - initial input focus (Boolean), default false
85-
* `on_clicked` - on click callback, receives 2 parameters, the click and the `Input` control instance, default NOOP
85+
* `focused` - Alias for `focussed`
86+
* `on_clicked` - Deprecated - use `on_click`
87+
* `on_click` - on click callback, receives 2 parameters, the click and the `Input` control instance, default `NOOP`
8688
* `on_unhandled_key` - on unhandle key pressed callback, receives 2 parameters, the key and the `Input` control instance, default NOOP. This callback receives keys like `[tab]` and `[enter]`
8789
* `max_length` - maximum allowed length (Integer), default `false` which disables length checks
8890
* `fill_from_bottom` - fill the text from the bottom, like for a log or game terminal, default `false`
@@ -112,6 +114,9 @@ The argument list below will list `prompt_color` but not the individual `prompt_
112114
* `#replace(text)` - Alias for `#insert(text)`
113115
* `#replace_at(text, start, end = start)` - Alias for `#insert_at(text, start, end = start)`
114116
* `#append(text)` - Appends text the end of the value, without changing the selection
117+
* `#delete_forward` - Deletes selection or the character to the right of the cursor location if the selection is empty (typically in response to the `Delete` key)
118+
* `#delete_back` - Deletes selection or the character to the left of the cursor location if the selection is empty (typically in response to the `Backspace` key)
119+
* `#current_selection` - Returns the currently selected text
115120
* `#current_selection` - Returns the currently selected text
116121
* `#current_line` - Returns the currently selected line object
117122
* `#current_word` - Returns the word currently under the cursor
@@ -146,11 +151,12 @@ The argument list below will list `prompt_color` but not the individual `prompt_
146151
* `#focus` - Focusses the instance. Note the instance will only receive the focus after it's rendered. This prevents multiple instances from handling the keyboard and mouse events in the same tick.
147152
* `#blur` - Removes the focus from the instance. This happens immediately and the instance will not process keyboard and some mouse events after being blurred.
148153
* `#focussed?` - Returns true if the input is focussed, false otherwise
154+
* `#focused?` - Alias for `#focussed?`
149155
* `#value_changed?` - Returns true if the input value changed in the last tick, false otherwise
150156

151-
## Special keyboard handling
157+
## Custom keyboard handling
152158

153-
There may be cases where you want to do some special keyboard handling, like filtering out certain characters. In order to do this, create a subclass of `Input::Text` or `Input::Multiline` and override the `handle_keyboard` method, calling `super` when your special handling is done. The following instance variables are available:
159+
There may be cases where you want to do some custom keyboard handling, like filtering out certain characters. In order to do this, create a subclass of `Input::Text` or `Input::Multiline` and override the `handle_keyboard` method, calling `super` when your special handling is done. The following instance variables are available:
154160

155161
* `@meta` - true if the Meta key is down (the Command key on a Mac, or Windows key on Windows)
156162
* `@alt` - true if the Alt key is down

lib/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def initialize(**params) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticCo
7373
@focussed = params[:focussed] || params[:focused] || false
7474
@will_focus = false # Get the focus at the end of the tick
7575

76-
@on_clicked = params[:on_clicked] || NOOP
76+
@on_click = params[:on_click] || params[:on_clicked] || NOOP
7777
# @on_handled_key = params[:on_handled_key] || NOOP
7878
@on_unhandled_key = params[:on_unhandled_key] || NOOP
7979

lib/multiline.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def handle_mouse # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
302302
@selection_end = index
303303
@mouse_down = false if mouse.up
304304
else # clicking
305-
@on_clicked.call(mouse, self)
305+
@on_click.call(mouse, self)
306306
return unless (@focussed || @will_focus) && mouse.button_left
307307

308308
if @shift

lib/text.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def handle_mouse # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
108108
@selection_end = index
109109
@mouse_down = false if mouse.up
110110
else
111-
@on_clicked.call(mouse, self)
111+
@on_click.call(mouse, self)
112112
return unless @focussed || @will_focus
113113

114114
@mouse_down = true

0 commit comments

Comments
 (0)