On Tue, Oct 09, 2007 at 10:47:54AM +0300, Martin Vermeer wrote:
...
> Now _my_ question:
>
> Looking at Text3.cpp, I find the passage
>
> if (gotsel && pastesel) {
> lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
> // reset first par to default
> if (cur.lastpit() != 0 || cur.lastpos() != 0) {
> LayoutPtr const layout =
>
> cur.buffer().params().getTextClass().defaultLayout();
>
> cur.text()->paragraphs().begin()->layout(layout);
> }
> }
>
> If I read this correctly, what's happening is that if an inset is
> created around selected text, and under some circumstances the first
> paragraph inside the inset is reset to default layout.
>
> Now my question is, what precisely is happening here, and is this what
> we really want? Those 'some circumstances' look suspicious.
>
> I am asking because we could use the multipar inset layout parameter
> for this. Reset to default only if multipar = false, because these are
> typically small insets embedded in a running paragraph. When selecting
> and enclosing multiple paragraphs in an inset, I find the resetting of
> the first paragraph often irritating.
>
> OTOH if the surrounding text para becomes empty after the cut, I think
> resetting _that_ to default makes sense. Think enclosing a section
> header plus text into a (branch) inset. Or a numbered/bullet list.
The attached patch implements this (IMHO saner) behaviour.
BTW the FIXME has been broken forever. As a fix, merging the paragraphs may
produce minimum information loss for the user.
- Martin
Index: Text3.cpp
===================================================================
--- Text3.cpp (revision 20732)
+++ Text3.cpp (working copy)
@@ -209,11 +209,20 @@
if (gotsel && pastesel) {
lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
- // reset first par to default
- if (cur.lastpit() != 0 || cur.lastpos() != 0) {
+ InsetLayout il = inset->getLayout(cur.buffer().params());
+ if (!il.multipar) {
+ // reset first par to default
LayoutPtr const layout =
cur.buffer().params().getTextClass().defaultLayout();
cur.text()->paragraphs().begin()->layout(layout);
+ // FIXME do something about pasted
+ // multiple paragraphs (merge them?)
+ } else {
+ // reset surrounding par to default
+ docstring const layoutname =
+ cur.buffer().params().getTextClass().defaultLayoutName();
+ cur.leaveInset(*inset);
+ text->setLayout(cur, layoutname);
}
}
}
Index: ../lib/layouts/stdinsets.inc
===================================================================
--- ../lib/layouts/stdinsets.inc (revision 20699)
+++ ../lib/layouts/stdinsets.inc (working copy)
@@ -12,6 +12,7 @@
Color Red
Size Small
EndFont
+ MultiPar true
End
InsetLayout Foot
@@ -22,6 +23,7 @@
Color Green
Size Small
EndFont
+ MultiPar true
End
InsetLayout Note:Comment
@@ -33,6 +35,7 @@
Color comment
Size Small
EndFont
+ MultiPar true
End
@@ -45,6 +48,7 @@
Color note
Size Small
EndFont
+ MultiPar true
End
InsetLayout Note:Greyedout
@@ -56,6 +60,7 @@
Color greyedout
Size Small
EndFont
+ MultiPar true
End
InsetLayout Note:Framed
@@ -67,6 +72,7 @@
Color greyedout
Size Small
EndFont
+ MultiPar true
End
InsetLayout Note:Shaded
@@ -78,6 +84,7 @@
Color greyedout
Size Small
EndFont
+ MultiPar true
End
InsetLayout ERT
@@ -91,6 +98,7 @@
Color latex
Size Small
EndFont
+ MultiPar true
End
InsetLayout Branch
@@ -99,6 +107,7 @@
Color Red
Size Small
EndFont
+ MultiPar true
End
InsetLayout Index
@@ -114,5 +123,6 @@
Color Green
Size Small
EndFont
+ MultiPar false
End