Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

commit: Alt-Q message reflow

This Qt version is much easier to follow, IMHO

Changeset 558c25668aae

Parent 280ee3bb4df2

by Steve Borho

Changes to one file · Browse files at 558c25668aae Showing diff from parent 280ee3bb4df2 Diff from another changeset...

 
20
21
22
23
 
24
25
26
 
171
172
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
175
176
 
503
504
505
 
 
 
 
 
506
507
508
 
20
21
22
 
23
24
25
26
 
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
 
547
548
549
550
551
552
553
554
555
556
557
@@ -20,7 +20,7 @@
 from tortoisehg.hgqt import qtlib, status, cmdui, branchop    # Technical Debt for CommitWidget -# reflow / auto-wrap / paste filenames +# auto-wrap / paste filenames  # qrefresh support  # refresh parent changeset descriptions after refresh  # threaded / wrapped commit (need a CmdRunner equivalent) @@ -171,6 +171,50 @@
  sels.append(sel)   self.msgte.setExtraSelections(sels)   + def msgReflow(self): + 'User pressed Alt-Q' + if QApplication.focusWidget() != self.msgte: + return + + sumlen, maxlen = self.getLengths() + if not maxlen: + return + + # In QtTextDocument land, a block is a sequence of text ending + # in (and including) a carriage return. Aka, a line of text. + block = self.msgte.textCursor().block() + while block.length() and block.previous().length() > 1: + block = block.previous() + begin = block.position() + + while block.length() and block.next().length() > 1: + block = block.next() + end = block.position() + block.length() - 1 + + # select the contiguous lines of text under the cursor + cursor = self.msgte.textCursor() + cursor.setPosition(begin, QTextCursor.MoveAnchor) + cursor.setPosition(end, QTextCursor.KeepAnchor) + sentence = cursor.selection().toPlainText().simplified() + + parts = sentence.split(' ', QString.SkipEmptyParts) + lines = QStringList() + line = QStringList() + partslen = 0 + for part in parts: + if partslen + len(line) + len(part) + 1 > maxlen: + if line: + lines.append(line.join(' ')) + line, partslen = QStringList(), 0 + line.append(part) + partslen += len(part) + if line: + lines.append(line.join(' ')) + reflow = lines.join('\n') + + # Replace selection with new sentence + cursor.insertText(reflow) +   def getLengths(self):   repo = self.stwidget.repo   try: @@ -503,6 +547,11 @@
  elif event.key() == Qt.Key_Escape:   self.reject()   return + elif event.modifiers() == Qt.AltModifier and event.key() == Qt.Key_Q: + self.commit.msgReflow() + elif event.modifiers() == Qt.MetaModifier and event.key() == Qt.Key_R: + # On a Mac, CTRL-R will also reflow (until someone fixes this) + self.commit.msgReflow()   return super(QDialog, self).keyPressEvent(event)     def accept(self):