Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LEAP-1615: LEAP-456: Fix tool unselect #6630

Merged
merged 8 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions web/libs/editor/src/components/Toolbar/Toolbar.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useMemo, useState } from "react";
import { Block, Elem } from "../../utils/bem";
import "./Toolbar.scss";
import "./Tool.scss";
import "./FlyoutMenu.scss";
import { inject, observer } from "mobx-react";

import { useWindowSize } from "../../common/Utils/useWindowSize";
import { Block, cn, Elem } from "../../utils/bem";
import { isDefined } from "../../utils/utilities";
import { inject, observer } from "mobx-react";
import { ToolbarProvider } from "./ToolbarContext";
import { Tool } from "./Tool";
import { ToolbarProvider } from "./ToolbarContext";

import "./FlyoutMenu.scss";
import "./Tool.scss";
import "./Toolbar.scss";

export const Toolbar = inject("store")(
observer(({ store, tools, expanded }) => {
Expand Down Expand Up @@ -110,9 +112,12 @@ const SmartTools = observer(({ tools }) => {
) : null
}
controls={selected.controls}
onClick={() => {
onClick={(e) => {
let nextIndex = selectedIndex + 1;

// if that's a smart button in extra block, it's already selected
if (e.target.closest(`.${cn("tool").elem("extra")}`)) return;

if (!hasSelected) nextIndex = 0;
else if (nextIndex >= tools.length) nextIndex = 0;

Expand Down
4 changes: 2 additions & 2 deletions web/libs/editor/src/tools/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ class ToolsManager {

if (selected) {
this.unselectAll();
if (tool.setSelected) tool.setSelected(true);
tool.setSelected?.(true);
} else {
const drawingTool = this.findDrawingTool();

if (drawingTool) return this.selectTool(drawingTool, true);
if (tool.setSelected) tool.setSelected(false);
this.selectTool(this._default_tool, true);
}
}

Expand Down
36 changes: 24 additions & 12 deletions web/libs/editor/src/tools/Selection.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import { observer } from "mobx-react";
import { types } from "mobx-state-tree";

import BaseTool from "./Base";
import ToolMixin from "../mixins/Tool";
import { AnnotationMixin } from "../mixins/AnnotationMixin";
import { IconMoveTool } from "../assets/icons";
import { Tool } from "../components/Toolbar/Tool";
import { AnnotationMixin } from "../mixins/AnnotationMixin";
import ToolMixin from "../mixins/Tool";
import { FF_LSDV_4930, isFF } from "../utils/feature-flags";
import BaseTool from "./Base";

const ToolView = observer(({ item }) => {
return (
<Tool
ariaLabel="move"
active={item.selected}
icon={<IconMoveTool />}
label="Move"
shortcut={item.shortcut}
extraShortcuts={item.extraShortcuts}
onClick={() => {
item.manager.selectTool(item, !item.selected);
}}
/>
);
});

const _Tool = types
.model("SelectionTool", {
shortcut: "V",
group: "control",
})
.views(() => {
.views((self) => {
return {
get isSeparated() {
return true;
},
get viewTooltip() {
return "Move";
},
get iconComponent() {
return IconMoveTool;
get viewClass() {
return () => <ToolView item={self} />;
},
get useTransformer() {
return true;
Expand Down
Loading