62 QsciLexerHTML *lexer =
new QsciLexerHTML(
this );
63 lexer->setDefaultFont( font );
66 lexer->setFont( font, -1 );
68 font.setItalic(
true );
69 lexer->setFont( font, QsciLexerHTML::HTMLComment );
70 lexer->setFont( font, QsciLexerHTML::JavaScriptComment );
71 lexer->setFont( font, QsciLexerHTML::JavaScriptCommentLine );
155 const QString commentStart(
"<!--" );
156 const QString commentEnd(
"-->" );
158 int startLine, startPos, endLine, endPos;
159 if ( hasSelectedText() )
161 getSelection( &startLine, &startPos, &endLine, &endPos );
165 getCursorPosition( &startLine, &startPos );
172 while ( text( startLine ).trimmed().isEmpty() )
175 if ( startLine > endLine )
181 while ( text( endLine ).trimmed().isEmpty() )
187 QString startLineTrimmed = text( startLine );
188 startLineTrimmed.remove( QRegularExpression(
"^\\s+" ) );
190 QString endLineTrimmed = text( endLine );
191 endLineTrimmed.remove( QRegularExpression(
"\\s+$" ) );
193 const bool commented = startLineTrimmed.startsWith( commentStart ) && endLineTrimmed.endsWith( commentEnd );
196 if ( commented && startLine == endLine && text( endLine ).trimmed().size() < commentStart.size() + commentEnd.size() )
209 c2 = endLineTrimmed.size();
210 if ( endLineTrimmed.endsWith( QStringLiteral(
" " ) + commentEnd ) )
212 c1 = c2 - commentEnd.size() - 1;
216 c1 = c2 - commentEnd.size();
219 setSelection( endLine, c1, endLine, c2 );
220 removeSelectedText();
223 c1 = indentation( startLine );
224 if ( startLineTrimmed.startsWith( commentStart + QStringLiteral(
" " ) ) )
226 c2 = c1 + commentStart.size() + 1;
230 c2 = c1 + commentStart.size();
233 setSelection( startLine, c1, startLine, c2 );
234 removeSelectedText();
239 insertAt( QStringLiteral(
" " ) + commentEnd, endLine, endLineTrimmed.size() );
240 insertAt( commentStart + QStringLiteral(
" " ), startLine, indentation( startLine ) );
246 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.