summaryrefslogtreecommitdiff
path: root/utils/themeeditor/gui/codeeditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/gui/codeeditor.cpp')
-rw-r--r--utils/themeeditor/gui/codeeditor.cpp59
1 files changed, 52 insertions, 7 deletions
diff --git a/utils/themeeditor/gui/codeeditor.cpp b/utils/themeeditor/gui/codeeditor.cpp
index 44f331d280..3858460385 100644
--- a/utils/themeeditor/gui/codeeditor.cpp
+++ b/utils/themeeditor/gui/codeeditor.cpp
@@ -107,6 +107,11 @@ void CodeEditor::cursorMoved()
107 /* Closing the completer if the cursor has moved out of its bounds */ 107 /* Closing the completer if the cursor has moved out of its bounds */
108 if(completer.isVisible()) 108 if(completer.isVisible())
109 { 109 {
110 if(document()->toPlainText().length() > docLength)
111 tagEnd++;
112 else if(document()->toPlainText().length() < docLength)
113 tagEnd--;
114
110 if(textCursor().position() < tagBegin 115 if(textCursor().position() < tagBegin
111 || textCursor().position() > tagEnd) 116 || textCursor().position() > tagEnd)
112 { 117 {
@@ -115,6 +120,24 @@ void CodeEditor::cursorMoved()
115 } 120 }
116} 121}
117 122
123void CodeEditor::insertTag()
124{
125 /* Clearing the typed tag and inserting one from the completer */
126 QTextCursor at(document());
127 at.setPosition(tagBegin, QTextCursor::MoveAnchor);
128 while(document()->characterAt(at.position()) == QChar('%')
129 || document()->characterAt(at.position()) == '?')
130 at.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, 1);
131
132 at.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,
133 tagEnd - at.position());
134 at.removeSelectedText();
135
136 at.insertText(completer.currentItem()->text(0));
137
138 completer.hide();
139}
140
118//![resizeEvent] 141//![resizeEvent]
119 142
120void CodeEditor::resizeEvent(QResizeEvent *e) 143void CodeEditor::resizeEvent(QResizeEvent *e)
@@ -131,7 +154,7 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
131void CodeEditor::keyPressEvent(QKeyEvent *event) 154void CodeEditor::keyPressEvent(QKeyEvent *event)
132{ 155{
133 156
134 if(!settings.value("completeSyntax", false).toBool()) 157 if(!settings.value("completeSyntax", true).toBool())
135 { 158 {
136 QPlainTextEdit::keyPressEvent(event); 159 QPlainTextEdit::keyPressEvent(event);
137 return; 160 return;
@@ -154,10 +177,22 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
154 < completer.topLevelItemCount() - 1) 177 < completer.topLevelItemCount() - 1)
155 QApplication::sendEvent(&completer, event); 178 QApplication::sendEvent(&completer, event);
156 } 179 }
157 else if(event->key() == Qt::Key_Backspace) 180 else if(event->key() == Qt::Key_Backspace
181 || event->key() == Qt::Key_Delete)
158 { 182 {
159 tagEnd--; 183 docLength = document()->toPlainText().length();
160 QPlainTextEdit::keyPressEvent(event); 184 QPlainTextEdit::keyPressEvent(event);
185
186 QString filterText;
187
188 for(int i = tagBegin; i < tagEnd; i++)
189 {
190 QChar c = document()->characterAt(i);
191 if(c != '%' && c != '?')
192 filterText.append(c);
193 }
194
195 completer.filter(filterText);
161 } 196 }
162 else if(event->key() == Qt::Key_Escape) 197 else if(event->key() == Qt::Key_Escape)
163 { 198 {
@@ -165,14 +200,15 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
165 completer.hide(); 200 completer.hide();
166 QPlainTextEdit::keyPressEvent(event); 201 QPlainTextEdit::keyPressEvent(event);
167 } 202 }
168 else if(event->key() == Qt::Key_Enter) 203 else if(event->key() == Qt::Key_Return)
169 { 204 {
170 /* The enter key inserts the currently selected tag */ 205 /* The enter key inserts the currently selected tag */
206 insertTag();
171 } 207 }
172 else if(event->key() == Qt::Key_Question) 208 else if(event->key() == Qt::Key_Question)
173 { 209 {
174 /* The question mark doesn't filter the list */ 210 /* The question mark doesn't filter the list */
175 tagEnd++; 211 docLength = document()->toPlainText().length();
176 QPlainTextEdit::keyPressEvent(event); 212 QPlainTextEdit::keyPressEvent(event);
177 } 213 }
178 else if(event->key() == Qt::Key_Left 214 else if(event->key() == Qt::Key_Left
@@ -184,10 +220,19 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
184 else 220 else
185 { 221 {
186 /* Otherwise, we have to filter the list */ 222 /* Otherwise, we have to filter the list */
187 tagEnd++; 223 docLength = document()->toPlainText().length();
188 QPlainTextEdit::keyPressEvent(event); 224 QPlainTextEdit::keyPressEvent(event);
189 225
190 QString filterText = ""; 226 QString filterText;
227
228 for(int i = tagBegin; i < tagEnd; i++)
229 {
230 QChar c = document()->characterAt(i);
231 if(c != '%' && c != '?')
232 filterText.append(c);
233 }
234
235 completer.filter(filterText);
191 } 236 }
192 } 237 }
193 else 238 else