mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -05:00
Merge pull request #325 from fsih/unfocusText
Unfocus text fields when canvas clicked and don't take keystrokes in canvas when text fields are focused
This commit is contained in:
commit
724fe85645
2 changed files with 17 additions and 8 deletions
|
@ -50,6 +50,10 @@ class PaintEditor extends React.Component {
|
|||
}
|
||||
componentDidMount () {
|
||||
document.addEventListener('keydown', this.props.onKeyPress);
|
||||
// document listeners used to detect if a mouse is down outside of the
|
||||
// canvas, and should therefore stop the eye dropper
|
||||
document.addEventListener('mousedown', this.onMouseDown);
|
||||
document.addEventListener('touchstart', this.onMouseDown);
|
||||
}
|
||||
componentDidUpdate (prevProps) {
|
||||
if (this.props.isEyeDropping && !prevProps.isEyeDropping) {
|
||||
|
@ -61,6 +65,8 @@ class PaintEditor extends React.Component {
|
|||
componentWillUnmount () {
|
||||
document.removeEventListener('keydown', this.props.onKeyPress);
|
||||
this.stopEyeDroppingLoop();
|
||||
document.removeEventListener('mousedown', this.onMouseDown);
|
||||
document.removeEventListener('touchstart', this.onMouseDown);
|
||||
}
|
||||
handleUpdateSvg (skipSnapshot) {
|
||||
// Store the zoom/pan and restore it after snapshotting
|
||||
|
@ -134,7 +140,12 @@ class PaintEditor extends React.Component {
|
|||
this.setState({canvas: canvas});
|
||||
this.canvas = canvas;
|
||||
}
|
||||
onMouseDown () {
|
||||
onMouseDown (event) {
|
||||
if (event.target === paper.view.element &&
|
||||
document.activeElement instanceof HTMLInputElement) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
if (this.props.isEyeDropping) {
|
||||
const colorString = this.eyeDropper.colorString;
|
||||
const callback = this.props.changeColorToEyeDropper;
|
||||
|
@ -164,11 +175,6 @@ class PaintEditor extends React.Component {
|
|||
this.eyeDropper.pickX = -1;
|
||||
this.eyeDropper.pickY = -1;
|
||||
this.eyeDropper.activate();
|
||||
|
||||
// document listeners used to detect if a mouse is down outside of the
|
||||
// canvas, and should therefore stop the eye dropper
|
||||
document.addEventListener('mousedown', this.onMouseDown);
|
||||
document.addEventListener('touchstart', this.onMouseDown);
|
||||
|
||||
this.intervalId = setInterval(() => {
|
||||
const colorInfo = this.eyeDropper.getColorInfo(
|
||||
|
@ -190,8 +196,6 @@ class PaintEditor extends React.Component {
|
|||
}
|
||||
stopEyeDroppingLoop () {
|
||||
clearInterval(this.intervalId);
|
||||
document.removeEventListener('mousedown', this.onMouseDown);
|
||||
document.removeEventListener('touchstart', this.onMouseDown);
|
||||
}
|
||||
render () {
|
||||
return (
|
||||
|
|
|
@ -232,6 +232,11 @@ class ReshapeTool extends paper.Tool {
|
|||
this.active = false;
|
||||
}
|
||||
handleKeyDown (event) {
|
||||
if (event.event.target instanceof HTMLInputElement) {
|
||||
// Ignore nudge if a text input field is focused
|
||||
return;
|
||||
}
|
||||
|
||||
const nudgeAmount = 1 / paper.view.zoom;
|
||||
const selected = getSelectedLeafItems();
|
||||
if (selected.length === 0) return;
|
||||
|
|
Loading…
Reference in a new issue