Skip to content

Commit

Permalink
#2060: Don't break the selection if the user's cursor goes beyond the…
Browse files Browse the repository at this point in the history
… canvas (#2071)

* #2060 — Don't break the selection if the user's cursor goes beyond the canvas

* #2060 - fix redundant actions on mouse events when not over canvas

Co-authored-by: Stanislav Permiakov <[email protected]>
  • Loading branch information
St-Permiakov and Stanislav Permiakov authored Jan 10, 2023
1 parent 00fd694 commit 248f71d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
27 changes: 16 additions & 11 deletions packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ function isMouseRight(event) {
}

function resetSelectionOnCanvasClick(editor: Editor, eventName: string) {
if (eventName === 'mouseup') {
if (eventName === 'mouseup' && editor.selection()) {
editor.selection(null)
}
}
Expand All @@ -616,17 +616,18 @@ function updateLastCursorPosition(editor: Editor, event) {
function domEventSetup(editor: Editor, clientArea) {
// TODO: addEventListener('resize', ...);
;[
'click',
'dblclick',
'mousedown',
'mousemove',
'mouseup',
'mouseleave',
'mouseover'
].forEach((eventName) => {
{ target: clientArea, eventName: 'click' },
{ target: clientArea, eventName: 'dblclick' },
{ target: clientArea, eventName: 'mousedown' },
{ target: document, eventName: 'mousemove' },
{ target: document, eventName: 'mouseup' },
{ target: document, eventName: 'mouseleave' },
{ target: clientArea, eventName: 'mouseover' }
].forEach(({ target, eventName }) => {
editor.event[eventName] = new DOMSubscription()
const subs = editor.event[eventName]
clientArea.addEventListener(eventName, subs.dispatch.bind(subs))

target.addEventListener(eventName, subs.dispatch.bind(subs))

subs.add((event) => {
updateLastCursorPosition(editor, event)
Expand All @@ -644,7 +645,11 @@ function domEventSetup(editor: Editor, clientArea) {
}
const EditorTool = editor.tool()
editor.lastEvent = event
if (EditorTool && eventName in EditorTool) {
if (
EditorTool &&
eventName in EditorTool &&
clientArea.contains(event.target)
) {
EditorTool[eventName](event)
return true
}
Expand Down
6 changes: 5 additions & 1 deletion packages/ketcher-react/src/script/editor/tool/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ class SelectTool {
// TODO it catches more events than needed, to be re-factored
this.selectElementsOnCanvas(newSelected, editor, event)
} else if (this.#lassoHelper.fragment) {
if (!event.shiftKey) editor.selection(null)
if (
!event.shiftKey &&
this.editor.render.clientArea.contains(event.target)
)
editor.selection(null)
}
editor.event.message.dispatch({
info: false
Expand Down

0 comments on commit 248f71d

Please sign in to comment.