Fix some bugs

This commit is contained in:
DD 2018-03-14 16:47:07 -04:00
parent 240282f9d2
commit f9aabe1beb
3 changed files with 31 additions and 27 deletions

View file

@ -263,15 +263,17 @@ const mapStateToProps = state => ({
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
onKeyPress: event => { onKeyPress: event => {
// if (event.key === 'e') { // TODO if text tool not in text edit mode
// dispatch(changeMode(Modes.ERASER)); // TODO unfocus other text input fields
// } else if (event.key === 'b') { if (event.key === 'e') {
// dispatch(changeMode(Modes.BRUSH)); dispatch(changeMode(Modes.ERASER));
// } else if (event.key === 'l') { } else if (event.key === 'b') {
// dispatch(changeMode(Modes.LINE)); dispatch(changeMode(Modes.BRUSH));
// } else if (event.key === 's') { } else if (event.key === 'l') {
// dispatch(changeMode(Modes.SELECT)); dispatch(changeMode(Modes.LINE));
// } } else if (event.key === 's') {
dispatch(changeMode(Modes.SELECT));
}
}, },
clearSelectedItems: () => { clearSelectedItems: () => {
dispatch(clearSelectedItems()); dispatch(clearSelectedItems());

View file

@ -30,8 +30,12 @@ const hoverItem = function (item) {
return clone; return clone;
}; };
const hoverBounds = function (item) { const hoverBounds = function (item, expandBy) {
const rect = new paper.Path.Rectangle(item.internalBounds); let bounds = item.internalBounds;
if (expandBy) {
bounds = bounds.expand(expandBy);
}
const rect = new paper.Path.Rectangle(bounds);
rect.matrix = item.matrix; rect.matrix = item.matrix;
setDefaultGuideStyle(rect); setDefaultGuideStyle(rect);
rect.parent = getGuideLayer(); rect.parent = getGuideLayer();

View file

@ -5,7 +5,6 @@ import {clearSelection} from '../selection';
import BoundingBoxTool from '../selection-tools/bounding-box-tool'; import BoundingBoxTool from '../selection-tools/bounding-box-tool';
import NudgeTool from '../selection-tools/nudge-tool'; import NudgeTool from '../selection-tools/nudge-tool';
import {hoverBounds} from '../guides'; import {hoverBounds} from '../guides';
import {expandBy} from '../math';
/** /**
* Tool for adding text. Text elements have limited editability; they can't be reshaped, * 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); clearSelection(this.clearSelectedItems);
this.textBox = doubleClickHitTest.item; this.textBox = doubleClickHitTest.item;
this.mode = TextTool.TEXT_EDIT_MODE; this.mode = TextTool.TEXT_EDIT_MODE;
} else if (this.boundingBoxTool.onMouseDown( } else if (
this.boundingBoxTool.onMouseDown(
event, false /* clone */, false /* multiselect */, this.getBoundingBoxHitOptions())) { event, false /* clone */, false /* multiselect */, this.getBoundingBoxHitOptions())) {
// In select mode staying in select mode // In select mode staying in select mode
this.mode = TextTool.SELECT_MODE; this.mode = TextTool.SELECT_MODE;
@ -147,16 +147,20 @@ class TextTool extends paper.Tool {
this.mode = TextTool.TEXT_EDIT_MODE; this.mode = TextTool.TEXT_EDIT_MODE;
} else if (this.mode === TextTool.TEXT_EDIT_MODE) { } else if (this.mode === TextTool.TEXT_EDIT_MODE) {
// In text mode clicking away to begin select mode // In text mode clicking away to begin select mode
this.mode = TextTool.SELECT_MODE; if (this.textBox) {
this.textBox.selected = true; this.mode = TextTool.SELECT_MODE;
this.setSelectedItems(); this.textBox.selected = true;
this.setSelectedItems();
} else {
this.mode = null;
}
} else { } else {
// In no mode or select mode clicking away to begin text edit mode // In no mode or select mode clicking away to begin text edit mode
this.mode = TextTool.TEXT_EDIT_MODE; this.mode = TextTool.TEXT_EDIT_MODE;
clearSelection(this.clearSelectedItems); clearSelection(this.clearSelectedItems);
this.textBox = new paper.PointText({ this.textBox = new paper.PointText({
point: event.point, point: event.point,
content: 'لوحة المفاتKeyboardيح العربية', content: '',
font: 'Times', font: 'Times',
fontSize: 30 fontSize: 30
}); });
@ -165,8 +169,7 @@ class TextTool extends paper.Tool {
} }
if (this.mode === TextTool.TEXT_EDIT_MODE) { if (this.mode === TextTool.TEXT_EDIT_MODE) {
this.guide = hoverBounds(this.textBox); this.guide = hoverBounds(this.textBox, TextTool.TEXT_PADDING);
expandBy(this.guide, TextTool.TEXT_PADDING);
this.guide.dashArray = [4, 4]; this.guide.dashArray = [4, 4];
} else if (this.guide) { } else if (this.guide) {
this.guide.remove(); this.guide.remove();
@ -180,9 +183,6 @@ class TextTool extends paper.Tool {
this.boundingBoxTool.onMouseDrag(event); this.boundingBoxTool.onMouseDrag(event);
return; return;
} }
// TODO selection
} }
handleMouseUp (event) { handleMouseUp (event) {
if (event.event.button > 0 || !this.active) return; // only first mouse button if (event.event.button > 0 || !this.active) return; // only first mouse button
@ -193,7 +193,6 @@ class TextTool extends paper.Tool {
return; return;
} }
// TODO
this.active = false; this.active = false;
} }
handleKeyUp (event) { handleKeyUp (event) {
@ -210,11 +209,10 @@ class TextTool extends paper.Tool {
} else if (!(event.modifiers.alt || event.modifiers.comand || event.modifiers.control || } else if (!(event.modifiers.alt || event.modifiers.comand || event.modifiers.control ||
event.modifiers.meta || event.modifiers.option)) { event.modifiers.meta || event.modifiers.option)) {
this.textBox.content = this.textBox.content + event.character; 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 () { deactivateTool () {