65 QsciLexerHTML *lexer =
new QsciLexerHTML(
this );
66 lexer->setDefaultFont( font );
69 lexer->setFont( font, -1 );
71 font.setItalic(
true );
72 lexer->setFont( font, QsciLexerHTML::HTMLComment );
73 lexer->setFont( font, QsciLexerHTML::JavaScriptComment );
74 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( QStringLiteral(
" " ) + 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 + QStringLiteral(
" " ) ) )
228 c2 = c1 + commentStart.size() + 1;
232 c2 = c1 + commentStart.size();
235 setSelection( startLine, c1, startLine, c2 );
236 removeSelectedText();
241 insertAt( QStringLiteral(
" " ) + commentEnd, endLine, endLineTrimmed.size() );
242 insertAt( commentStart + QStringLiteral(
" " ), startLine, indentation( startLine ) );
248 setSelection( startLine, startPos, endLine, endPos );