Do not remove character at start of paragraph when cutting

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.
This commit is contained in:
Jean-Marc Lasgouttes 2018-07-22 22:18:50 +02:00
parent 20976e81fb
commit e4dba53232
7 changed files with 26 additions and 31 deletions

View File

@ -905,7 +905,7 @@ size_type numberOfSelections()
namespace { 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 // This doesn't make sense, if there is no selection
if (!cur.selection()) if (!cur.selection())
@ -954,11 +954,6 @@ void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool doclear, bool realcu
cur.pos() = endpos; cur.pos() = endpos;
cur.pit() = endpit; cur.pit() = endpit;
// sometimes necessary
if (doclear
&& text->paragraphs()[begpit].stripLeadingSpaces(bp.track_changes))
cur.fixIfBroken();
// need a valid cursor. (Lgb) // need a valid cursor. (Lgb)
cur.clearSelection(); cur.clearSelection();
@ -990,15 +985,15 @@ void cutSelectionHelper(Cursor & cur, CutStack & cuts, bool doclear, bool realcu
} // namespace } // 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);
} }
@ -1308,7 +1303,7 @@ void pasteSimpleText(Cursor & cur, bool asParagraphs)
return; return;
cur.recordUndo(); cur.recordUndo();
cutSelection(cur, true, false); cutSelection(cur, false);
if (asParagraphs) if (asParagraphs)
cur.text()->insertStringAsParagraphs(cur, text, cur.current_font); cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
else else
@ -1364,14 +1359,14 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str)
par.insertChar(pos, *cit, font, cur.buffer()->params().track_changes); par.insertChar(pos, *cit, font, cur.buffer()->params().track_changes);
// Cut the selection // Cut the selection
cutSelection(cur, true, false); cutSelection(cur, false);
} }
void replaceSelection(Cursor & cur) void replaceSelection(Cursor & cur)
{ {
if (cur.selection()) if (cur.selection())
cutSelection(cur, true, false); cutSelection(cur, false);
} }

View File

@ -59,9 +59,9 @@ void replaceSelection(Cursor & cur);
* system clipboard. Set this to false to only delete the * system clipboard. Set this to false to only delete the
* selection. * 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 /// 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. /// Push the current selection to the cut buffer and the system clipboard.
void copySelection(Cursor const & cur); void copySelection(Cursor const & cur);

View File

@ -1484,7 +1484,7 @@ void Text::deleteWordForward(Cursor & cur, bool const force)
cursorForwardOneWord(cur); cursorForwardOneWord(cur);
cur.setSelection(); cur.setSelection();
if (force || !cur.confirmDeletion()) { if (force || !cur.confirmDeletion()) {
cutSelection(cur, true, false); cutSelection(cur, false);
cur.checkBufferStructure(); cur.checkBufferStructure();
} }
} }
@ -1502,7 +1502,7 @@ void Text::deleteWordBackward(Cursor & cur, bool const force)
cursorBackwardOneWord(cur); cursorBackwardOneWord(cur);
cur.setSelection(); cur.setSelection();
if (force || !cur.confirmDeletion()) { if (force || !cur.confirmDeletion()) {
cutSelection(cur, true, false); cutSelection(cur, false);
cur.checkBufferStructure(); cur.checkBufferStructure();
} }
} }

View File

