Mercurial > octave
changeset 29712:0e888d2f79b7 stable
fix auto indentation of switch-strucutre in GUI editor (bug #60649)
* octave-qscintilla.cc (smart_indent): consider case ot otherwise
already being correctly indented, unindent endswitch twice,
(smart_indent_line_or_selected_text): remove duplicate handling of
otherwise
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Fri, 28 May 2021 23:15:21 +0200 |
parents | 096523ffd20d |
children | 3e046fba8805 a7935014edd1 |
files | libgui/src/m-editor/octave-qscintilla.cc |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/octave-qscintilla.cc Fri May 21 09:08:48 2021 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.cc Fri May 28 23:15:21 2021 +0200 @@ -582,28 +582,40 @@ if (prevline.contains (case_key) && do_smart_indent) { QString last_line = text (line-1); + int prev_ind = indentation (line-1); int act_ind = indentation (line); - if (last_line.contains ("switch")) + if (last_line.contains (QRegExp ("^[\t ]*switch"))) { indent (line+1); act_ind = indentation (line+1); } else - unindent (line); + { + if (prev_ind == act_ind) + unindent (line); + else if (prev_ind > act_ind) + act_ind = prev_ind; + } setIndentation (line+1, act_ind); setCursorPosition (line+1, act_ind); } ekey = QRegExp ("^[\t ]*(?:end|endif|endfor|endwhile|until|endfunction" - "|end_try_catch|end_unwind_protect)[\r]?[\t #%\n(;]"); + "|endswitch|end_try_catch|end_unwind_protect)[\r]?[\t #%\n(;]"); if (prevline.contains (ekey)) { if (indentation (line-1) <= indentation (line)) { unindent (line+1); unindent (line); + if (prevline.contains ("endswitch")) + { + // endswitch has to me unndented twice + unindent (line+1); + unindent (line); + } setCursorPosition (line+1, indentation (line)); } @@ -633,7 +645,6 @@ QRegExp mid_block_regexp = QRegExp ("^[\t ]*(?:elseif|else" - "|otherwise" "|unwind_protect_cleanup|catch)" "[\r\n\t #%]");