> Jean-Marc Lasgouttes schrieb:
>> M-Return is supposed to be do for commands what Return would do for
>> Environments and do for environments what Return would do for
>> commands.
>>
>> However, I see now that it does not do anything interesting for
>> enumerations. I'll have to double check that.
Here is a patch that implements proper functionning of M-Return (at
least as I see it: like Return, but inverting role of environment and
non-environment). I'd be interested to have some feedback on it. This
is potentially for trunk and branch.
This is basically bug 2445
http://bugzilla.lyx.org/show_bug.cgi?id=2445
but not everybody agrees on what the behaviour should be.
JMarc
svndiff src
Index: src/Text.cpp
===================================================================
--- src/Text.cpp (révision 20240)
+++ src/Text.cpp (copie de travail)
@@ -356,7 +356,7 @@ double Text::spacing(Buffer const & buff
}
-void Text::breakParagraph(Cursor & cur, bool keep_layout)
+void Text::breakParagraph(Cursor & cur, bool inverse_logic)
{
BOOST_ASSERT(this == cur.text());
@@ -381,11 +381,9 @@ void Text::breakParagraph(Cursor & cur,
cpar.eraseChar(cur.pos(), cur.buffer().params().trackChanges);
// What should the layout for the new paragraph be?
- int preserve_layout = 0;
- if (keep_layout)
- preserve_layout = 2;
- else
- preserve_layout = layout->isEnvironment();
+ bool keep_layout = inverse_logic ?
+ !layout->isEnvironment()
+ : layout->isEnvironment();
// We need to remember this before we break the paragraph, because
// that invalidates the layout variable
@@ -395,7 +393,7 @@ void Text::breakParagraph(Cursor & cur,
bool const isempty = cpar.allowEmpty() && cpar.empty();
lyx::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
- cur.pos(), preserve_layout);
+ cur.pos(), keep_layout);
// After this, neither paragraph contains any rows!
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp (révision 20240)
+++ src/Text3.cpp (copie de travail)
@@ -574,13 +574,13 @@ void Text::dispatch(Cursor & cur, FuncRe
case LFUN_BREAK_PARAGRAPH:
cap::replaceSelection(cur);
- breakParagraph(cur, 0);
+ breakParagraph(cur, false);
cur.resetAnchor();
break;
case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
cap::replaceSelection(cur);
- breakParagraph(cur, 1);
+ breakParagraph(cur, true);
cur.resetAnchor();
break;
@@ -591,7 +591,7 @@ void Text::dispatch(Cursor & cur, FuncRe
if (cur.pos() == 0)
cur.paragraph().params().labelWidthString(docstring());
else
- breakParagraph(cur, 0);
+ breakParagraph(cur, false);
cur.resetAnchor();
break;
}
Index: src/paragraph_funcs.h
===================================================================
--- src/paragraph_funcs.h (révision 20240)
+++ src/paragraph_funcs.h (copie de travail)
@@ -27,9 +27,9 @@ class ParagraphList;
/**
* This breaks a paragraph at the specified position.
* The new paragraph will:
- * get the default layout, when flag == 0
- * will inherit the existing one, except for depth, when flag == 1
- * will inherit the existing one, including depth, when flag == 2
+ * - Decrease depth by one (or chenge layout to default layout when
+ * keep_layout == false
+ * - keep current depth and layout when keep_layout == true
* Be aware that the old or new paragraph does not contain any rows
* after this.
*/
@@ -37,7 +37,7 @@ void breakParagraph(BufferParams const &
ParagraphList & paragraphs,
pit_type par,
pos_type pos,
- int flag);
+ bool keep_layout);
///
void breakParagraphConservative(BufferParams const & bparams,
Index: src/paragraph_funcs.cpp
===================================================================
--- src/paragraph_funcs.cpp (révision 20240)
+++ src/paragraph_funcs.cpp (copie de travail)
@@ -60,7 +60,8 @@ static bool moveItem(Paragraph & fromPar
void breakParagraph(BufferParams const & bparams,
- ParagraphList & pars, pit_type par_offset, pos_type pos, int flag)
+ ParagraphList & pars, pit_type par_offset, pos_type pos,
+ bool keep_layout)
{
// create a new paragraph, and insert into the list
ParagraphList::iterator tmp =
@@ -76,7 +77,7 @@ void breakParagraph(BufferParams const &
tmp->setInsetOwner(par.inInset());
// layout stays the same with latex-environments
- if (flag) {
+ if (keep_layout) {
tmp->layout(par.layout());
tmp->setLabelWidthString(par.params().labelWidthString());
tmp->params().depth(par.params().depth());
@@ -90,7 +91,7 @@ void breakParagraph(BufferParams const &
bool const isempty = (par.allowEmpty() && par.empty());
- if (!isempty && (par.size() > pos || par.empty() || flag == 2)) {
+ if (!isempty && (par.size() > pos || par.empty())) {
tmp->layout(par.layout());
tmp->params().align(par.params().align());
tmp->setLabelWidthString(par.params().labelWidthString());
@@ -142,7 +143,7 @@ void breakParagraph(BufferParams const &
}
// layout stays the same with latex-environments
- if (flag) {
+ if (keep_layout) {
par.layout(tmp->layout());
par.setLabelWidthString(tmp->params().labelWidthString());
par.params().depth(tmp->params().depth());
Index: src/Text.h
===================================================================
--- src/Text.h (révision 20240)
+++ src/Text.h (copie de travail)
@@ -75,7 +75,7 @@ public:
Font const & font, bool toggleall = false);
/// what you expect when pressing \<enter\> at cursor position
- void breakParagraph(Cursor & cur, bool keep_layout = false);
+ void breakParagraph(Cursor & cur, bool inverse_logic = false);
/// set layout over selection
void setLayout(Buffer const & buffer, pit_type start, pit_type end,