text: start a new line with Enter key
Finish writing with click or `Escape` key. close #30
This commit is contained in:
parent
c087e359d9
commit
755b3d79c9
49
draw.js
49
draw.js
|
|
@ -248,13 +248,13 @@ var DrawingArea = new Lang.Class({
|
||||||
let [x, y] = event.get_coords();
|
let [x, y] = event.get_coords();
|
||||||
let shiftPressed = event.has_shift_modifier();
|
let shiftPressed = event.has_shift_modifier();
|
||||||
|
|
||||||
// stop writing
|
|
||||||
if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.WRITING) {
|
if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.WRITING) {
|
||||||
|
// finish writing
|
||||||
this._stopWriting();
|
this._stopWriting();
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide helper
|
|
||||||
if (this.helper.visible) {
|
if (this.helper.visible) {
|
||||||
|
// hide helper
|
||||||
this.helper.hideHelp();
|
this.helper.hideHelp();
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
}
|
}
|
||||||
|
|
@ -296,15 +296,11 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_onKeyPressed: function(actor, event) {
|
_onKeyPressed: function(actor, event) {
|
||||||
|
if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.WRITING) {
|
||||||
if (event.get_key_symbol() == Clutter.KEY_Escape) {
|
if (event.get_key_symbol() == Clutter.KEY_Escape) {
|
||||||
if (this.helper.visible)
|
// finish writing
|
||||||
this.helper.hideHelp();
|
this._stopWriting();
|
||||||
else
|
} else if (event.get_key_symbol() == Clutter.KEY_BackSpace) {
|
||||||
this.emit('stop-drawing');
|
|
||||||
return Clutter.EVENT_STOP;
|
|
||||||
|
|
||||||
} else if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.WRITING) {
|
|
||||||
if (event.get_key_symbol() == Clutter.KEY_BackSpace) {
|
|
||||||
this.currentElement.text = this.currentElement.text.slice(0, -1);
|
this.currentElement.text = this.currentElement.text.slice(0, -1);
|
||||||
this._updateTextCursorTimeout();
|
this._updateTextCursorTimeout();
|
||||||
} else if (event.has_control_modifier() && event.get_key_symbol() == 118) {
|
} else if (event.has_control_modifier() && event.get_key_symbol() == 118) {
|
||||||
|
|
@ -314,13 +310,13 @@ var DrawingArea = new Lang.Class({
|
||||||
this._updateTextCursorTimeout();
|
this._updateTextCursorTimeout();
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
});
|
});
|
||||||
return Clutter.EVENT_STOP;
|
|
||||||
} else if (event.get_key_symbol() == Clutter.KEY_Return || event.get_key_symbol() == 65421) {
|
} else if (event.get_key_symbol() == Clutter.KEY_Return || event.get_key_symbol() == 65421) {
|
||||||
// stop writing
|
|
||||||
// Clutter.KEY_Return is "Enter" and 65421 is KP_Enter
|
// Clutter.KEY_Return is "Enter" and 65421 is KP_Enter
|
||||||
this._stopWriting();
|
// start a new line
|
||||||
|
let startNewLine = true;
|
||||||
|
this._stopWriting(startNewLine);
|
||||||
} else if (event.has_control_modifier()){
|
} else if (event.has_control_modifier()){
|
||||||
// it's a shortcut, do not write text
|
// it is a shortcut, do not write text
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
} else {
|
} else {
|
||||||
let unicode = event.get_key_unicode();
|
let unicode = event.get_key_unicode();
|
||||||
|
|
@ -330,6 +326,13 @@ var DrawingArea = new Lang.Class({
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
|
|
||||||
|
} else if (event.get_key_symbol() == Clutter.KEY_Escape) {
|
||||||
|
if (this.helper.visible)
|
||||||
|
this.helper.hideHelp();
|
||||||
|
else
|
||||||
|
this.emit('stop-drawing');
|
||||||
|
return Clutter.EVENT_STOP;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
@ -407,11 +410,11 @@ var DrawingArea = new Lang.Class({
|
||||||
(this.currentShape == Shapes.NONE ||
|
(this.currentShape == Shapes.NONE ||
|
||||||
Math.hypot(this.currentElement.points[1][0] - this.currentElement.points[0][0], this.currentElement.points[1][1] - this.currentElement.points[0][1]) > 3)) {
|
Math.hypot(this.currentElement.points[1][0] - this.currentElement.points[0][0], this.currentElement.points[1][1] - this.currentElement.points[0][1]) > 3)) {
|
||||||
|
|
||||||
// start writing
|
|
||||||
if (this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.DRAWING) {
|
if (this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.DRAWING) {
|
||||||
|
// start writing
|
||||||
this.currentElement.state = TextState.WRITING;
|
this.currentElement.state = TextState.WRITING;
|
||||||
this.currentElement.text = '';
|
this.currentElement.text = '';
|
||||||
this.emit('show-osd', null, _("Type your text\nand press Enter"), "", -1);
|
this.emit('show-osd', null, _("Type your text\nand press <i>Escape</i>"), "", -1);
|
||||||
this._updateTextCursorTimeout();
|
this._updateTextCursorTimeout();
|
||||||
this.textHasCursor = true;
|
this.textHasCursor = true;
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
|
|
@ -445,11 +448,23 @@ var DrawingArea = new Lang.Class({
|
||||||
this.updatePointerCursor(controlPressed);
|
this.updatePointerCursor(controlPressed);
|
||||||
},
|
},
|
||||||
|
|
||||||
_stopWriting: function() {
|
_stopWriting: function(startNewLine) {
|
||||||
if (this.currentElement.text.length > 0)
|
if (this.currentElement.text.length > 0)
|
||||||
this.elements.push(this.currentElement);
|
this.elements.push(this.currentElement);
|
||||||
|
if (startNewLine && this.currentElement.points.length == 2) {
|
||||||
|
// copy object, the original keep existing in this.elements
|
||||||
|
this.currentElement = Object.create(this.currentElement);
|
||||||
|
let height = Math.abs(this.currentElement.points[1][1] - this.currentElement.points[0][1]);
|
||||||
|
// define a new 'points' array, the original keep existing in this.elements
|
||||||
|
this.currentElement.points = [
|
||||||
|
[this.currentElement.points[0][0], this.currentElement.points[0][1] + height],
|
||||||
|
[this.currentElement.points[1][0], this.currentElement.points[1][1] + height]
|
||||||
|
];
|
||||||
|
this.currentElement.text = "";
|
||||||
|
} else {
|
||||||
this.currentElement = null;
|
this.currentElement = null;
|
||||||
this._stopTextCursorTimeout();
|
this._stopTextCursorTimeout();
|
||||||
|
}
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ msgstr ""
|
||||||
|
|
||||||
msgid ""
|
msgid ""
|
||||||
"Type your text\n"
|
"Type your text\n"
|
||||||
"and press Enter"
|
"and press <i>Escape</i>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "Screenshot"
|
msgid "Screenshot"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue