From: Vincent van Ravesteijn Date: Mon, 18 Oct 2010 10:48:29 +0000 (+0000) Subject: Fix bug #6869: Crash when unindenting empty lines in listings inset. X-Git-Tag: 2.0.0~2354 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f35d1a2a4c7fcc4ab589c3fd2cf60424659bd74e;p=features.git Fix bug #6869: Crash when unindenting empty lines in listings inset. - Remove some duplicated code; - Do not call par.getChar(0) when the par is empty. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35702 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Text3.cpp b/src/Text3.cpp index 0a86d7cc3b..255dc62d6b 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -911,24 +911,22 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) pit_type const pit_end = cur.selEnd().pit(); for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) { Paragraph & par = paragraphs()[pit]; - if (par.getChar(0) == '\t') { - if (cur.pit() == pit) - cur.posBackward(); - if (cur.realAnchor().pit() == pit && cur.realAnchor().pos() > 0 ) - cur.realAnchor().backwardPos(); - - par.eraseChar(0, tc); - } else - // If no tab was present, try to remove up to four spaces. - for (int n_spaces = 0; - par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) { + if (par.empty()) + continue; + char_type const c = par.getChar(0); + if (c == '\t' || c == ' ') { + // remove either 1 tab or 4 spaces. + int const n = (c == ' ' ? 4 : 1); + for (int i = 0; i < n + && !par.empty() && par.getChar(0) == c; ++i) { if (cur.pit() == pit) cur.posBackward(); - if (cur.realAnchor().pit() == pit && cur.realAnchor().pos() > 0 ) + if (cur.realAnchor().pit() == pit + && cur.realAnchor().pos() > 0 ) cur.realAnchor().backwardPos(); - par.eraseChar(0, tc); } + } } cur.finishUndo(); } else {