Mercurial > octave
changeset 24306:5b7f99dfdab3 stable
allow uncommenting in editor when line begins with whitespace (bug #52406)
* file-editor-tab.cc (do_comment_selected_text): use a regular expression
instead of only checking the beginning of the line for a comment string
author | Torsten <mttl@mailbox.org> |
---|---|
date | Tue, 21 Nov 2017 21:35:32 +0100 |
parents | 30921b835960 |
children | ae7948b6c017 |
files | libgui/src/m-editor/file-editor-tab.cc |
diffstat | 1 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Thu Nov 09 21:07:42 2017 +0100 +++ b/libgui/src/m-editor/file-editor-tab.cc Tue Nov 21 21:35:32 2017 +0100 @@ -1374,6 +1374,9 @@ file_editor_tab::do_comment_selected_text (bool comment) { QString comment_str = comment_string (_edit_area->lexer ()->lexer ()); + QRegExp rxc = QRegExp ("^([ \\t]*)" + comment_str); + int len, lenc = comment_str.length (); + _edit_area->beginUndoAction (); if (_edit_area->hasSelectedText ()) @@ -1391,9 +1394,10 @@ else { QString line (_edit_area->text (i)); - if (line.startsWith (comment_str)) + if (line.contains (rxc)) { - _edit_area->setSelection (i, 0, i, comment_str.length ()); + len = rxc.matchedLength (); + _edit_area->setSelection (i, len-lenc, i, len); _edit_area->removeSelectedText (); } } @@ -1411,9 +1415,10 @@ else { QString line (_edit_area->text (cpline)); - if (line.startsWith (comment_str)) + if (line.contains (rxc)) { - _edit_area->setSelection (cpline, 0, cpline, comment_str.length ()); + len = rxc.matchedLength (); + _edit_area->setSelection (cpline, len-lenc, cpline, len); _edit_area->removeSelectedText (); } }