64 QsciLexerHTML *lexer =
new QsciLexerHTML(
this );
65 lexer->setDefaultFont( font );
68 lexer->setFont( font, -1 );
70 font.setItalic(
true );
71 lexer->setFont( font, QsciLexerHTML::HTMLComment );
72 lexer->setFont( font, QsciLexerHTML::JavaScriptComment );
73 lexer->setFont( font, QsciLexerHTML::JavaScriptCommentLine );
157 const QString commentStart(
"<!--" );
158 const QString commentEnd(
"-->" );
160 int startLine, startPos, endLine, endPos;
161 if ( hasSelectedText() )
163 getSelection( &startLine, &startPos, &endLine, &endPos );
167 getCursorPosition( &startLine, &startPos );
174 while ( text( startLine ).trimmed().isEmpty() )
177 if ( startLine > endLine )
183 while ( text( endLine ).trimmed().isEmpty() )
189 QString startLineTrimmed = text( startLine );
190 startLineTrimmed.remove( QRegularExpression(
"^\\s+" ) );
192 QString endLineTrimmed = text( endLine );
193 endLineTrimmed.remove( QRegularExpression(
"\\s+$" ) );
195 const bool commented = startLineTrimmed.startsWith( commentStart ) && endLineTrimmed.endsWith( commentEnd );
198 if ( commented && startLine == endLine && text( endLine ).trimmed().size() < commentStart.size() + commentEnd.size() )
211 c2 = endLineTrimmed.size();
212 if ( endLineTrimmed.endsWith( u
" "_s + commentEnd ) )
214 c1 = c2 - commentEnd.size() - 1;
218 c1 = c2 - commentEnd.size();
221 setSelection( endLine, c1, endLine, c2 );
222 removeSelectedText();
225 c1 = indentation( startLine );
226 if ( startLineTrimmed.startsWith( commentStart + u
" "_s ) )
228 c2 = c1 + commentStart.size() + 1;
232 c2 = c1 + commentStart.size();
235 setSelection( startLine, c1, startLine, c2 );
236 removeSelectedText();
241 insertAt( u
" "_s + commentEnd, endLine, endLineTrimmed.size() );
242 insertAt( commentStart + u
" "_s, startLine, indentation( startLine ) );
248 setSelection( startLine, startPos, endLine, endPos );
QgsCodeEditor(QWidget *parent=nullptr, const QString &title=QString(), bool folding=false, bool margin=false, QgsCodeEditor::Flags flags=QgsCodeEditor::Flags(), QgsCodeEditor::Mode mode=QgsCodeEditor::Mode::ScriptEditor)
Construct a new code editor.