@ -292,7 +292,7 @@ static bool doInsertInset(Cursor & cur, Text * text,
if (cmd.action() == LFUN_INDEX_INSERT) if (cmd.action() == LFUN_INDEX_INSERT)
copySelectionToTemp(cur); copySelectionToTemp(cur);
else else
cutSelectionToTemp(cur, false, pastesel); cutSelectionToTemp(cur, pastesel);
cur.clearSelection(); cur.clearSelection();
gotsel = true; gotsel = true;
} else if (cmd.action() == LFUN_INDEX_INSERT) { } else if (cmd.action() == LFUN_INDEX_INSERT) {
@ -713,7 +713,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_WORD_DELETE_FORWARD: case LFUN_WORD_DELETE_FORWARD:
if (cur.selection()) if (cur.selection())
cutSelection(cur, true, false); cutSelection(cur, false);
else else
deleteWordForward(cur, cmd.getArg(0) == "force"); deleteWordForward(cur, cmd.getArg(0) == "force");
finishChange(cur, false); finishChange(cur, false);
@ -721,7 +721,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_WORD_DELETE_BACKWARD: case LFUN_WORD_DELETE_BACKWARD:
if (cur.selection()) if (cur.selection())
cutSelection(cur, true, false); cutSelection(cur, false);
else else
deleteWordBackward(cur, cmd.getArg(0) == "force"); deleteWordBackward(cur, cmd.getArg(0) == "force");
finishChange(cur, false); finishChange(cur, false);
@ -729,7 +729,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_LINE_DELETE_FORWARD: case LFUN_LINE_DELETE_FORWARD:
if (cur.selection()) if (cur.selection())
cutSelection(cur, true, false); cutSelection(cur, false);
else else
tm->deleteLineForward(cur); tm->deleteLineForward(cur);
finishChange(cur, false); finishChange(cur, false);
@ -1207,7 +1207,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
needsUpdate |= erase(cur); needsUpdate |= erase(cur);
cur.resetAnchor(); cur.resetAnchor();
} else { } else {
cutSelection(cur, true, false); cutSelection(cur, false);
singleParUpdate = false; singleParUpdate = false;
} }
moveCursor(cur, false); moveCursor(cur, false);
@ -1237,7 +1237,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
} }
} else { } else {
cutSelection(cur, true, false); cutSelection(cur, false);
singleParUpdate = false; singleParUpdate = false;
} }
break; break;
@ -1322,7 +1322,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
*/ */
if (cur.selection()) if (cur.selection())
cutSelection(cur, true, false); cutSelection(cur, false);
cur.insert(inset); cur.insert(inset);
cur.forceBufferUpdate(); cur.forceBufferUpdate();
if (inset->editable() && inset->asInsetText()) if (inset->editable() && inset->asInsetText())
@ -1514,7 +1514,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
case LFUN_CUT: case LFUN_CUT:
cutSelection(cur, true, true); cutSelection(cur, true);
cur.message(_("Cut")); cur.message(_("Cut"));
break; break;
@ -1919,7 +1919,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// true (on). // true (on).
if (lyxrc.auto_region_delete && cur.selection()) if (lyxrc.auto_region_delete && cur.selection())
cutSelection(cur, false, false); cutSelection(cur, false);
cur.clearSelection(); cur.clearSelection();
for (char_type c : cmd.argument()) for (char_type c : cmd.argument())
@ -2000,7 +2000,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
if (cmd.argument().empty() && cur.selection()) { if (cmd.argument().empty() && cur.selection()) {
// if command argument is empty use current selection as parameter. // if command argument is empty use current selection as parameter.
docstring ds = cur.selectionAsString(false); docstring ds = cur.selectionAsString(false);
cutSelection(cur, true, false); cutSelection(cur, false);
FuncRequest cmd0(cmd, ds); FuncRequest cmd0(cmd, ds);
inset = createInset(cur.buffer(), cmd0); inset = createInset(cur.buffer(), cmd0);
} else { } else {
@ -2469,7 +2469,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
if (tclass.floats().typeExist(to_utf8(cmd.argument()))) { if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
cur.recordUndo(); cur.recordUndo();
if (cur.selection()) if (cur.selection())
cutSelection(cur, true, false); cutSelection(cur, false);
breakParagraph(cur); breakParagraph(cur);
if (cur.lastpos() != 0) { if (cur.lastpos() != 0) {

View File

@ -1564,7 +1564,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
if (!cur.selection()) if (!cur.selection())
text_->deleteWordForward(cur); text_->deleteWordForward(cur);
else else
cap::cutSelection(cur, true, false); cap::cutSelection(cur, false);
cur.checkBufferStructure(); cur.checkBufferStructure();
} }
} }

View File

@ -1463,7 +1463,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
changeFirstCase(repl_buffer, text_uppercase, text_uppercase); changeFirstCase(repl_buffer, text_uppercase, text_uppercase);
} }
} }
cap::cutSelection(cur, false, false); cap::cutSelection(cur, false);
if (cur.inTexted()) { if (cur.inTexted()) {
repl_buffer.changeLanguage( repl_buffer.changeLanguage(
repl_buffer.language(), repl_buffer.language(),

View File

@ -560,7 +560,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CUT: case LFUN_CUT:
cur.recordUndo(); cur.recordUndo();
cutSelection(cur, true, true); cutSelection(cur, true);
cur.message(_("Cut")); cur.message(_("Cut"));
// Prevent stale position >= size crash // Prevent stale position >= size crash
// Probably not necessary anymore, see eraseSelection (gb 2005-10-09) // Probably not necessary anymore, see eraseSelection (gb 2005-10-09)