Bug #959116: Split slide button inserts tag on its own line

This commit is contained in:
M2j 2012-04-02 16:23:25 +02:00
parent 9d3093a99f
commit 36fc1b5339
2 changed files with 24 additions and 12 deletions

View File

@ -72,16 +72,25 @@ class EditCustomSlideForm(QtGui.QDialog, Ui_CustomSlideEditDialog):
"""
Adds a slide split at the cursor.
"""
if self.slideTextEdit.textCursor().columnNumber() != 0:
self.slideTextEdit.insertPlainText(u'\n')
self.slideTextEdit.insertPlainText(u'[===]\n')
self.insertSingleLineTextAtCursor(u'[===]')
self.slideTextEdit.setFocus()
def onSplitButtonPressed(self):
"""
Adds a virtual split at cursor.
"""
if self.slideTextEdit.textCursor().columnNumber() != 0:
self.slideTextEdit.insertPlainText(u'\n')
self.slideTextEdit.insertPlainText(u'[---]')
self.insertSingleLineTextAtCursor(u'[---]')
self.slideTextEdit.setFocus()
def insertSingleLineTextAtCursor(self, text):
"""
Adds ``text`` in a single line at the cursor position.
"""
full_text = self.slideTextEdit.toPlainText()
position = self.slideTextEdit.textCursor().position()
if position and full_text[position-1] != u'\n':
text = u'\n' + text
if position == len(full_text) or full_text[position] != u'\n':
text += u'\n'
self.slideTextEdit.insertPlainText(text)

View File

@ -75,10 +75,14 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
self.verseTextEdit.setFocus()
def onSplitButtonClicked(self):
verse_type_index = self.verseTypeComboBox.currentIndex()
if self.verseTextEdit.textCursor().columnNumber() != 0:
self.verseTextEdit.insertPlainText(u'\n')
self.verseTextEdit.insertPlainText(u'[---]')
text = self.verseTextEdit.toPlainText()
position = self.verseTextEdit.textCursor().position()
insert_string = u'[---]'
if position and text[position-1] != u'\n':
insert_string = u'\n' + insert_string
if position == len(text) or text[position] != u'\n':
insert_string += u'\n'
self.verseTextEdit.insertPlainText(insert_string)
self.verseTextEdit.setFocus()
def onInsertButtonClicked(self):
@ -113,8 +117,7 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
verse_num = int(match.group(2))
except ValueError:
verse_num = 1
verse_type_index = VerseType.from_loose_input(verse_tag, None)
if verse_type_index is not None:
if VerseType.from_loose_input(verse_tag, False):
self.verseNumberBox.setValue(verse_num)
def onCursorPositionChanged(self):