Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Held brush size keys repeat on whatever keys they are bound to (incl. the Shift 1 px steps), and step an insert set; still not while typing (Ziel on Discord). ActionRegistry::actionForKey + brushSizeStep; test action_brush_size_keys_follow_rebinding

islandmed8c27a523b979
diff --git a/changes/fix-brush-size-repeat-rebound.md b/changes/fix-brush-size-repeat-rebound.md
new file mode 100644
index 00000000..d8344675
--- /dev/null
+++ b/changes/fix-brush-size-repeat-rebound.md
@@ -0,0 +1,9 @@
+---
+fixed: Holding a rebound Smaller brush / Larger brush key (and the 1 px Shift steps) repeats again, like [ and ]
+ always did; after a rebind it changed the size once and stopped. Those keys also step through an insert set.
+ Not while typing in a field (thanks Ziel on Discord).
+testers:
+ - Preferences > Input: bind Smaller brush to Q and Larger brush to E; hold each over the canvas: the size keeps
+ changing until let go. Shift with the 1 px steps' keys does the same.
+ - Default keys: hold [ and ] as before; type in a text field and hold Q: no brush size change.
+---
diff --git a/src/app/Actions.cpp b/src/app/Actions.cpp
index 7680247c..2aced0af 100644
--- a/src/app/Actions.cpp
+++ b/src/app/Actions.cpp
@@ -242,8 +242,8 @@ const Action* ActionRegistry::actionForChord(const Chord& chord) const {
return nullptr;
}
-bool ActionRegistry::handleKey(SDL_Keycode key, SDL_Keymod mods) {
- if (isModifierKey(key)) return false;
+const Action* ActionRegistry::actionForKey(SDL_Keycode key, SDL_Keymod mods) const {
+ if (isModifierKey(key)) return nullptr;
Chord chord = chordFromEvent(key, mods);
const Action* a = actionForChord(chord);
if (!a && !chord.ctrl && (chord.shift || chord.alt)) {
@@ -252,6 +252,18 @@ bool ActionRegistry::handleKey(SDL_Keycode key, SDL_Keymod mods) {
chord.shift = chord.alt = false;
a = actionForChord(chord);
}
+ return a;
+}
+
+int brushSizeStep(const Action* a) {
+ if (!a) return 0;
+ if (a->id == "brush.size_down" || a->id == "brush.size_down_fine") return -1;
+ if (a->id == "brush.size_up" || a->id == "brush.size_up_fine") return 1;
+ return 0;
+}
+
+bool ActionRegistry::handleKey(SDL_Keycode key, SDL_Keymod mods) {
+ const Action* a = actionForKey(key, mods);
if (!a || !a->run) return false;
if (a->enabled && !a->enabled()) return true; // bound, just not available right now
// Copy: running an action may register or replace actions.
diff --git a/src/app/Actions.h b/src/app/Actions.h
index 9ef0b404..3d442e8b 100644
--- a/src/app/Actions.h
+++ b/src/app/Actions.h
@@ -48,6 +48,10 @@ bool isModifierKey(SDL_Keycode key);
// The individual keys of a chord, for drawing keycaps: "Ctrl+Shift+Z" -> {"Ctrl", "Shift", "Z"}.
std::vector<std::string> chordKeys(std::string_view chord);
+// -1 for Smaller brush (and by 1 px), +1 for Larger brush (and by 1 px), 0 otherwise: these repeat while their
+// key is held, and step through an insert set, on whatever keys they are bound to.
+int brushSizeStep(const Action* a);
+
class ActionRegistry {
public:
void add(Action a); // replaces by id
@@ -76,6 +80,8 @@ public:
void clearOverrides();
// The action that CHORD runs (enabled or not), or nullptr.
const Action* actionForChord(const Chord& chord) const;
+ // The action a key press runs, as handleKey finds it (an unbound Shift or Alt chord falls back to the plain key).
+ const Action* actionForKey(SDL_Keycode key, SDL_Keymod mods) const;
// Every command becomes "cmd.<name>". Commands with required parameters are listed too: `prefill`
// is called for them (the console opens with the name typed), `run` for the others. Commands that
// another action already runs (Action::command) are skipped by the command palette, not here.
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 835c0fdf..042a2c02 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -1618,8 +1618,8 @@ void App::dispatchEvent(const SDL_Event& event) {
}
if (!io.WantCaptureKeyboard && !e.key.repeat) quickRemeshKey(e.key.key, e.key.mod, true); // held: drag remeshes
if (!io.WantCaptureKeyboard && !e.key.repeat) onKey(e.key.key, e.key.mod);
- else if (!io.WantCaptureKeyboard && (e.key.key == SDLK_LEFTBRACKET || e.key.key == SDLK_RIGHTBRACKET))
- onKey(e.key.key, e.key.mod);
+ else if (!io.WantCaptureKeyboard && brushSizeStep(actions_.actionForKey(e.key.key, e.key.mod)))
+ onKey(e.key.key, e.key.mod); // held brush size keys repeat, whatever they are bound to
break;
case SDL_EVENT_KEY_UP:
if (e.key.key == SDLK_SPACE) spaceHeld_ = false;
@@ -2131,9 +2131,9 @@ void App::onKey(SDL_Keycode key, SDL_Keymod mod) {
closeStrokePopup();
return;
}
- if ((key == SDLK_LEFTBRACKET || key == SDLK_RIGHTBRACKET) && !(mod & (SDL_KMOD_CTRL | SDL_KMOD_ALT | SDL_KMOD_GUI)) &&
- insertSetActive()) { // an insert set: [ and ] step through it (the drag sets the size, not the brush's)
- selectInsertSetItem(insertSet_.index + (key == SDLK_RIGHTBRACKET ? 1 : -1));
+ if (const int step = brushSizeStep(actions_.actionForKey(key, mod)); step && insertSetActive()) {
+ // an insert set: the brush size keys ([ and ]) step through it (the drag sets the size, not the brush's)
+ selectInsertSetItem(insertSet_.index + step);
return;
}
if (key == SDLK_ESCAPE && !insertType_.empty()) { // Append > Insert (#34) off
diff --git a/tests/test_actions.cpp b/tests/test_actions.cpp
index e097c235..3a0afd3f 100644
--- a/tests/test_actions.cpp
+++ b/tests/test_actions.cpp
@@ -84,6 +84,29 @@ TEST(action_registry_style_default_before_add) {
CHECK(reg.shortcutText("ui.size_popup") == "Ctrl+Alt+S");
}
+TEST(action_brush_size_keys_follow_rebinding) {
+ // Ziel on Discord: holding a rebound Smaller / Larger brush key repeats like [ and ] do (App.cpp asks
+ // brushSizeStep(actionForKey(...)) for key repeats, so this is what decides it).
+ ActionRegistry reg;
+ reg.add({"brush.size_down", "Smaller brush", nullptr, "", "Draw", "[", "", [] {}, nullptr, nullptr});
+ reg.add({"brush.size_up", "Larger brush", nullptr, "", "Draw", "]", "", [] {}, nullptr, nullptr});
+ reg.add({"brush.size_down_fine", "Smaller brush by 1 px", nullptr, "", "Draw", "Shift+[", "", [] {}, nullptr, nullptr});
+ reg.add({"brush.size_up_fine", "Larger brush by 1 px", nullptr, "", "Draw", "Shift+]", "", [] {}, nullptr, nullptr});
+ reg.add({"view.wireframe", "Wireframe", nullptr, "", "Render", "W", "", [] {}, nullptr, nullptr});
+ const auto step = [&](SDL_Keycode k, SDL_Keymod m = SDL_KMOD_NONE) { return brushSizeStep(reg.actionForKey(k, m)); };
+ CHECK(step(SDLK_LEFTBRACKET) == -1 && step(SDLK_RIGHTBRACKET) == 1);
+ CHECK(step(SDLK_LEFTBRACKET, SDL_KMOD_LSHIFT) == -1 && step(SDLK_W) == 0 && step(SDLK_Q) == 0);
+ reg.setShortcut("brush.size_down", "Q");
+ reg.setShortcut("brush.size_up", "E");
+ reg.setShortcut("brush.size_down_fine", "Shift+A");
+ reg.setShortcut("brush.size_up_fine", "Alt+D");
+ CHECK(step(SDLK_Q) == -1 && step(SDLK_E) == 1);
+ CHECK(step(SDLK_A, SDL_KMOD_LSHIFT) == -1 && step(SDLK_D, SDL_KMOD_LALT) == 1);
+ CHECK(step(SDLK_LEFTBRACKET) == 0 && step(SDLK_RIGHTBRACKET) == 0); // the old keys no longer repeat
+ CHECK(step(SDLK_W) == 0 && step(SDLK_LSHIFT, SDL_KMOD_LSHIFT) == 0);
+ CHECK(brushSizeStep(nullptr) == 0);
+}
+
TEST(action_registry_commands) {
CommandRegistry commands;
ActionRegistry reg;