]> git.lyx.org Git - features.git/commitdiff
Do not remove character at start of paragraph when cutting
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 22 Jul 2018 20:18:50 +0000 (22:18 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 18 Sep 2018 20:57:41 +0000 (22:57 +0200)
The part of code that removed space at start of paragraph have been
there forever, but its intent is unclear. For example, cutting text at
the end of a paragraph will lead to remove space at the start of this
same paragraph.

The removal of this functionality is offset by a rewrite of DEPM that
makes it more thorough.

Fixes bug #10503.

(cherry picked from commit e4dba53232bc71d5a577466e7fb4a3251944d9d8)

src/CutAndPaste.cpp
src/CutAndPaste.h
src/Text.cpp
src/Text3.cpp
src/TextMetrics.cpp
src/lyxfind.cpp
src/mathed/InsetMathNest.cpp

index 2d18abad8d2c2dc4dc2c25a16a9ee98287f03d74..43e6278b3ef65e60a694ee507b9418f06d09952f 100644 (file)
@@ -897,7 +897,7 @@ size_type numberOfSelections()
 
 namespace {
 
-void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool doclear, bool realcut, bool putclip)
+void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool realcut, bool putclip)
 {
        // This doesn't make sense, if there is no selection
        if (!cur.selection())
@@ -946,11 +946,6 @@ void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool doclear, bool realcu
                cur.pos() = endpos;
                cur.pit() = endpit;
 
-               // sometimes necessary
-               if (doclear
-                       && text->paragraphs()[begpit].stripLeadingSpaces(bp.track_changes))
-                       cur.fixIfBroken();
-
                // need a valid cursor. (Lgb)
                cur.clearSelection();
 
@@ -982,15 +977,15 @@ void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool doclear, bool realcu
 
 } // namespace
 
-void cutSelection(Cursor & cur, bool doclear, bool realcut)
+void cutSelection(Cursor & cur, bool realcut)
 {
-       cutSelectionHelper(cur, theCuts, doclear, realcut, true);
+       cutSelectionHelper(cur, theCuts, realcut, true);
 }
 
 
-void cutSelectionToTemp(Cursor & cur, bool doclear, bool realcut)
+void cutSelectionToTemp(Cursor & cur, bool realcut)
 {
-       cutSelectionHelper(cur, tempCut, doclear, realcut, false);
+       cutSelectionHelper(cur, tempCut, realcut, false);
 }
 
 
@@ -1300,7 +1295,7 @@ void pasteSimpleText(Cursor & cur, bool asParagraphs)
                return;
 
        cur.recordUndo();
-       cutSelection(cur, true, false);
+       cutSelection(cur, false);
        if (asParagraphs)
                cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
        else
@@ -1356,14 +1351,14 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str)
                par.insertChar(pos, *cit, font, cur.buffer()->params().track_changes);
 
        // Cut the selection
-       cutSelection(cur, true, false);
+       cutSelection(cur, false);
 }
 
 
 void replaceSelection(Cursor & cur)
 {
        if (cur.selection())
-               cutSelection(cur, true, false);
+               cutSelection(cur, false);
 }
 
 
index 540397dde99a004f021eece10957206083e544ba..ae80ac0a3163264259b1d82fa5919926dee7d89a 100644 (file)
@@ -59,9 +59,9 @@ void replaceSelection(Cursor & cur);
  *                system clipboard. Set this to false to only delete the
  *                selection.
  */
-void cutSelection(Cursor & cur, bool doclear = true, bool realcut = true);
+void cutSelection(Cursor & cur, bool realcut = true);
 /// Like cutSelection, but only put to temporary cut buffer
-void cutSelectionToTemp(Cursor & cur, bool doclear = true, bool realcut = true);
+void cutSelectionToTemp(Cursor & cur, bool realcut = true);
 
 /// Push the current selection to the cut buffer and the system clipboard.
 void copySelection(Cursor const & cur);
index ca2d06eabba30265abe53588670a65600a0d5862..bdff46efec99d179821e66a38f16cfd98e990673 100644 (file)
@@ -1481,7 +1481,7 @@ void Text::deleteWordForward(Cursor & cur, bool const force)
                cursorForwardOneWord(cur);
                cur.setSelection();
                if (force || !cur.confirmDeletion()) {
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                        cur.checkBufferStructure();
                }
        }
