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 );
156 const QString commentStart(
"<!--" );
157 const QString commentEnd(
"-->" );
159 int startLine, startPos, endLine, endPos;
160 if ( hasSelectedText() )
162 getSelection( &startLine, &startPos, &endLine, &endPos );
166 getCursorPosition( &startLine, &startPos );
173 while ( text( startLine ).trimmed().isEmpty() )
176 if ( startLine > endLine )
182 while ( text( endLine ).trimmed().isEmpty() )
188 QString startLineTrimmed = text( startLine );
189 startLineTrimmed.remove( QRegularExpression(
"^\\s+" ) );
191 QString endLineTrimmed = text( endLine );
192 endLineTrimmed.remove( QRegularExpression(
"\\s+$" ) );
194 const bool commented = startLineTrimmed.startsWith( commentStart ) && endLineTrimmed.endsWith( commentEnd );
197 if ( commented && startLine == endLine && text( endLine ).trimmed().size() < commentStart.size() + commentEnd.size() )
210 c2 = endLineTrimmed.size();
211 if ( endLineTrimmed.endsWith( QStringLiteral(
" " ) + commentEnd ) )
213 c1 = c2 - commentEnd.size() - 1;
217 c1 = c2 - commentEnd.size();
220 setSelection( endLine, c1, endLine, c2 );
221 removeSelectedText();
224 c1 = indentation( startLine );
225 if ( startLineTrimmed.startsWith( commentStart + QStringLiteral(
" " ) ) )
227 c2 = c1 + commentStart.size() + 1;
231 c2 = c1 + commentStart.size();
234 setSelection( startLine, c1, startLine, c2 );
235 removeSelectedText();
240 insertAt( QStringLiteral(
" " ) + commentEnd, endLine, endLineTrimmed.size() );
241 insertAt( commentStart + QStringLiteral(
" " ), startLine, indentation( startLine ) );
247 setSelection( startLine, startPos, endLine, endPos );