@rbxts/centurion-ui 2.0.0-rc.5 → 2.0.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/centurion.luau +4 -1
- package/package.json +2 -2
- package/src/analyse/highlight.luau +7 -8
- package/src/analyse/init.luau +48 -24
- package/src/analyse/suggest.luau +29 -13
- package/src/app/history.luau +11 -1
- package/src/app/init.luau +107 -5
- package/src/app/suggestions.luau +35 -1
- package/src/components/textbox.luau +3 -3
- package/src/init.luau +3 -1
- package/src/state.luau +1 -1
- package/src/ts/index.d.ts +1 -0
package/centurion.luau
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
local centurion = require(
|
|
1
|
+
local centurion = require("../centurion/src")
|
|
2
2
|
|
|
3
3
|
export type Argument = centurion.Argument
|
|
4
4
|
export type ArgumentRange = centurion.ArgumentRange
|
|
5
5
|
export type Command<T...> = centurion.Command<T...>
|
|
6
6
|
export type Response = centurion.Response
|
|
7
7
|
export type Result<T = unknown> = centurion.Result<T>
|
|
8
|
+
export type Suggestion = centurion.Suggestion
|
|
9
|
+
export type SuggestionData = centurion.SuggestionData
|
|
10
|
+
export type SuggestionList = centurion.SuggestionList
|
|
8
11
|
export type Token = centurion.Token
|
|
9
12
|
|
|
10
13
|
return centurion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/centurion-ui",
|
|
3
3
|
"description": "Terminal UI for the Centurion command framework",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
4
|
+
"version": "2.0.0-rc.7",
|
|
5
5
|
"author": "paradoxuum",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/ts/init.luau",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@rbxts/centurion": "^2.0.0-rc.
|
|
36
|
+
"@rbxts/centurion": "^2.0.0-rc.4"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {}
|
|
39
39
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
--!strict
|
|
2
|
-
local Players = game:GetService("Players")
|
|
3
|
-
|
|
4
2
|
local centurion = require("../../centurion")
|
|
5
3
|
local rich = require("../rich")
|
|
6
4
|
local types = require("../types")
|
|
7
5
|
|
|
8
6
|
type Kind = "command" | "argument" | "string" | "invalid"
|
|
9
7
|
|
|
10
|
-
local function is_valid(raw: string, arg: centurion.Argument): boolean
|
|
11
|
-
|
|
8
|
+
local function is_valid(executor: Player, raw: string, arg: centurion.Argument): boolean
|
|
9
|
+
-- this runs while vide updates, which breaks if a transform yields
|
|
10
|
+
local ok, result = pcall(centurion.check_arg, executor, arg, raw)
|
|
12
11
|
return ok and result.success
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
local function classify(text: string): { { span: vector, kind: Kind } }
|
|
14
|
+
local function classify(executor: Player, text: string): { { span: vector, kind: Kind } }
|
|
16
15
|
local resolution = centurion.resolve_command(text)
|
|
17
16
|
local tokens = resolution.tokens
|
|
18
17
|
local cmds = centurion.registry.commands
|
|
@@ -45,7 +44,7 @@ local function classify(text: string): { { span: vector, kind: Kind } }
|
|
|
45
44
|
local token = tokens[cmd_index + j]
|
|
46
45
|
local raw = text:sub(token.span.x, token.span.y)
|
|
47
46
|
|
|
48
|
-
if not is_valid(raw, arg) then
|
|
47
|
+
if not is_valid(executor, raw, arg) then
|
|
49
48
|
add(token, "invalid")
|
|
50
49
|
elseif raw:match("^[\"']") then
|
|
51
50
|
add(token, "string")
|
|
@@ -68,7 +67,7 @@ local function classify(text: string): { { span: vector, kind: Kind } }
|
|
|
68
67
|
return highlights
|
|
69
68
|
end
|
|
70
69
|
|
|
71
|
-
local function highlight(text: string, theme: types.Theme): string
|
|
70
|
+
local function highlight(executor: Player, text: string, theme: types.Theme): string
|
|
72
71
|
local colors: { [Kind]: Color3 } = {
|
|
73
72
|
command = theme.highlight,
|
|
74
73
|
argument = theme.text,
|
|
@@ -78,7 +77,7 @@ local function highlight(text: string, theme: types.Theme): string
|
|
|
78
77
|
|
|
79
78
|
local out = {}
|
|
80
79
|
local pos = 1
|
|
81
|
-
for _, item in classify(text) do
|
|
80
|
+
for _, item in classify(executor, text) do
|
|
82
81
|
table.insert(out, rich.escape(text:sub(pos, item.span.x - 1)))
|
|
83
82
|
table.insert(out, rich.color(rich.escape(text:sub(item.span.x, item.span.y)), colors[item.kind]))
|
|
84
83
|
pos = item.span.y + 1
|
package/src/analyse/init.luau
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
--!strict
|
|
2
|
-
local Players = game:GetService("Players")
|
|
3
|
-
|
|
4
2
|
local centurion = require("../centurion")
|
|
5
3
|
local cursor = require("@self/cursor")
|
|
6
4
|
local match = require("@self/match")
|
|
7
5
|
local suggest = require("@self/suggest")
|
|
8
6
|
local types = require("./types")
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
-- a string is shorthand for a suggestion that's only found by its text
|
|
9
|
+
local function normalize(suggestion: centurion.Suggestion): centurion.SuggestionData
|
|
10
|
+
if type(suggestion) == "string" then
|
|
11
|
+
return { text = suggestion }
|
|
12
|
+
end
|
|
13
|
+
return suggestion
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
local function suggestion_keys(suggestion: centurion.SuggestionData): { string }
|
|
17
|
+
local keys = { suggestion.text }
|
|
18
|
+
if suggestion.aliases then
|
|
19
|
+
for _, alias in suggestion.aliases do
|
|
20
|
+
table.insert(keys, alias)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
return keys
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
local function analyse(
|
|
27
|
+
executor: Player,
|
|
28
|
+
text: string,
|
|
29
|
+
cursor_pos: number,
|
|
30
|
+
max_suggestions: number?
|
|
31
|
+
): types.AnalysisResult
|
|
11
32
|
local resolution = centurion.resolve_command(text)
|
|
12
33
|
local tokens = resolution.tokens
|
|
13
34
|
|
|
@@ -62,12 +83,12 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
62
83
|
end
|
|
63
84
|
|
|
64
85
|
return {
|
|
65
|
-
result = centurion.
|
|
86
|
+
result = centurion.check_args(executor, arg_text, cmd_args),
|
|
66
87
|
suggestions = {},
|
|
67
88
|
}
|
|
68
89
|
end
|
|
69
90
|
|
|
70
|
-
local transform_result = centurion.
|
|
91
|
+
local transform_result = centurion.check_args(executor, arg_text, cmd_args)
|
|
71
92
|
|
|
72
93
|
if not at_arg then
|
|
73
94
|
return {
|
|
@@ -143,35 +164,37 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
143
164
|
end
|
|
144
165
|
end
|
|
145
166
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
167
|
+
-- the type's suggestions come before the argument's own, and the first
|
|
168
|
+
-- suggestion with a given text wins
|
|
169
|
+
local arg_suggestions: { centurion.SuggestionData } = {}
|
|
170
|
+
local seen: { [string]: true } = {}
|
|
171
|
+
local function add(list: centurion.SuggestionList?)
|
|
172
|
+
if not list then
|
|
173
|
+
return
|
|
174
|
+
end
|
|
150
175
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
176
|
+
for _, item in list do
|
|
177
|
+
local suggestion = normalize(item)
|
|
178
|
+
if not seen[suggestion.text] then
|
|
179
|
+
seen[suggestion.text] = true
|
|
180
|
+
table.insert(arg_suggestions, suggestion)
|
|
181
|
+
end
|
|
154
182
|
end
|
|
155
183
|
end
|
|
156
184
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
for i = #arg_suggestions, 1, -1 do
|
|
160
|
-
local suggestion = arg_suggestions[i]
|
|
161
|
-
if seen[suggestion] then
|
|
162
|
-
table.remove(arg_suggestions, i)
|
|
163
|
-
else
|
|
164
|
-
seen[suggestion] = true
|
|
165
|
-
end
|
|
185
|
+
if arg_type.suggestions then
|
|
186
|
+
add(arg_type.suggestions(input_token.text, executor, arg))
|
|
166
187
|
end
|
|
188
|
+
add(arg.suggestions)
|
|
167
189
|
|
|
168
190
|
local suggestions = {}
|
|
169
191
|
local hidden = 0
|
|
170
192
|
if #arg_suggestions > 0 then
|
|
171
|
-
local matches, total = suggest(input_token.text, arg_suggestions, max_suggestions)
|
|
193
|
+
local matches, total = suggest(input_token.text, arg_suggestions, max_suggestions, suggestion_keys)
|
|
172
194
|
hidden = total - #matches
|
|
173
195
|
|
|
174
|
-
for _,
|
|
196
|
+
for _, item in matches do
|
|
197
|
+
local suggestion_text = item.text
|
|
175
198
|
local replacement = ""
|
|
176
199
|
local replacement_text = {}
|
|
177
200
|
for _, replacement_token in centurion.parse_text(suggestion_text, " ").tokens do
|
|
@@ -187,6 +210,7 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
187
210
|
local suggestion = {
|
|
188
211
|
kind = "argument",
|
|
189
212
|
name = suggestion_text,
|
|
213
|
+
description = item.description,
|
|
190
214
|
matches = match(input_token.text, suggestion_text),
|
|
191
215
|
|
|
192
216
|
span = input_token.span,
|
|
@@ -209,7 +233,7 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
209
233
|
end
|
|
210
234
|
|
|
211
235
|
local function process_command(): types.AnalysisResult
|
|
212
|
-
local to_match = {}
|
|
236
|
+
local to_match: { string } = {}
|
|
213
237
|
for k, _ in cmds do
|
|
214
238
|
if k == cmd_name then
|
|
215
239
|
continue
|
package/src/analyse/suggest.luau
CHANGED
|
@@ -40,8 +40,28 @@ local function subsequence_bonus(query: string, candidate: string): number
|
|
|
40
40
|
return best
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
local function score(normalized: string, key: string): number
|
|
44
|
+
if key:sub(1, #normalized):lower() == normalized then
|
|
45
|
+
return 1000 - (#key - #normalized)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
local distance = leventine.score(normalized, key, false)
|
|
49
|
+
return (1 - distance / math.max(#normalized, #key)) * 100 + subsequence_bonus(normalized, key:lower())
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
local function identity(candidate: any): { string }
|
|
53
|
+
return { candidate }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
-- returns the best matches, and how many there were before being limited.
|
|
57
|
+
-- `keys` gives the strings a candidate can be found by, and its best scoring
|
|
58
|
+
-- key ranks it. by default a candidate is its own only key
|
|
59
|
+
local function suggest<T>(
|
|
60
|
+
input: string,
|
|
61
|
+
candidates: { T },
|
|
62
|
+
max_suggestions: number?,
|
|
63
|
+
keys: ((candidate: T) -> { string })?
|
|
64
|
+
): ({ T }, number)
|
|
45
65
|
if #input == 0 then
|
|
46
66
|
if max_suggestions and #candidates > max_suggestions then
|
|
47
67
|
return { unpack(candidates, 1, max_suggestions) }, #candidates
|
|
@@ -49,21 +69,17 @@ local function suggest(input: string, candidates: { string }, max_suggestions: n
|
|
|
49
69
|
return candidates, #candidates
|
|
50
70
|
end
|
|
51
71
|
|
|
72
|
+
local get_keys = keys or identity
|
|
52
73
|
local normalized = input:lower()
|
|
53
74
|
local scored = {}
|
|
54
75
|
for _, candidate in candidates do
|
|
55
|
-
local
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
score = 1000 - (#candidate - #normalized)
|
|
59
|
-
else
|
|
60
|
-
score = leventine.score(normalized, candidate, false)
|
|
61
|
-
score = (1 - score / math.max(#normalized, #candidate)) * 100
|
|
62
|
-
score += subsequence_bonus(normalized, candidate:lower())
|
|
76
|
+
local best = MIN_SCORE
|
|
77
|
+
for _, key in get_keys(candidate) do
|
|
78
|
+
best = math.max(best, score(normalized, key))
|
|
63
79
|
end
|
|
64
80
|
|
|
65
|
-
if
|
|
66
|
-
table.insert(scored, {
|
|
81
|
+
if best > MIN_SCORE then
|
|
82
|
+
table.insert(scored, { value = candidate, score = best })
|
|
67
83
|
end
|
|
68
84
|
end
|
|
69
85
|
|
|
@@ -73,7 +89,7 @@ local function suggest(input: string, candidates: { string }, max_suggestions: n
|
|
|
73
89
|
|
|
74
90
|
local mapped = {}
|
|
75
91
|
for i = 1, math.min(max_suggestions or #scored, #scored) do
|
|
76
|
-
table.insert(mapped, scored[i].
|
|
92
|
+
table.insert(mapped, scored[i].value)
|
|
77
93
|
end
|
|
78
94
|
return mapped, #scored
|
|
79
95
|
end
|
package/src/app/history.luau
CHANGED
|
@@ -23,8 +23,12 @@ local spring = vide.spring
|
|
|
23
23
|
|
|
24
24
|
type History = {
|
|
25
25
|
read max_lines: number | () -> number,
|
|
26
|
+
-- the most room the history can take up, in pixels, so it fits on screen
|
|
27
|
+
read max_height: (() -> number)?,
|
|
26
28
|
read on_select: (command: string) -> (),
|
|
27
29
|
read order: number?,
|
|
30
|
+
|
|
31
|
+
[number]: unknown,
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
local line_height = 23
|
|
@@ -197,7 +201,11 @@ local function history(props: History)
|
|
|
197
201
|
if height == 0 then
|
|
198
202
|
return UDim2.new()
|
|
199
203
|
end
|
|
200
|
-
|
|
204
|
+
height = math.min(height, max_height()) + px.convert(top_padding)
|
|
205
|
+
if props.max_height then
|
|
206
|
+
height = math.min(height, math.max(props.max_height(), 0))
|
|
207
|
+
end
|
|
208
|
+
return UDim2.fromOffset(0, height)
|
|
201
209
|
end, 0.1),
|
|
202
210
|
|
|
203
211
|
ScrollBarThickness = px(3),
|
|
@@ -257,6 +265,8 @@ local function history(props: History)
|
|
|
257
265
|
indexes(state.logs, function(value: () -> types.Log, i: number)
|
|
258
266
|
return entry(value, i, props.on_select)
|
|
259
267
|
end),
|
|
268
|
+
|
|
269
|
+
unpack(props),
|
|
260
270
|
}
|
|
261
271
|
end
|
|
262
272
|
|
package/src/app/init.luau
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
local ContextActionService = game:GetService("ContextActionService")
|
|
2
|
+
local GuiService = game:GetService("GuiService")
|
|
2
3
|
local Players = game:GetService("Players")
|
|
3
4
|
local RunService = game:GetService("RunService")
|
|
4
5
|
local UserInputService = game:GetService("UserInputService")
|
|
@@ -79,6 +80,22 @@ local function app()
|
|
|
79
80
|
keyboard_visible(UserInputService.OnScreenKeyboardVisible)
|
|
80
81
|
end))
|
|
81
82
|
|
|
83
|
+
-- top edge of the on-screen keyboard, in the same space as the console, or
|
|
84
|
+
-- nil when there isn't one taking up the screen
|
|
85
|
+
local function read_keyboard_top(): number?
|
|
86
|
+
if UserInputService.OnScreenKeyboardSize.Y <= 0 then
|
|
87
|
+
return nil
|
|
88
|
+
end
|
|
89
|
+
-- the keyboard is placed on the whole screen, while the console is placed below the topbar
|
|
90
|
+
return UserInputService.OnScreenKeyboardPosition.Y - GuiService:GetGuiInset().Y
|
|
91
|
+
end
|
|
92
|
+
local keyboard_top = source(read_keyboard_top())
|
|
93
|
+
local function update_keyboard_top()
|
|
94
|
+
keyboard_top(read_keyboard_top())
|
|
95
|
+
end
|
|
96
|
+
cleanup(UserInputService:GetPropertyChangedSignal("OnScreenKeyboardPosition"):Connect(update_keyboard_top))
|
|
97
|
+
cleanup(UserInputService:GetPropertyChangedSignal("OnScreenKeyboardSize"):Connect(update_keyboard_top))
|
|
98
|
+
|
|
82
99
|
local next_cursor_pos = false
|
|
83
100
|
local refocus_deadline = 0
|
|
84
101
|
local cmd_history = {}
|
|
@@ -271,7 +288,7 @@ local function app()
|
|
|
271
288
|
untrack(function()
|
|
272
289
|
local input_text = raw_text()
|
|
273
290
|
if #input_text > 0 then
|
|
274
|
-
analysis(analyse(input_text, #input_text + 1, state.max_suggestions()))
|
|
291
|
+
analysis(analyse(Players.LocalPlayer, input_text, #input_text + 1, state.max_suggestions()))
|
|
275
292
|
end
|
|
276
293
|
end)
|
|
277
294
|
end)
|
|
@@ -318,7 +335,7 @@ local function app()
|
|
|
318
335
|
pos = #raw_text() + 1
|
|
319
336
|
end
|
|
320
337
|
|
|
321
|
-
analysis(analyse(raw_text(), pos, state.max_suggestions()))
|
|
338
|
+
analysis(analyse(Players.LocalPlayer, raw_text(), pos, state.max_suggestions()))
|
|
322
339
|
end)
|
|
323
340
|
end)
|
|
324
341
|
|
|
@@ -457,6 +474,76 @@ local function app()
|
|
|
457
474
|
return if has_popover() then 1 else 0
|
|
458
475
|
end, 0.12)
|
|
459
476
|
|
|
477
|
+
-- on short screens the history gives up room first, then the suggestions,
|
|
478
|
+
-- so that neither runs off the bottom of the screen
|
|
479
|
+
local bounds_bottom = source(math.huge)
|
|
480
|
+
local console_top = source(0)
|
|
481
|
+
-- height of the console without its history
|
|
482
|
+
local console_fixed = source(0)
|
|
483
|
+
local popover_height = source(0)
|
|
484
|
+
local frames: { [string]: GuiObject } = {}
|
|
485
|
+
|
|
486
|
+
local function measure()
|
|
487
|
+
local console, history_frame, popover = frames.console, frames.history, frames.popover
|
|
488
|
+
if console and history_frame then
|
|
489
|
+
console_top(console.AbsolutePosition.Y)
|
|
490
|
+
-- read together so both sizes are from the same layout pass
|
|
491
|
+
console_fixed(console.AbsoluteSize.Y - history_frame.AbsoluteSize.Y)
|
|
492
|
+
end
|
|
493
|
+
if popover then
|
|
494
|
+
popover_height(popover.AbsoluteSize.Y)
|
|
495
|
+
end
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
local function measured(name: string)
|
|
499
|
+
return action(function(instance: GuiObject)
|
|
500
|
+
frames[name] = instance
|
|
501
|
+
cleanup(instance:GetPropertyChangedSignal("AbsoluteSize"):Connect(measure))
|
|
502
|
+
cleanup(instance:GetPropertyChangedSignal("AbsolutePosition"):Connect(measure))
|
|
503
|
+
end)
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
-- room for the history and suggestions, between the input and the bottom of the screen
|
|
507
|
+
local function free_space()
|
|
508
|
+
local bottom = bounds_bottom()
|
|
509
|
+
-- shrink out of the way of the on-screen keyboard while it's open. consoles
|
|
510
|
+
-- are left alone, since their keyboard covers the whole screen anyway
|
|
511
|
+
local top_of_keyboard = keyboard_top()
|
|
512
|
+
if touch() and keyboard_visible() and top_of_keyboard then
|
|
513
|
+
bottom = math.min(bottom, top_of_keyboard)
|
|
514
|
+
end
|
|
515
|
+
return bottom - px.convert(8) - console_top() - console_fixed()
|
|
516
|
+
end
|
|
517
|
+
|
|
518
|
+
-- the bottom of whatever the console is drawn in, usually the ScreenGui
|
|
519
|
+
local track_bounds = action(function(instance: GuiObject)
|
|
520
|
+
local connection: RBXScriptConnection? = nil
|
|
521
|
+
|
|
522
|
+
local function update_parent()
|
|
523
|
+
if connection then
|
|
524
|
+
connection:Disconnect()
|
|
525
|
+
connection = nil
|
|
526
|
+
end
|
|
527
|
+
|
|
528
|
+
local parent = instance.Parent
|
|
529
|
+
if parent and parent:IsA("GuiBase2d") then
|
|
530
|
+
local function update()
|
|
531
|
+
bounds_bottom(parent.AbsolutePosition.Y + parent.AbsoluteSize.Y)
|
|
532
|
+
end
|
|
533
|
+
connection = parent:GetPropertyChangedSignal("AbsoluteSize"):Connect(update)
|
|
534
|
+
update()
|
|
535
|
+
end
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
cleanup(instance:GetPropertyChangedSignal("Parent"):Connect(update_parent))
|
|
539
|
+
cleanup(function()
|
|
540
|
+
if connection then
|
|
541
|
+
connection:Disconnect()
|
|
542
|
+
end
|
|
543
|
+
end)
|
|
544
|
+
update_parent()
|
|
545
|
+
end)
|
|
546
|
+
|
|
460
547
|
-- created inside the console so that it fades with it
|
|
461
548
|
local function input_field()
|
|
462
549
|
return background {
|
|
@@ -535,7 +622,7 @@ local function app()
|
|
|
535
622
|
text {
|
|
536
623
|
size = UDim2.fromScale(1, 1),
|
|
537
624
|
text = function()
|
|
538
|
-
return if touch() then "" else highlight(raw_text(), state.theme())
|
|
625
|
+
return if touch() then "" else highlight(Players.LocalPlayer, raw_text(), state.theme())
|
|
539
626
|
end,
|
|
540
627
|
rich_text = true,
|
|
541
628
|
xalignment = Enum.TextXAlignment.Left,
|
|
@@ -572,8 +659,11 @@ local function app()
|
|
|
572
659
|
end,
|
|
573
660
|
|
|
574
661
|
focused = state.focused,
|
|
575
|
-
update_focused = function(focused)
|
|
576
|
-
if focused then
|
|
662
|
+
update_focused = function(focused, enter)
|
|
663
|
+
if focused or enter then
|
|
664
|
+
-- pressing enter right after selecting an entry shouldn't refocus
|
|
665
|
+
-- straight away, since capturing focus while enter is still being
|
|
666
|
+
-- handled leaves whitespace in the textbox
|
|
577
667
|
refocus_deadline = 0
|
|
578
668
|
elseif os.clock() < refocus_deadline then
|
|
579
669
|
-- the tap that selected an entry released the textbox, so take it back
|
|
@@ -631,6 +721,7 @@ local function app()
|
|
|
631
721
|
|
|
632
722
|
padding(px(8)),
|
|
633
723
|
flex():row():gap(1),
|
|
724
|
+
track_bounds,
|
|
634
725
|
|
|
635
726
|
{
|
|
636
727
|
Visible = function()
|
|
@@ -656,6 +747,7 @@ local function app()
|
|
|
656
747
|
},
|
|
657
748
|
flex():row():fill("horizontal"),
|
|
658
749
|
catch_hover(),
|
|
750
|
+
measured("console"),
|
|
659
751
|
|
|
660
752
|
header {
|
|
661
753
|
order = 1,
|
|
@@ -673,6 +765,10 @@ local function app()
|
|
|
673
765
|
history {
|
|
674
766
|
order = 3,
|
|
675
767
|
max_lines = max_history_lines,
|
|
768
|
+
-- the suggestions take priority, since they're what's being typed into
|
|
769
|
+
max_height = function()
|
|
770
|
+
return free_space() - (if has_popover() then popover_height() else 0)
|
|
771
|
+
end,
|
|
676
772
|
on_select = function(command)
|
|
677
773
|
cmd_history_index = 0
|
|
678
774
|
raw_text(command)
|
|
@@ -680,6 +776,8 @@ local function app()
|
|
|
680
776
|
-- after the textbox has recaptured focus, move the cursor to the end
|
|
681
777
|
task.defer(cursor_pos, #command + 1)
|
|
682
778
|
end,
|
|
779
|
+
|
|
780
|
+
measured("history"),
|
|
683
781
|
},
|
|
684
782
|
|
|
685
783
|
container {
|
|
@@ -713,10 +811,14 @@ local function app()
|
|
|
713
811
|
return pop() > 0.01
|
|
714
812
|
end,
|
|
715
813
|
},
|
|
814
|
+
measured("popover"),
|
|
716
815
|
|
|
717
816
|
suggestions {
|
|
718
817
|
analysis = display_analysis,
|
|
719
818
|
selected_suggestion = selected_suggestion,
|
|
819
|
+
max_height = function()
|
|
820
|
+
return free_space() - px.convert(4)
|
|
821
|
+
end,
|
|
720
822
|
on_select = function(suggestion: types.AnalysisSuggestion)
|
|
721
823
|
raw_text(autofill(raw_text(), suggestion, true))
|
|
722
824
|
if not gamepad() then
|
package/src/app/suggestions.luau
CHANGED
|
@@ -33,6 +33,8 @@ export type Suggestions = {
|
|
|
33
33
|
read analysis: () -> types.AnalysisResult,
|
|
34
34
|
read selected_suggestion: () -> number,
|
|
35
35
|
read on_select: (suggestion: types.AnalysisSuggestion) -> (),
|
|
36
|
+
-- the most room the popover can take up, in pixels, so it fits on screen
|
|
37
|
+
read max_height: (() -> number)?,
|
|
36
38
|
read order: number?,
|
|
37
39
|
|
|
38
40
|
[number]: unknown,
|
|
@@ -252,6 +254,19 @@ local function suggestions(props: Suggestions)
|
|
|
252
254
|
-- set by the list, which is also at the bottom when it's too short to scroll
|
|
253
255
|
local scrolled_to_bottom = source(true)
|
|
254
256
|
|
|
257
|
+
-- height of everything in the popover besides the list, which is what the
|
|
258
|
+
-- list has to leave room for when it's limited by max_height
|
|
259
|
+
local root: GuiObject? = nil
|
|
260
|
+
local list: GuiObject? = nil
|
|
261
|
+
local chrome_height = source(0)
|
|
262
|
+
|
|
263
|
+
local function measure()
|
|
264
|
+
if root and list then
|
|
265
|
+
-- read together so both sizes are from the same layout pass
|
|
266
|
+
chrome_height(root.AbsoluteSize.Y - list.AbsoluteSize.Y)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
255
270
|
return background {
|
|
256
271
|
auto = "XY",
|
|
257
272
|
order = props.order,
|
|
@@ -272,6 +287,10 @@ local function suggestions(props: Suggestions)
|
|
|
272
287
|
end,
|
|
273
288
|
},
|
|
274
289
|
flex():row():fill("horizontal"),
|
|
290
|
+
action(function(instance: Frame)
|
|
291
|
+
root = instance
|
|
292
|
+
cleanup(instance:GetPropertyChangedSignal("AbsoluteSize"):Connect(measure))
|
|
293
|
+
end),
|
|
275
294
|
|
|
276
295
|
-- why the input can't be run as it is
|
|
277
296
|
show(failed, function()
|
|
@@ -406,7 +425,15 @@ local function suggestions(props: Suggestions)
|
|
|
406
425
|
end
|
|
407
426
|
|
|
408
427
|
local function visible_height()
|
|
409
|
-
|
|
428
|
+
local height = math.min(content_height(), row_height() * state.visible_suggestions())
|
|
429
|
+
local row = row_height()
|
|
430
|
+
if props.max_height == nil or row == 0 then
|
|
431
|
+
return height
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
-- only whole rows, around the list's padding, but always at least one
|
|
435
|
+
local room = props.max_height() - chrome_height() - px.convert(6)
|
|
436
|
+
return math.min(height, math.max(math.floor(room / row), 1) * row)
|
|
410
437
|
end
|
|
411
438
|
|
|
412
439
|
effect(function()
|
|
@@ -480,6 +507,13 @@ local function suggestions(props: Suggestions)
|
|
|
480
507
|
changed("CanvasPosition", function(position: Vector2)
|
|
481
508
|
canvas_y(position.Y)
|
|
482
509
|
end),
|
|
510
|
+
action(function(instance: ScrollingFrame)
|
|
511
|
+
list = instance
|
|
512
|
+
cleanup(instance:GetPropertyChangedSignal("AbsoluteSize"):Connect(measure))
|
|
513
|
+
cleanup(function()
|
|
514
|
+
list = nil
|
|
515
|
+
end)
|
|
516
|
+
end),
|
|
483
517
|
|
|
484
518
|
padding(px(3)),
|
|
485
519
|
|
|
@@ -39,7 +39,7 @@ type TextBoxProps = {
|
|
|
39
39
|
read bind_open_keyboard: ((open: () -> ()) -> ())?,
|
|
40
40
|
|
|
41
41
|
read update_text: ((string) -> ())?,
|
|
42
|
-
read update_focused: ((boolean) -> ())?,
|
|
42
|
+
read update_focused: ((focused: boolean, enter: boolean) -> ())?,
|
|
43
43
|
read enter: (string) -> (),
|
|
44
44
|
|
|
45
45
|
[number]: unknown,
|
|
@@ -96,7 +96,7 @@ return function(props: TextBoxProps)
|
|
|
96
96
|
if not props.update_focused then
|
|
97
97
|
return
|
|
98
98
|
end
|
|
99
|
-
props.update_focused(true)
|
|
99
|
+
props.update_focused(true, false)
|
|
100
100
|
end,
|
|
101
101
|
|
|
102
102
|
FocusLost = function(enter)
|
|
@@ -104,7 +104,7 @@ return function(props: TextBoxProps)
|
|
|
104
104
|
return
|
|
105
105
|
end
|
|
106
106
|
if props.update_focused then
|
|
107
|
-
props.update_focused(false)
|
|
107
|
+
props.update_focused(false, enter)
|
|
108
108
|
end
|
|
109
109
|
if not enter then
|
|
110
110
|
return
|
package/src/init.luau
CHANGED
package/src/state.luau
CHANGED
|
@@ -10,7 +10,7 @@ return {
|
|
|
10
10
|
logs = source({} :: { types.Log }),
|
|
11
11
|
|
|
12
12
|
-- options
|
|
13
|
-
activation_keys = source({}),
|
|
13
|
+
activation_keys = source({ Enum.KeyCode.F2 }),
|
|
14
14
|
hide_on_lost_focus = source(true),
|
|
15
15
|
theme = source(theme.themes.mocha),
|
|
16
16
|
font = source(Font.fromId(16658246179)),
|