61 QsciLexerHTML *lexer =
new QsciLexerHTML(
this );
62 lexer->setDefaultFont( font );
65 lexer->setFont( font, -1 );
67 font.setItalic(
true );
68 lexer->setFont( font, QsciLexerHTML::HTMLComment );
69 lexer->setFont( font, QsciLexerHTML::JavaScriptComment );
70 lexer->setFont( font, QsciLexerHTML::JavaScriptCommentLine );
154 const QString commentStart(
"<!--" );
155 const QString commentEnd(
"-->" );
157 int startLine, startPos, endLine, endPos;
158 if ( hasSelectedText() )
160 getSelection( &startLine, &startPos, &endLine, &endPos );
164 getCursorPosition( &startLine, &startPos );
171 while ( text( startLine ).trimmed().isEmpty() )
174 if ( startLine > endLine )
180 while ( text( endLine ).trimmed().isEmpty() )
186 QString startLineTrimmed = text( startLine );
187 startLineTrimmed.remove( QRegularExpression(
"^\\s+" ) );
189 QString endLineTrimmed = text( endLine );
190 endLineTrimmed.remove( QRegularExpression(
"\\s+$" ) );
192 const bool commented = startLineTrimmed.startsWith( commentStart ) && endLineTrimmed.endsWith( commentEnd );
195 if ( commented && startLine == endLine && text( endLine ).trimmed().size() < commentStart.size() + commentEnd.size() )
208 c2 = endLineTrimmed.size();
209 if ( endLineTrimmed.endsWith( QStringLiteral(
" " ) + commentEnd ) )
211 c1 = c2 - commentEnd.size() - 1;
215 c1 = c2 - commentEnd.size();
218 setSelection( endLine, c1, endLine, c2 );
219 removeSelectedText();
222 c1 = indentation( startLine );
223 if ( startLineTrimmed.startsWith( commentStart + QStringLiteral(
" " ) ) )
225 c2 = c1 + commentStart.size() + 1;
229 c2 = c1 + commentStart.size();
232 setSelection( startLine, c1, startLine, c2 );
233 removeSelectedText();
238 insertAt( QStringLiteral(
" " ) + commentEnd, endLine, endLineTrimmed.size() );
239 insertAt( commentStart + QStringLiteral(
" " ), startLine, indentation( startLine ) );
245 setSelection( startLine, startPos, endLine, endPos );