]> git.lyx.org Git - features.git/commitdiff
Fix bug #6869: Crash when unindenting empty lines in listings inset.
authorVincent van Ravesteijn <vfr@lyx.org>
Mon, 18 Oct 2010 10:48:29 +0000 (10:48 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Mon, 18 Oct 2010 10:48:29 +0000 (10:48 +0000)
- 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

src/Text3.cpp

index 0a86d7cc3b636e9c78c09aa7c1030fbd2b319c91..255dc62d6b487a4c451a2d7e2f509b5f3cd3673a 100644 (file)
@@ -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 {