Skip to content

Commit 4c2322c

Browse files
feat: onkeydown for text edit and cancel event
1 parent a0ade96 commit 4c2322c

9 files changed

Lines changed: 49 additions & 9 deletions

File tree

deps/breeze-ui.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package("breeze-glfw")
33
set_urls("https://github.com/breeze-shell/glfw.git")
44
add_versions("2026.03.07+1", "a79c32a7d9ef4cd8a15b5f8ccbcdf9510c48da03")
55

6-
local BREEZE_UI_VER = "2026.03.29+1"
7-
local BREEZE_UI_HASH = "9ced7b5735ad6cd18eb49d5cfebf88ea8bc9dab2"
6+
local BREEZE_UI_VER = "2026.03.29+2"
7+
local BREEZE_UI_HASH = "a6d34e86d37579e1aa722c640dcef485069ba1cd"
88
local USE_LOCAL_BREEZE_UI = os.getenv("CI") ~= "true"
99
local BREEZE_UI_LOCAL_PATH = "../breeze-ui"
1010

src/shell/script/binding_qjs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ template<> struct js_bind<mb_shell::js::breeze_ui::js_textbox_widget> {
127127
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_on_change, &mb_shell::js::breeze_ui::js_textbox_widget::set_on_change>("on_change")
128128
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_on_focus, &mb_shell::js::breeze_ui::js_textbox_widget::set_on_focus>("on_focus")
129129
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_on_blur, &mb_shell::js::breeze_ui::js_textbox_widget::set_on_blur>("on_blur")
130+
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_on_key_down, &mb_shell::js::breeze_ui::js_textbox_widget::set_on_key_down>("on_key_down")
130131
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_selection_start>("selection_start")
131132
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_selection_end>("selection_end")
132133
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::get_text>("get_text")
@@ -183,6 +184,8 @@ template<> struct js_bind<mb_shell::js::breeze_ui::js_textbox_widget> {
183184
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::set_on_focus>("set_on_focus")
184185
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::get_on_blur>("get_on_blur")
185186
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::set_on_blur>("set_on_blur")
187+
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::get_on_key_down>("get_on_key_down")
188+
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::set_on_key_down>("set_on_key_down")
186189
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::focus>("focus")
187190
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::blur>("blur")
188191
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::select_all>("select_all")

src/shell/script/binding_types.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export class js_textbox_widget extends js_widget {
121121
set on_focus(value: (() => void));
122122
get on_blur(): (() => void);
123123
set on_blur(value: (() => void));
124+
get on_key_down(): ((arg1: number, arg2: boolean, arg3: boolean, arg4: boolean, arg5: boolean) => boolean);
125+
set on_key_down(value: ((arg1: number, arg2: boolean, arg3: boolean, arg4: boolean, arg5: boolean) => boolean));
124126
get selection_start(): number;
125127
get selection_end(): number;
126128
focus(): void
@@ -1396,4 +1398,4 @@ declare module "mshell" {
13961398
type intptr_t = number;
13971399
type uintptr_t = number;
13981400
type ssize_t = number;
1399-
}
1401+
}

src/shell/script/binding_types_breeze_ui.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ IMPL_CALLBACK_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, on_focus,
171171
std::function<void()>)
172172
IMPL_CALLBACK_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, on_blur,
173173
std::function<void()>)
174+
IMPL_CALLBACK_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget,
175+
on_key_down,
176+
std::function<bool(int, bool, bool, bool, bool)>)
174177

175178
void breeze_ui::js_widget::append_child_after(std::shared_ptr<js_widget> child,
176179
int after_index) {

src/shell/script/binding_types_breeze_ui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ struct breeze_ui {
108108
DEFINE_PROP(std::function<void(std::string)>, on_change)
109109
DEFINE_PROP(std::function<void()>, on_focus)
110110
DEFINE_PROP(std::function<void()>, on_blur)
111+
DEFINE_PROP(std::function<bool(int, bool, bool, bool, bool)>,
112+
on_key_down)
111113

112114
void focus();
113115
void blur();

src/shell/script/script.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/shell/script/ts/src/config_page/pages/TestPage.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,37 @@ import { Button, Text } from "../components";
33
import { useTranslation } from "../hooks";
44
import { memo, useState } from "react";
55

6+
const GLFW_KEY_ENTER = 257;
7+
68
const TestPage = memo(() => {
79
const { t } = useTranslation();
810
const [singleLineValue, setSingleLineValue] = useState("你尴尬Say个Hi 没位坐下来");
911
const [multiLineValue, setMultiLineValue] = useState(
1012
"你的影子被日落拉长\n思念在很远的地方\n喔喔喔喔 轻轻的唱年少的轻狂\nAabcd1234567890!@#$%^&*()_+"
1113
);
1214
const [focusState, setFocusState] = useState("none");
15+
const [singleLineSubmitValue, setSingleLineSubmitValue] = useState("");
16+
const [multiLineSubmitValue, setMultiLineSubmitValue] = useState("");
17+
18+
const handleSingleLineKeyDown = (key: number) => {
19+
if (key !== GLFW_KEY_ENTER) {
20+
return false;
21+
}
22+
setSingleLineSubmitValue(singleLineValue);
23+
return true;
24+
};
25+
26+
const handleMultiLineKeyDown = (
27+
key: number,
28+
_shiftKey: boolean,
29+
ctrlKey: boolean,
30+
) => {
31+
if (key !== GLFW_KEY_ENTER || !ctrlKey) {
32+
return false;
33+
}
34+
setMultiLineSubmitValue(multiLineValue);
35+
return true;
36+
};
1337

1438
return (
1539
<flex maxHeight={500} enableScrolling>
@@ -40,6 +64,7 @@ const TestPage = memo(() => {
4064
height={34}
4165
fontSize={14}
4266
onChange={setSingleLineValue}
67+
onKeyDown={handleSingleLineKeyDown}
4368
onFocus={() => setFocusState("single")}
4469
onBlur={() => setFocusState("none")}
4570
/>
@@ -54,11 +79,14 @@ const TestPage = memo(() => {
5479
caretColor="#ff00ff"
5580
multiline
5681
onChange={setMultiLineValue}
82+
onKeyDown={handleMultiLineKeyDown}
5783
onFocus={() => setFocusState("multi")}
5884
onBlur={() => setFocusState("none")}
5985
/>
6086
<Text fontSize={13} fontWeight={900}>Focused: {focusState}</Text>
6187
<Text fontSize={13}>Single line value: {singleLineValue}</Text>
88+
<Text fontSize={13}>Single enter submit: {singleLineSubmitValue || "(empty)"}</Text>
89+
<Text fontSize={13}>Multi Ctrl+Enter submit: {multiLineSubmitValue || "(empty)"}</Text>
6290
</flex>
6391

6492
<flex>

src/shell/script/ts/src/jsx.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ declare module 'react' {
8484
onChange?: (value: string) => void;
8585
onFocus?: () => void;
8686
onBlur?: () => void;
87+
onKeyDown?: (key: number, shiftKey: boolean, ctrlKey: boolean, altKey: boolean, metaKey: boolean) => boolean;
8788
key?: string | number;
8889
animatedVars?: string[];
8990
x?: number;

src/shell/script/ts/src/react/renderer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ const componentMap = {
186186
onChange: getSetFactory('on_change'),
187187
onFocus: getSetFactory('on_focus'),
188188
onBlur: getSetFactory('on_blur'),
189+
onKeyDown: getSetFactory('on_key_down'),
189190
...commonProps
190191
}
191192
},

0 commit comments

Comments
 (0)