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

Backmerge: #5581 - fixed view only toggle fragment issue and multitail arrows undo\redo not saving coordinates #5736

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
import { BaseOperation } from 'application/editor/operations/base';
import { OperationType } from 'application/editor';
import { ReStruct } from 'application/render';
import { FixedPrecisionCoordinates } from 'domain/entities';

export class MultitailArrowAddTail extends BaseOperation {
constructor(private itemId: number, private tailId?: number) {
constructor(
private itemId: number,
private tailId?: number,
private coordinate?: FixedPrecisionCoordinates,
) {
super(OperationType.MULTITAIL_ARROW_ADD_TAIL);
}

Expand All @@ -15,8 +20,7 @@ export class MultitailArrowAddTail extends BaseOperation {
if (!reMultitailArrow || !multitailArrow) {
return;
}

this.tailId = multitailArrow.addTail(this.tailId);
this.tailId = multitailArrow.addTail(this.tailId, this.coordinate);
BaseOperation.invalidateItem(reStruct, 'multitailArrows', this.itemId, 1);
}

Expand All @@ -26,15 +30,17 @@ export class MultitailArrowAddTail extends BaseOperation {
}

export class MultitailArrowRemoveTail extends BaseOperation {
private coordinate?: FixedPrecisionCoordinates;
constructor(private itemId: number, private tailId: number) {
super(OperationType.MULTITAIL_ARROW_REMOVE_TAIL);
}

execute(reStruct: ReStruct) {
const reMultitailArrow = reStruct.multitailArrows.get(this.itemId);
const multitailArrow = reStruct.molecule.multitailArrows.get(this.itemId);
this.coordinate = multitailArrow?.getTailCoordinate(this.tailId);

if (!reMultitailArrow || !multitailArrow) {
if (!reMultitailArrow || !multitailArrow || !this.coordinate) {
return;
}

Expand All @@ -43,6 +49,6 @@ export class MultitailArrowRemoveTail extends BaseOperation {
}

invert(): BaseOperation {
return new MultitailArrowAddTail(this.itemId, this.tailId);
return new MultitailArrowAddTail(this.itemId, this.tailId, this.coordinate);
}
}
1 change: 1 addition & 0 deletions packages/ketcher-core/src/domain/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
export * from './atom';
export * from './atomList';
export * from './bond';
export * from './fixedPrecision';
export * from './fragment';
export * from './functionalGroup';
export * from './halfBond';
Expand Down
13 changes: 11 additions & 2 deletions packages/ketcher-core/src/domain/entities/multitailArrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Vec2 } from 'domain/entities/vec2';
import { Pool } from 'domain/entities/pool';
import { getNodeWithInvertedYCoord, KetFileNode } from 'domain/serializers';
import { MULTITAIL_ARROW_SERIALIZE_KEY } from 'domain/constants';
import { FixedPrecisionCoordinates } from 'domain/entities/fixedPrecision';
import { FixedPrecisionCoordinates } from 'domain/entities';

export type Line = [Vec2, Vec2];

Expand Down Expand Up @@ -365,7 +365,16 @@ export class MultitailArrow extends BaseMicromoleculeEntity {
);
}

addTail(id?: number): number {
getTailCoordinate(id: number): FixedPrecisionCoordinates | undefined {
return this.tailsYOffset.get(id);
}

addTail(id?: number, coordinate?: FixedPrecisionCoordinates): number {
// Coordinate can only be present for undo\redo
if (typeof id === 'number' && coordinate) {
this.tailsYOffset.set(id, coordinate);
return id;
}
const { center, distance } = this.getTailsMaxDistance();
if (!MultitailArrow.canAddTail(distance)) {
throw new Error('Cannot add tail because no minimal distance found');
Expand Down
2 changes: 1 addition & 1 deletion packages/ketcher-react/src/script/ui/state/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function initEditor(dispatch, getState) {
// eslint-disable-line no-shadow
const state = global.currentState;
const activeTool = state.actionState.activeTool.tool;
if (activeTool === 'select') return;
if (activeTool === 'select' && !force) return;
const selectMode = state.toolbar.visibleTools.select;
const resetOption = state.options.settings.resetToSelect;
if (resetOption === true || resetOption === activeTool || force === true)
Expand Down
Loading