From 9731ebecb74c81ca64af6a79bab08e4035e55ea5 Mon Sep 17 00:00:00 2001 From: abakkk Date: Mon, 12 Oct 2020 11:09:20 +0200 Subject: [PATCH] start a new line with "Shift + Enter" Text tool: * Enter: valid text and close text entry. * Escape: close text entry. * Shift + Enter: Start a new line. related to #30. --- area.js | 16 +++++++++++----- locale/draw-on-your-screen.pot | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/area.js b/area.js index 5fcbddb..380da2f 100644 --- a/area.js +++ b/area.js @@ -802,8 +802,8 @@ var DrawingArea = new Lang.Class({ this.currentElement.text = ''; this.currentElement.cursorPosition = 0; // Translators: %s is a key label - this.emit('show-osd', Files.Icons.TOOL_TEXT, _("Type your text and press %s") - .format(Gtk.accelerator_get_label(Clutter.KEY_Escape, 0)), "", -1, true); + this.emit('show-osd', Files.Icons.TOOL_TEXT, _("Press %s\nto start a new line") + .format(Gtk.accelerator_get_label(Clutter.KEY_Return, 1)), "", -1, true); this._updateTextCursorTimeout(); this.textHasCursor = true; this._redisplay(); @@ -828,9 +828,7 @@ var DrawingArea = new Lang.Class({ } this.textEntry.clutterText.connect('activate', (clutterText) => { - let startNewLine = true; - this._stopWriting(startNewLine); - clutterText.text = ""; + this._stopWriting(); }); this.textEntry.clutterText.connect('text-changed', (clutterText) => { @@ -844,8 +842,16 @@ var DrawingArea = new Lang.Class({ this.textEntry.clutterText.connect('key-press-event', (clutterText, event) => { if (event.get_key_symbol() == Clutter.KEY_Escape) { + this.currentElement.text = ""; this._stopWriting(); return Clutter.EVENT_STOP; + } else if (event.has_shift_modifier() && + (event.get_key_symbol() == Clutter.KEY_Return || + event.get_key_symbol() == Clutter.KEY_KP_Enter)) { + let startNewLine = true; + this._stopWriting(startNewLine); + clutterText.text = ""; + return Clutter.EVENT_STOP; } // 'cursor-changed' signal is not emitted if the text entry is not visible. diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index 5e87946..5de5eaf 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -44,7 +44,7 @@ msgstr "" #. Translators: %s is a key label #, javascript-format -msgid "Type your text and press %s" +msgid "Press %s\nto start a new line" msgstr "" #. Translators: It is displayed in an OSD notification to ask the user to start picking, so it should use the imperative mood.