From: Vincent van Ravesteijn Date: Sun, 3 May 2009 18:58:00 +0000 (+0000) Subject: Introduce new LFUN_SECTION_SELECT. When this lfun is called and the cursor is in... X-Git-Tag: 2.0.0~6681 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0da78f8bbd2f5961e624880a9ce3f73a320b83f2;p=features.git Introduce new LFUN_SECTION_SELECT. When this lfun is called and the cursor is in a section heading, the whole section is selected. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29518 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/FuncCode.h b/src/FuncCode.h index 33cca3a56c..d2257a4e37 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -428,6 +428,7 @@ enum FuncCode // 330 LFUN_MATH_BIGDELIM, LFUN_MATH_FONT_STYLE, + LFUN_SECTION_SELECT, // vfr, 20090503 LFUN_LASTACTION // end of the table diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index dc8121a0bb..d6d540d723 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3273,6 +3273,17 @@ void LyXAction::init() */ { LFUN_BUFFER_ZOOM_OUT, "buffer-zoom-out", ReadOnly, Buffer }, +/*! + * \var lyx::FuncCode lyx::LFUN_SECTION_SELECT + * \li Action: Selects the whole section. + * \li Notion: The cursor should be in a section heading + before calling this lfun. + * \li Syntax: section-select + * \li Origin: vfr, 05 May 2009 + * \endvar + */ + { LFUN_SECTION_SELECT, "section-select", ReadOnly, Edit }, + { LFUN_NOACTION, "", Noop, Hidden } #ifndef DOXYGEN_SHOULD_SKIP_THIS }; diff --git a/src/Text3.cpp b/src/Text3.cpp index f306a6d2de..c4c4524a96 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -329,9 +329,8 @@ static void outline(OutlineOp mode, Cursor & cur) // Seek the one (on same level) below for (; finish != end; ++finish) { toclevel = finish->layout().toclevel; - if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) { + if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) break; - } } switch (mode) { @@ -373,9 +372,8 @@ static void outline(OutlineOp mode, Cursor & cur) for (; dest != end; ++dest) { toclevel = dest->layout().toclevel; if (toclevel != Layout::NOT_IN_TOC - && toclevel <= thistoclevel) { + && toclevel <= thistoclevel) break; - } } // One such was found: pit_type newpit = distance(bgn, dest); @@ -709,6 +707,42 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) needsUpdate |= tm.cursorEnd(cur); break; + case LFUN_SECTION_SELECT: { + Buffer & buf = *cur.buffer(); + pit_type & pit = cur.pit(); + ParagraphList & pars = buf.text().paragraphs(); + ParagraphList::iterator bgn = pars.begin(); + // The first paragraph of the area to be selected: + ParagraphList::iterator start = boost::next(bgn, pit); + // The final paragraph of area to be selected: + ParagraphList::iterator finish = start; + ParagraphList::iterator end = pars.end(); + + setCursor(cur, cur.pit(), 0); + Cursor old_cur = cur; + needsUpdate |= cur.selHandle(true); + + int const thistoclevel = start->layout().toclevel; + if (thistoclevel == Layout::NOT_IN_TOC) + break; + + // Move out (down) from this section header + if (finish != end) + ++finish; + + int toclevel; + // Seek the one (on same level) below + for (; finish != end; ++finish, cur.forwardPar()) { + toclevel = finish->layout().toclevel; + if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) + break; + } + setCursor(cur, cur.pit(), cur.lastpos()); + + needsUpdate |= cur != old_cur; + break; + } + case LFUN_WORD_RIGHT: case LFUN_WORD_RIGHT_SELECT: if (lyxrc.visual_cursor) { @@ -2363,6 +2397,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_WORD_RIGHT_SELECT: case LFUN_WORD_LEFT_SELECT: case LFUN_WORD_SELECT: + case LFUN_SECTION_SELECT: case LFUN_PARAGRAPH_UP: case LFUN_PARAGRAPH_DOWN: case LFUN_LINE_BEGIN: