From 90b125c67c109181acf83c7fed59e3011b0d03d4 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Mon, 9 Dec 2013 21:57:07 -0800 Subject: [PATCH] commitmsg: better copy/paste behavior Qt allows users to paste newlines into the `summary` field even though it's not something that's normally allowed via the keyboard. This is unwanted because the commit message may contain more than what is visible in the single-line field. Allow users to paste multiple lines of text into the `summary` field by automatically splitting it apart so that everything beyond the first newline is moved to the `Extended description` field. This prevents newlines from entering the `summary` field and improves the editor's usability when pasting multiple lines of text. Closes #212 Reported-by: @grandinj via github.com Signed-off-by: David Aguilar --- cola/widgets/commitmsg.py | 26 +++++++++++++++++++++++++- share/doc/git-cola/relnotes.rst | 9 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cola/widgets/commitmsg.py b/cola/widgets/commitmsg.py index eafcd9d3..ab9e48cf 100644 --- a/cola/widgets/commitmsg.py +++ b/cola/widgets/commitmsg.py @@ -149,7 +149,7 @@ class CommitMessageEditor(QtGui.QWidget): # Keep model informed of changes self.connect(self.summary, SIGNAL('textChanged(QString)'), - self.commit_message_changed) + self.commit_summary_changed) self.connect(self.description, SIGNAL('textChanged()'), self.commit_message_changed) @@ -216,6 +216,30 @@ class CommitMessageEditor(QtGui.QWidget): return text return textwrap.word_wrap(text, self._tabwidth, self._textwidth) + def commit_summary_changed(self, value): + """Respond to changes to the `summary` field + + Newlines can enter the `summary` field when pasting, which is + undesirable. Break the pasted value apart into the separate + (summary, description) values and move the description over to the + "extended description" field. + + """ + value = unicode(value) + if '\n' in value: + summary, description = value.split('\n', 1) + description = description.lstrip('\n') + cur_description = self.description.value() + if cur_description: + description = description + '\n' + cur_description + # this callback is triggered by changing `summary` + # so disable signals for `summary` only. + self.summary.blockSignals(True) + self.summary.set_value(summary) + self.summary.blockSignals(False) + self.description.set_value(description) + self.commit_message_changed() + def commit_message_changed(self, value=None): """Update the model when values change""" self.notifying = True diff --git a/share/doc/git-cola/relnotes.rst b/share/doc/git-cola/relnotes.rst index 0caa0bfe..80a74427 100644 --- a/share/doc/git-cola/relnotes.rst +++ b/share/doc/git-cola/relnotes.rst @@ -1,5 +1,14 @@ git-cola v1.9.3 --------------- +Usability, bells and whistles +----------------------------- + +* Multiple lines of text can now be pasted into the `summary` field. + All text beyond the first newline will be automatically moved to the + `extended description` field. + + https://github.com/git-cola/git-cola/issues/212 + Fixes ----- * Stray whitespace in `.git` files is now ignored. -- 2.11.4.GIT