83
83
Find the last used verse tag by using given position and regex.
84
84
Then insert the tag and create a new line if required.
86
text = self.verse_text_edit.toPlainText()
86
87
position = self.verse_text_edit.textCursor().position()
87
text = self.verse_text_edit.toPlainText()
88
position = text.rfind('---[', 0, position)
89
# If editing single verse or ---[ not found, get value of the current verse and insert it.
90
# This will insert the verse tag if editing a single verse or all verses and no verse tag is present.
91
if self.has_single_verse or position == -1:
92
verse_type_index = self.verse_type_combo_box.currentIndex()
93
self.insert_verse(VerseType.tags[verse_type_index], self.verse_number_box.value())
94
# Find & Duplicate the currently selected verses tag and insert it.
96
text = text[position:]
97
position = text.find(']---')
100
text = text[:position + 4]
101
match = re.match(('---\[.*\]---'), text)
102
insert_string = match.group()
103
# Reset text & position data for checking the proper inserting place & is newline required.
104
text = self.verse_text_edit.toPlainText()
105
position = self.verse_text_edit.textCursor().position()
106
if position and text[position - 1] != '\n':
107
insert_string = '\n' + insert_string
108
if position == len(text) or text[position] != '\n':
109
insert_string += '\n'
110
self.verse_text_edit.insertPlainText(insert_string)
111
self.verse_text_edit.setFocus()
88
insert_string = '[--]'
89
if position and text[position - 1] != '\n':
90
insert_string = '\n' + insert_string
91
if position == len(text) or text[position] != '\n':
93
self.verse_text_edit.insertPlainText(insert_string)
94
self.verse_text_edit.setFocus()
113
96
def on_insert_button_clicked(self):
134
117
Adjusts the verse number SpinBox in regard to the selected verse type and the cursor's position.
119
if self.has_single_verse:
136
121
position = self.verse_text_edit.textCursor().position()
137
122
text = self.verse_text_edit.toPlainText()
138
123
verse_name = VerseType.translated_names[
139
124
self.verse_type_combo_box.currentIndex()]
140
if not text or self.has_single_verse:
142
127
position = text.rfind('---[{verse}'.format(verse=verse_name), 0, position)
143
128
if position == -1:
147
132
position = text.find(']---')
148
133
if position == -1:
150
# If editing a Single verse, set the text to match current verse, otherwise increase the suggested verse.
151
# This seems to only take effect when adding a split in middle of the sentence.
152
if self.has_single_verse:
153
text = text[:position]
155
text = text[:position + 4]
135
text = text[:position + 4]
156
136
match = VERSE_REGEX.match(text)