@@ -1499,7 +1499,7 @@ void Text::deleteWordBackward(Cursor & cur, bool const force)
                cursorBackwardOneWord(cur);
                cur.setSelection();
                if (force || !cur.confirmDeletion()) {
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                        cur.checkBufferStructure();
                }
        }
index 41760b5a7cbf64225f28040c04e9f0efa248ac6d..2158128891b220ad0650960e597283a993f0b2fd 100644 (file)
@@ -292,7 +292,7 @@ static bool doInsertInset(Cursor & cur, Text * text,
                if (cmd.action() == LFUN_INDEX_INSERT)
                                copySelectionToTemp(cur);
                        else
-                               cutSelectionToTemp(cur, false, pastesel);
+                               cutSelectionToTemp(cur, pastesel);
                        cur.clearSelection();
                        gotsel = true;
        } else if (cmd.action() == LFUN_INDEX_INSERT) {
@@ -669,7 +669,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_WORD_DELETE_FORWARD:
                if (cur.selection())
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                else
                        deleteWordForward(cur, cmd.getArg(0) == "force");
                finishChange(cur, false);
@@ -677,7 +677,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_WORD_DELETE_BACKWARD:
                if (cur.selection())
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                else
                        deleteWordBackward(cur, cmd.getArg(0) == "force");
                finishChange(cur, false);
@@ -685,7 +685,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_LINE_DELETE_FORWARD:
                if (cur.selection())
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                else
                        tm->deleteLineForward(cur);
                finishChange(cur, false);
@@ -1163,7 +1163,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        needsUpdate |= erase(cur);
                        cur.resetAnchor();
                } else {
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                        singleParUpdate = false;
                }
                moveCursor(cur, false);
@@ -1193,7 +1193,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                }
                        }
                } else {
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                        singleParUpdate = false;
                }
                break;
@@ -1280,7 +1280,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        }
                        */
                        if (cur.selection())
-                               cutSelection(cur, true, false);
+                               cutSelection(cur, false);
                        cur.insert(inset);
                        cur.forceBufferUpdate();
                        if (inset->editable() && inset->asInsetText())
@@ -1472,7 +1472,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_CUT:
-               cutSelection(cur, true, true);
+               cutSelection(cur, true);
                cur.message(_("Cut"));
                break;
 
@@ -1911,7 +1911,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // true (on).
 
                if (lyxrc.auto_region_delete && cur.selection())
-                       cutSelection(cur, false, false);
+                       cutSelection(cur, false);
                cur.clearSelection();
 
                for (char_type c : cmd.argument())
@@ -1992,7 +1992,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (cmd.argument().empty() && cur.selection()) {
                        // if command argument is empty use current selection as parameter.
                        docstring ds = cur.selectionAsString(false);
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                        FuncRequest cmd0(cmd, ds);
                        inset = createInset(cur.buffer(), cmd0);
                } else {
@@ -2459,7 +2459,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
                        cur.recordUndo();
                        if (cur.selection())
-                               cutSelection(cur, true, false);
+                               cutSelection(cur, false);
                        breakParagraph(cur);
 
                        if (cur.lastpos() != 0) {
index e5345dd0405c7cd775dfc0dbd5de582aa846c713..20ff864ed8ad7f02f101cdaf7bc126d1c3ceabae 100644 (file)
@@ -1573,7 +1573,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
                if (!cur.selection())
                        text_->deleteWordForward(cur);
                else
-                       cap::cutSelection(cur, true, false);
+                       cap::cutSelection(cur, false);
                cur.checkBufferStructure();
        }
 }
index 4b8da77ac0c33ff572c4af9904d64b7d0609d7b0..ddb13bf69f5c1166f5f1a4bf39587d875f194130 100644 (file)
@@ -1463,7 +1463,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                                changeFirstCase(repl_buffer, text_uppercase, text_uppercase);
                }
        }
-       cap::cutSelection(cur, false, false);
+       cap::cutSelection(cur, false);
        if (cur.inTexted()) {
                repl_buffer.changeLanguage(
                        repl_buffer.language(),
index d871660d516620901d563cb8eaaf304452567c23..4b19c3ce090f516fe348c5deffc197619a8df45a 100644 (file)
@@ -560,7 +560,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_CUT:
                cur.recordUndo();
-               cutSelection(cur, true, true);
+               cutSelection(cur, true);
                cur.message(_("Cut"));
                // Prevent stale position >= size crash
                // Probably not necessary anymore, see eraseSelection (gb 2005-10-09)