mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
Fix some bugs
This commit is contained in:
parent
240282f9d2
commit
f9aabe1beb
3 changed files with 31 additions and 27 deletions
|
@ -263,15 +263,17 @@ const mapStateToProps = state => ({
|
|||
});
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
onKeyPress: event => {
|
||||
// if (event.key === 'e') {
|
||||
// dispatch(changeMode(Modes.ERASER));
|
||||
// } else if (event.key === 'b') {
|
||||
// dispatch(changeMode(Modes.BRUSH));
|
||||
// } else if (event.key === 'l') {
|
||||
// dispatch(changeMode(Modes.LINE));
|
||||
// } else if (event.key === 's') {
|
||||
// dispatch(changeMode(Modes.SELECT));
|
||||
// }
|
||||
// TODO if text tool not in text edit mode
|
||||
// TODO unfocus other text input fields
|
||||
if (event.key === 'e') {
|
||||
dispatch(changeMode(Modes.ERASER));
|
||||
} else if (event.key === 'b') {
|
||||
dispatch(changeMode(Modes.BRUSH));
|
||||
} else if (event.key === 'l') {
|
||||
dispatch(changeMode(Modes.LINE));
|
||||
} else if (event.key === 's') {
|
||||
dispatch(changeMode(Modes.SELECT));
|
||||
}
|
||||
},
|
||||
clearSelectedItems: () => {
|
||||
dispatch(clearSelectedItems());
|
||||
|
|
|
@ -30,8 +30,12 @@ const hoverItem = function (item) {
|
|||
return clone;
|
||||
};
|
||||
|
||||
const hoverBounds = function (item) {
|
||||
const rect = new paper.Path.Rectangle(item.internalBounds);
|
||||
const hoverBounds = function (item, expandBy) {
|
||||
let bounds = item.internalBounds;
|
||||
if (expandBy) {
|
||||
bounds = bounds.expand(expandBy);
|
||||
}
|
||||
const rect = new paper.Path.Rectangle(bounds);
|
||||
rect.matrix = item.matrix;
|
||||
setDefaultGuideStyle(rect);
|
||||
rect.parent = getGuideLayer();
|
||||
|
|
|
@ -5,7 +5,6 @@ import {clearSelection} from '../selection';
|
|||
import BoundingBoxTool from '../selection-tools/bounding-box-tool';
|
||||
import NudgeTool from '../selection-tools/nudge-tool';
|
||||
import {hoverBounds} from '../guides';
|
||||
import {expandBy} from '../math';
|
||||
|
||||
/**
|
||||
* Tool for adding text. Text elements have limited editability; they can't be reshaped,
|
||||
|
@ -130,7 +129,8 @@ class TextTool extends paper.Tool {
|
|||
clearSelection(this.clearSelectedItems);
|
||||
this.textBox = doubleClickHitTest.item;
|
||||
this.mode = TextTool.TEXT_EDIT_MODE;
|
||||
} else if (this.boundingBoxTool.onMouseDown(
|
||||
} else if (
|
||||
this.boundingBoxTool.onMouseDown(
|
||||
event, false /* clone */, false /* multiselect */, this.getBoundingBoxHitOptions())) {
|
||||
// In select mode staying in select mode
|
||||
this.mode = TextTool.SELECT_MODE;
|
||||
|
@ -147,16 +147,20 @@ class TextTool extends paper.Tool {
|
|||
this.mode = TextTool.TEXT_EDIT_MODE;
|
||||
} else if (this.mode === TextTool.TEXT_EDIT_MODE) {
|
||||
// In text mode clicking away to begin select mode
|
||||
if (this.textBox) {
|
||||
this.mode = TextTool.SELECT_MODE;
|
||||
this.textBox.selected = true;
|
||||
this.setSelectedItems();
|
||||
} else {
|
||||
this.mode = null;
|
||||
}
|
||||
} else {
|
||||
// In no mode or select mode clicking away to begin text edit mode
|
||||
this.mode = TextTool.TEXT_EDIT_MODE;
|
||||
clearSelection(this.clearSelectedItems);
|
||||
this.textBox = new paper.PointText({
|
||||
point: event.point,
|
||||
content: 'لوحة المفاتKeyboardيح العربية',
|
||||
content: '',
|
||||
font: 'Times',
|
||||
fontSize: 30
|
||||
});
|
||||
|
@ -165,8 +169,7 @@ class TextTool extends paper.Tool {
|
|||
}
|
||||
|
||||
if (this.mode === TextTool.TEXT_EDIT_MODE) {
|
||||
this.guide = hoverBounds(this.textBox);
|
||||
expandBy(this.guide, TextTool.TEXT_PADDING);
|
||||
this.guide = hoverBounds(this.textBox, TextTool.TEXT_PADDING);
|
||||
this.guide.dashArray = [4, 4];
|
||||
} else if (this.guide) {
|
||||
this.guide.remove();
|
||||
|
@ -180,9 +183,6 @@ class TextTool extends paper.Tool {
|
|||
this.boundingBoxTool.onMouseDrag(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO selection
|
||||
|
||||
}
|
||||
handleMouseUp (event) {
|
||||
if (event.event.button > 0 || !this.active) return; // only first mouse button
|
||||
|
@ -193,7 +193,6 @@ class TextTool extends paper.Tool {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
this.active = false;
|
||||
}
|
||||
handleKeyUp (event) {
|
||||
|
@ -210,11 +209,10 @@ class TextTool extends paper.Tool {
|
|||
} else if (!(event.modifiers.alt || event.modifiers.comand || event.modifiers.control ||
|
||||
event.modifiers.meta || event.modifiers.option)) {
|
||||
this.textBox.content = this.textBox.content + event.character;
|
||||
if (this.guide) this.guide.remove();
|
||||
this.guide = hoverBounds(this.textBox);
|
||||
expandBy(this.guide, TextTool.TEXT_PADDING);
|
||||
this.guide.dashArray = [4, 4];
|
||||
}
|
||||
if (this.guide) this.guide.remove();
|
||||
this.guide = hoverBounds(this.textBox, TextTool.TEXT_PADDING);
|
||||
this.guide.dashArray = [4, 4];
|
||||
}
|
||||
}
|
||||
deactivateTool () {
|
||||
|
|
Loading…
Reference in a new issue