Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/2.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMazol committed Jun 9, 2022
2 parents c9c7c22 + 3da3805 commit 6ebb073
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
1 change: 1 addition & 0 deletions packages/ketcher-polymer-editor-react/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"private": true,
"name": "ketcher-polymer-editor-react",
"version": "1.0.0",
"description": "Web-based molecule sketcher",
Expand Down
65 changes: 16 additions & 49 deletions packages/ketcher-react/src/script/editor/tool/hand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
import { Vec2, Box2Abs, Scale } from 'ketcher-core'

import Editor from '../Editor'
import { Vec2 } from 'ketcher-core'

class HandTool {
editor: Editor
begPos: any
endPos: any
begPos: Vec2 | null = null
endPos: Vec2 | null = null

constructor(editor) {
this.editor = editor
Expand All @@ -34,65 +35,31 @@ class HandTool {
}

mousedown(event) {
this.begPos = this.editor.render.page2obj(event)
// this.editor.render.options.offset = new Vec2(-5, -5)
// this.editor.render.ctab.translate(new Vec2(-5, -5))
// this.editor.render.setScrollOffset(-5, -5)
const { clientX, clientY } = event
this.begPos = new Vec2(clientX, clientY)
}

mousemove(event) {
this.editor.event.cursor.dispatch({ status: 'move' })
if (this.begPos === null) return
if (this.begPos == null) return
const { clientX, clientY } = event
this.endPos = new Vec2(clientX, clientY)

const rnd = this.editor.render
if (!this.begPos) return
this.endPos = rnd.page2obj(event)
const diff = Vec2.diff(this.begPos, this.endPos)
const d = new Vec2(-diff.x, -diff.y)
rnd.ctab.translate(d)
rnd.options.offset = rnd.options.offset.add(d)
const viewSz = new Vec2(
rnd.clientArea.clientWidth || 100,
rnd.clientArea.clientHeight || 100
const diff = Vec2.diff(this.endPos, this.begPos).scaled(
1 / this.editor.zoom()
)
const sf = rnd.options.scale
const bb = rnd!
.ctab!.getVBoxObj({})!
.transform(Scale.obj2scaled, rnd.options)
.translate(rnd.options.offset || new Vec2())
if (!rnd.options.autoScale) {
const ext = Vec2.UNIT.scaled(sf)
const eb = bb.sz().length() > 0 ? bb.extend(ext, ext) : bb
const vb = new Box2Abs(
rnd.scrollPos(),
viewSz.scaled(1 / rnd.options.zoom).sub(Vec2.UNIT.scaled(20))
)
const cb = Box2Abs.union(vb, eb)
if (!rnd.oldCb) rnd.oldCb = new Box2Abs()
this.begPos = this.endPos

const sz = cb.sz().floor()
rnd.oldBb = bb
if (!rnd.sz || sz.x !== rnd.sz.x || sz.y !== rnd.sz.y) {
rnd.setPaperSize(sz)
const awidth = rnd.sz.x
const swidth = rnd.clientArea.scrollWidth
const dscroll = (diff.x * swidth) / awidth
rnd.clientArea.scrollLeft += dscroll
}
if (cb.p0.x !== 0 && cb.p0.y !== 0) {
rnd.ctab.translate(d)
rnd.options.offset = rnd.options.offset.add(d)
}
rnd.options.offset = rnd.options.offset || new Vec2()
}
rnd.ctab.translate(diff)
rnd.options.offset = rnd.options.offset.add(diff)
rnd.update(false)
}

mouseup(event) {
if (this.begPos === null) return
const rnd = this.editor.render
this.endPos = rnd.page2obj(event)
const diff = Vec2.diff(this.begPos, this.endPos)
// const d = new Vec2(-diff.x, -diff.y)
console.log(diff)
this.begPos = null
this.endPos = null
rnd.update(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ const sgroup = {
title: 'Repeat count',
type: 'integer',
default: 1,
minimum: 1,
maximum: 1000,
invalidMessage: 'Value out of range: must be between 1 and 1000'
minimum: 1
}
},
required: ['mul']
Expand Down

0 comments on commit 6ebb073

Please sign in to comment.