/**
* This breaks a paragraph at the specified position.
* The new paragraph will:
- * - Decrease depth by one (or change layout to default layout) when
- * keep_layout == false
- * - keep current depth and layout when keep_layout == true
+ * - change layout to default layout when keep_layout == false
+ * - keep layout when keep_layout == true
*/
static void breakParagraph(Text & text, pit_type par_offset, pos_type pos,
bool keep_layout)
// remember to set the inset_owner
tmp->setInsetOwner(&par.inInset());
- // without doing that we get a crash when typing <Return> at the
- // end of a paragraph
- tmp->setPlainOrDefaultLayout(bparams.documentClass());
+ tmp->params().depth(par.params().depth());
if (keep_layout) {
tmp->setLayout(par.layout());
tmp->setLabelWidthString(par.params().labelWidthString());
- tmp->params().depth(par.params().depth());
- } else if (par.params().depth() > 0) {
- Paragraph const & hook = pars[text.outerHook(par_offset)];
- tmp->setLayout(hook.layout());
- // not sure the line below is useful
- tmp->setLabelWidthString(par.params().labelWidthString());
- tmp->params().depth(hook.params().depth());
- }
+ } else
+ tmp->setPlainOrDefaultLayout(bparams.documentClass());
bool const isempty = (par.allowEmpty() && par.empty());
Layout priorlayout;
Cursor c(cur.bv());
c.setCursor(cur.selectionBegin());
- for ( ; c <= cur.selectionEnd() ; ++c.pit()) {
+ pit_type const last_pit = cur.selectionEnd().pit();
+ for ( ; c.pit() <= last_pit ; ++c.pit()) {
Paragraph & par = c.paragraph();
ParagraphParameters params = par.params();
params.read(argument, merge);
Layout priorlayout;
Cursor c(cur.bv());
c.setCursor(cur.selectionBegin());
- for ( ; c < cur.selectionEnd() ; ++c.pit()) {
+ pit_type const last_pit = cur.selectionEnd().pit();
+ for ( ; c.pit() <= last_pit ; ++c.pit()) {
Paragraph & par = c.paragraph();
// Changes to label width string apply to all paragraphs
// with same layout in a sequence.
}
-void outline(OutlineOp mode, Cursor & cur, Text * text)
+void outline(OutlineOp mode, Cursor & cur, bool local)
{
Buffer & buf = *cur.buffer();
+ Text & text = *cur.text();
pit_type & pit = cur.pit();
- ParagraphList & pars = buf.text().paragraphs();
+ ParagraphList & pars = text.paragraphs();
ParagraphList::iterator const bgn = pars.begin();
// The first paragraph of the area to be copied:
ParagraphList::iterator start = pars.iterator_at(pit);
ParagraphList::iterator const end = pars.end();
depth_type const current_depth = cur.paragraph().params().depth();
- int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
+ int const thistoclevel = text.getTocLevel(distance(bgn, start));
int toclevel;
// Move out (down) from this section header
if (finish != end)
++finish;
- // Seek the one (on same level) below
- for (; finish != end; ++finish) {
- toclevel = buf.text().getTocLevel(distance(bgn, finish));
- if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
- break;
+ if (!local || (mode != OutlineIn && mode != OutlineOut)) {
+ // Seek the one (on same level) below
+ for (; finish != end; ++finish) {
+ toclevel = text.getTocLevel(distance(bgn, finish));
+ if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
+ break;
+ }
}
switch (mode) {
// Search previous same-level header above
do {
--dest;
- toclevel = buf.text().getTocLevel(distance(bgn, dest));
+ toclevel = text.getTocLevel(distance(bgn, dest));
} while(dest != bgn
&& (toclevel == Layout::NOT_IN_TOC
|| toclevel > thistoclevel));
// Get the parent paragraph (outer in nested context)
pit_type const parent =
before->params().depth() > current_depth
- ? text->depthHook(distance(bgn, before), current_depth)
+ ? text.depthHook(distance(bgn, before), current_depth)
: distance(bgn, before);
// If a environment with same layout preceeds the moved one in the new
// position, and there is no separator yet, insert one.
ParagraphList::iterator dest = next(finish, 1);
// Go further down to find header to insert in front of:
for (; dest != end; ++dest) {
- toclevel = buf.text().getTocLevel(distance(bgn, dest));
+ toclevel = text.getTocLevel(distance(bgn, dest));
if (toclevel != Layout::NOT_IN_TOC
&& toclevel <= thistoclevel)
break;
// Get the parent paragraph (outer in nested context)
pit_type const parent =
before->params().depth() > current_depth
- ? text->depthHook(distance(bgn, before), current_depth)
+ ? text.depthHook(distance(bgn, before), current_depth)
: distance(bgn, before);
// If a environment with same layout preceeds the moved one in the new
// position, and there is no separator yet, insert one.
ParagraphList::iterator cstart = start;
bool strucchange = false;
for (; cstart != finish; ++cstart) {
- toclevel = buf.text().getTocLevel(distance(bgn, cstart));
+ toclevel = text.getTocLevel(distance(bgn, cstart));
if (toclevel == Layout::NOT_IN_TOC)
continue;
pit_type const len = distance(start, finish);
buf.undo().recordUndo(cur, pit, pit + len - 1);
for (; start != finish; ++start) {
- toclevel = buf.text().getTocLevel(distance(bgn, start));
+ toclevel = text.getTocLevel(distance(bgn, start));
if (toclevel == Layout::NOT_IN_TOC)
continue;
case LFUN_OUTLINE_UP: {
pos_type const opos = cur.pos();
- outline(OutlineUp, cur, this);
+ outline(OutlineUp, cur, false);
setCursor(cur, cur.pit(), opos);
cur.forceBufferUpdate();
needsUpdate = true;
case LFUN_OUTLINE_DOWN: {
pos_type const opos = cur.pos();
- outline(OutlineDown, cur, this);
+ outline(OutlineDown, cur, false);
setCursor(cur, cur.pit(), opos);
cur.forceBufferUpdate();
needsUpdate = true;
}
case LFUN_OUTLINE_IN:
- outline(OutlineIn, cur, this);
+ outline(OutlineIn, cur, cmd.getArg(0) == "local");
cur.forceBufferUpdate();
needsUpdate = true;
break;
case LFUN_OUTLINE_OUT:
- outline(OutlineOut, cur, this);
+ outline(OutlineOut, cur, cmd.getArg(0) == "local");
cur.forceBufferUpdate();
needsUpdate = true;
break;
s = from_ascii("Flex:") + s;
if (!cur.buffer()->params().documentClass().hasInsetLayout(s))
enable = false;
+ else if (!cur.paragraph().allowedInContext(cur, cur.buffer()->params().documentClass().insetLayout(s)))
+ enable = false;
else {
InsetLyXType ilt =
cur.buffer()->params().documentClass().insetLayout(s).lyxtype();
case LFUN_OUTLINE_DOWN:
case LFUN_OUTLINE_IN:
case LFUN_OUTLINE_OUT:
- // FIXME: LyX is not ready for outlining within inset.
- enable = isMainText()
- && cur.buffer()->text().getTocLevel(cur.pit()) != Layout::NOT_IN_TOC;
+ enable = cur.text()->getTocLevel(cur.pit()) != Layout::NOT_IN_TOC;
break;
case LFUN_NEWLINE_INSERT: