Prevent double-click to constrain length on unsupported lines (#5938)

* WIP: Prevent length constraint creation on endAbsolute lines
Fixes #5937

* Typo

Thanks @franknoirot

Co-authored-by: Frank Noirot <frank@zoo.dev>

* length constraint stuff from @lrev-Dev

* Clean up

* Lint

* Add regression test for double click after sketch constraint

---------

Co-authored-by: Frank Noirot <frank@zoo.dev>
Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
This commit is contained in:
Pierre Jacquier
2025-04-02 10:52:36 -04:00
committed by GitHub
parent d168ef94e9
commit 10c1f3a849
7 changed files with 116 additions and 65 deletions

View File

@ -2,6 +2,7 @@ import { DEV } from '@src/env'
import type { EventFrom, StateFrom } from 'xstate'
import type { CustomIconName } from '@src/components/CustomIcon'
import { createLiteral } from '@src/lang/create'
import { commandBarActor } from '@src/machines/commandBarMachine'
import type { modelingMachine } from '@src/machines/modelingMachine'
import {
@ -621,7 +622,22 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
[
{
id: 'constraint-length',
disabled: (state) => !state.matches({ Sketch: 'SketchIdle' }),
disabled: (state) =>
!(
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({
type: 'Constrain length',
data: {
selection: state.context.selectionRanges,
// dummy data is okay for checking if the constrain is possible
length: {
valueAst: createLiteral(1),
valueText: '1',
valueCalculated: '1',
},
},
})
),
onClick: () =>
commandBarActor.send({
type: 'Find and select command',