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: #1934 hot key hot key 1 turns sulfur into carbon when cursor over the atom (#2010) #2014

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
7 changes: 7 additions & 0 deletions packages/ketcher-core/src/application/actions/action.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
* limitations under the License.
***************************************************************************/

// import { Operation } from "application/operations"
// import { ReStruct } from "application/render"

export interface Action {
perform: () => void
// operations: Array<Operation>
// mergeWith(action: Action): Action
// addOp(operation: Operation, restruct?: ReStruct): Operation
// isDummy(restruct?: ReStruct): boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ export interface Editor {
setOptions: (opts: string) => any
zoom: (value?: any) => any
structSelected: () => Struct
// update: (action: Action | true, ignoreHistory?: boolean) => void
}
1 change: 1 addition & 0 deletions packages/ketcher-core/src/application/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './rxnPlus'
export * from './sgroup'
export * from './simpleObject'
export * from './text'
export * from './baseOperation'
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
***************************************************************************/

import { ReStruct } from 'application/render'
import { Struct } from 'domain/entities'

export type OperationType =
Expand Down Expand Up @@ -70,8 +71,13 @@ export type OperationType =
export interface Operation {
readonly type: OperationType
readonly priority: number
readonly _inverted: OperationType | undefined
data: any
// eslint-disable-next-line no-use-before-define
perform: (struct: Struct) => PerformOperationResult
invert(): Operation
isDummy(_restruct: ReStruct): boolean
execute(_restruct: ReStruct): void
}

export type PerformOperationResult = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class Editor implements KetcherEditor {
}
}

update(action: Action | true, ignoreHistory?) {
update(action: Action | true, ignoreHistory?: boolean) {
if (action === true) {
this.render.update(true) // force
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/ketcher-react/src/script/editor/tool/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {

import LassoHelper from './helper/lasso'
import { atomLongtapEvent } from './atom'
import { sgroupDialog } from './sgroup'
import SGroupTool from './sgroup'
import utils from '../shared/utils'
import { xor } from 'lodash/fp'
import { Editor } from '../Editor'
Expand Down Expand Up @@ -536,7 +536,7 @@ class SelectTool {
ci.map === 'sgroupData'
) {
editor.selection(closestToSel(ci))
sgroupDialog(editor, ci.id, null)
SGroupTool.sgroupDialog(editor, ci.id, null)
} else if (ci.map === 'texts') {
editor.selection(closestToSel(ci))
const text = molecule.texts.get(ci.id)
Expand Down
122 changes: 61 additions & 61 deletions packages/ketcher-react/src/script/editor/tool/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class SGroupTool {
return
}

sgroupDialog(this.editor, id !== undefined ? id : null, this.type)
SGroupTool.sgroupDialog(this.editor, id ?? null, this.type)
this.isNotActiveTool = true
}
}
Expand Down Expand Up @@ -443,7 +443,7 @@ class SGroupTool {

// TODO: handle click on an existing group?
if (id !== null || (selection && selection.atoms))
sgroupDialog(this.editor, id, this.type)
SGroupTool.sgroupDialog(this.editor, id, this.type)
}

cancel() {
Expand All @@ -452,75 +452,75 @@ class SGroupTool {
}
this.editor.selection(null)
}
}

export function sgroupDialog(editor, id, defaultType) {
const restruct = editor.render.ctab
const struct = restruct.molecule
const selection = editor.selection() || {}
const sg = id !== null ? struct.sgroups.get(id) : null
const type = sg ? sg.type : defaultType
const eventName = type === 'DAT' ? 'sdataEdit' : 'sgroupEdit'

if (!selection.atoms && !selection.bonds && !sg) {
console.info('There is no selection or sgroup')
return
}
static sgroupDialog(editor, id, defaultType) {
const restruct = editor.render.ctab
const struct = restruct.molecule
const selection = editor.selection() || {}
const sg = id !== null ? struct.sgroups.get(id) : null
const type = sg ? sg.type : defaultType
const eventName = type === 'DAT' ? 'sdataEdit' : 'sgroupEdit'

let attrs
if (sg) {
attrs = sg.getAttrs()
if (!attrs.context) attrs.context = getContextBySgroup(restruct, sg.atoms)
} else {
attrs = {
context: getContextBySelection(restruct, selection)
if (!selection.atoms && !selection.bonds && !sg) {
console.info('There is no selection or sgroup')
return
}
}

const res = editor.event[eventName].dispatch({
type,
attrs
})
let attrs
if (sg) {
attrs = sg.getAttrs()
if (!attrs.context) attrs.context = getContextBySgroup(restruct, sg.atoms)
} else {
attrs = {
context: getContextBySelection(restruct, selection)
}
}

Promise.resolve(res)
.then((newSg) => {
// TODO: check before signal
if (
newSg.type !== 'DAT' && // when data s-group separates
checkOverlapping(struct, selection.atoms || [])
) {
editor.event.message.dispatch({
error: 'Partial S-group overlapping is not allowed.'
})
} else {
const res = editor.event[eventName].dispatch({
type,
attrs
})

Promise.resolve(res)
.then((newSg) => {
// TODO: check before signal
if (
!sg &&
newSg.type !== 'DAT' &&
(!selection.atoms || selection.atoms.length === 0)
)
return
newSg.type !== 'DAT' && // when data s-group separates
checkOverlapping(struct, selection.atoms || [])
) {
editor.event.message.dispatch({
error: 'Partial S-group overlapping is not allowed.'
})
} else {
if (
!sg &&
newSg.type !== 'DAT' &&
(!selection.atoms || selection.atoms.length === 0)
)
return

const isDataSg = sg && sg.getAttrs().context === newSg.attrs.context
const isDataSg = sg && sg.getAttrs().context === newSg.attrs.context

if (isDataSg) {
const action = fromSeveralSgroupAddition(
restruct,
newSg.type,
sg.atoms,
newSg.attrs
).mergeWith(fromSgroupDeletion(restruct, id))
if (isDataSg) {
const action = fromSeveralSgroupAddition(
restruct,
newSg.type,
sg.atoms,
newSg.attrs
).mergeWith(fromSgroupDeletion(restruct, id))

editor.update(action)
editor.selection(selection)
return
}
editor.update(action)
editor.selection(selection)
return
}

const result = fromContextType(id, editor, newSg, selection)
editor.update(result.action)
editor.selection(null)
}
})
.catch(() => null)
const result = fromContextType(id, editor, newSg, selection)
editor.update(result.action)
editor.selection(null)
}
})
.catch(() => null)
}
}

function getContextBySgroup(restruct, sgAtoms) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ketcher-react/src/script/ui/action/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { toBondType } from '../data/convert/structconv'
const toolActions = {
hand: {
title: 'Hand tool',
shortcut: 'Mod+h',
shortcut: 'Mod+Alt+h',
action: { tool: 'hand' },
hidden: (options) => isHidden(options, 'hand')
},
Expand Down
Loading