3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Angus Leeming
11 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
20 #include "BranchList.h"
22 #include "BufferParams.h"
23 #include "BufferView.h"
25 #include "CutAndPaste.h"
26 #include "DispatchResult.h"
28 #include "FloatList.h"
29 #include "FuncStatus.h"
30 #include "FuncRequest.h"
31 #include "InsetList.h"
35 #include "LyXAction.h"
39 #include "Paragraph.h"
40 #include "ParagraphParameters.h"
41 #include "SpellChecker.h"
42 #include "TextClass.h"
43 #include "TextMetrics.h"
44 #include "Thesaurus.h"
45 #include "WordLangTuple.h"
47 #include "frontends/alert.h"
48 #include "frontends/Application.h"
49 #include "frontends/Clipboard.h"
50 #include "frontends/Selection.h"
52 #include "insets/InsetArgument.h"
53 #include "insets/InsetCollapsible.h"
54 #include "insets/InsetCommand.h"
55 #include "insets/InsetExternal.h"
56 #include "insets/InsetFloat.h"
57 #include "insets/InsetFloatList.h"
58 #include "insets/InsetGraphics.h"
59 #include "insets/InsetGraphicsParams.h"
60 #include "insets/InsetInfo.h"
61 #include "insets/InsetIPAMacro.h"
62 #include "insets/InsetNewline.h"
63 #include "insets/InsetQuotes.h"
64 #include "insets/InsetSpecialChar.h"
65 #include "insets/InsetText.h"
66 #include "insets/InsetWrap.h"
68 #include "support/convert.h"
69 #include "support/debug.h"
70 #include "support/docstring_list.h"
71 #include "support/filetools.h"
72 #include "support/gettext.h"
73 #include "support/lassert.h"
74 #include "support/limited_stack.h"
75 #include "support/lstrings.h"
77 #include "mathed/InsetMathHull.h"
78 #include "mathed/InsetMathMacroTemplate.h"
86 using namespace lyx::support;
90 using cap::copySelection;
91 using cap::copySelectionToTemp;
92 using cap::cutSelection;
93 using cap::cutSelectionToTemp;
94 using cap::pasteFromStack;
95 using cap::pasteFromTemp;
96 using cap::pasteClipboardText;
97 using cap::pasteClipboardGraphics;
98 using cap::replaceSelection;
99 using cap::grabAndEraseSelection;
100 using cap::selClearOrDel;
101 using cap::pasteSimpleText;
102 using frontend::Clipboard;
105 typedef limited_stack<pair<docstring, Font>> FontStack;
106 static FontStack freeFonts(15);
107 static bool toggleall = false;
109 static void toggleAndShow(Cursor & cur, Text * text,
110 Font const & font, bool togall = true)
112 text->toggleFree(cur, font, togall);
114 if (font.language() != ignore_language ||
115 font.fontInfo().number() != FONT_IGNORE) {
116 TextMetrics const & tm = cur.bv().textMetrics(text);
117 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
118 cur.real_current_font))
119 text->setCursor(cur, cur.pit(), cur.pos(),
120 false, !cur.boundary());
121 if (font.language() != ignore_language)
122 // We need a buffer update if we change the language
123 // (e.g., with info insets or if the selection contains
125 cur.forceBufferUpdate();
130 static void moveCursor(Cursor & cur, bool selecting)
132 if (selecting || cur.mark())
137 static void finishChange(Cursor & cur, bool selecting)
140 moveCursor(cur, selecting);
144 static void mathDispatch(Cursor & cur, FuncRequest const & cmd)
147 docstring sel = cur.selectionAsString(false);
149 // It may happen that sel is empty but there is a selection
150 replaceSelection(cur);
152 // Is this a valid formula?
156 #ifdef ENABLE_ASSERTIONS
157 const int old_pos = cur.pos();
159 cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
160 #ifdef ENABLE_ASSERTIONS
161 LATTEST(old_pos == cur.pos());
163 cur.nextInset()->edit(cur, true);
164 if (cmd.action() != LFUN_MATH_MODE)
165 // LFUN_MATH_MODE has a different meaning in math mode
168 InsetMathHull * formula = new InsetMathHull(cur.buffer());
169 string const selstr = to_utf8(sel);
170 istringstream is(selstr);
173 if (!formula->readQuiet(lex)) {
174 // No valid formula, let's try with delims
175 is.str("$" + selstr + "$");
177 if (!formula->readQuiet(lex)) {
178 // Still not valid, leave it as is
186 cur.nextInset()->edit(cur, true);
187 LASSERT(cur.inMathed(), return);
191 cur.pos() = cur.lastpos();
192 if (cmd.action() != LFUN_MATH_MODE)
193 // LFUN_MATH_MODE has a different meaning in math mode
195 cur.clearSelection();
196 cur.pos() = cur.lastpos();
200 cur.message(from_utf8(N_("Math editor mode")));
202 cur.message(from_utf8(N_("No valid math formula")));
206 void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
208 LASSERT(cmd.action() == LFUN_REGEXP_MODE, return);
209 if (cur.inRegexped()) {
210 cur.message(_("Already in regular expression mode"));
214 docstring sel = cur.selectionAsString(false);
216 // It may happen that sel is empty but there is a selection
217 replaceSelection(cur);
219 cur.insert(new InsetMathHull(cur.buffer(), hullRegexp));
220 cur.nextInset()->edit(cur, true);
223 cur.message(_("Regexp editor mode"));
227 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
230 cap::replaceSelection(cur);
231 cur.insert(new InsetSpecialChar(kind));
236 static void ipaChar(Cursor & cur, InsetIPAChar::Kind kind)
239 cap::replaceSelection(cur);
240 cur.insert(new InsetIPAChar(kind));
245 static bool doInsertInset(Cursor & cur, Text * text,
246 FuncRequest const & cmd, bool edit,
247 bool pastesel, bool resetfont = false)
249 Buffer & buffer = cur.bv().buffer();
250 BufferParams const & bparams = buffer.params();
251 Inset * inset = createInset(&buffer, cmd);
255 if (InsetCollapsible * ci = inset->asInsetCollapsible())
256 ci->setButtonLabel();
259 if (cmd.action() == LFUN_ARGUMENT_INSERT) {
260 bool cotextinsert = false;
261 InsetArgument * const ia = static_cast<InsetArgument *>(inset);
262 Layout const & lay = cur.paragraph().layout();
263 Layout::LaTeXArgMap args = lay.args();
264 Layout::LaTeXArgMap::const_iterator const lait = args.find(ia->name());
265 if (lait != args.end())
266 cotextinsert = (*lait).second.insertcotext;
268 InsetLayout const & il = cur.inset().getLayout();
270 Layout::LaTeXArgMap::const_iterator const ilait = args.find(ia->name());
271 if (ilait != args.end())
272 cotextinsert = (*ilait).second.insertcotext;
274 // The argument requests to insert a copy of the co-text to the inset
277 // If we have a selection within a paragraph, use this
278 if (cur.selection() && cur.selBegin().pit() == cur.selEnd().pit())
279 ds = cur.selectionAsString(false);
280 // else use the whole paragraph
282 ds = cur.paragraph().asString();
283 text->insertInset(cur, inset);
284 ia->init(cur.paragraph());
286 inset->edit(cur, true);
287 // Now put co-text into inset
288 Font const f(inherit_font, cur.current_font.language());
290 cur.text()->insertStringAsLines(cur, ds, f);
291 cur.leaveInset(*inset);
298 bool move_layout = false;
299 if (cur.selection()) {
300 if (cmd.action() == LFUN_INDEX_INSERT)
301 copySelectionToTemp(cur);
303 cutSelectionToTemp(cur, pastesel);
304 /* Move layout information inside the inset if the whole
305 * paragraph and the inset allows setting layout
306 * FIXME: this does not work as expected when change tracking is on
307 * However, we do not really know what to do in this case.
308 * FIXME: figure out a good test in the environment case (see #12251).
310 if (cur.paragraph().layout().isCommand()
311 && cur.paragraph().empty()
312 && !inset->forcePlainLayout()) {
313 cur.paragraph().setPlainOrDefaultLayout(bparams.documentClass());
317 cur.clearSelection();
319 } else if (cmd.action() == LFUN_INDEX_INSERT) {
320 gotsel = text->selectWordWhenUnderCursor(cur, WHOLE_WORD);
321 copySelectionToTemp(cur);
322 cur.clearSelection();
324 text->insertInset(cur, inset);
326 InsetText * inset_text = inset->asInsetText();
328 Font const & font = inset->inheritFont()
329 ? cur.bv().textMetrics(text).displayFont(cur.pit(), cur.pos())
331 inset_text->setOuterFont(cur.bv(), font.fontInfo());
334 if (cmd.action() == LFUN_ARGUMENT_INSERT) {
335 InsetArgument * const ia = static_cast<InsetArgument *>(inset);
336 ia->init(cur.paragraph());
340 inset->edit(cur, true);
342 if (!gotsel || !pastesel)
345 pasteFromTemp(cur, cur.buffer()->errorList("Paste"));
346 cur.buffer()->errors("Paste");
347 cur.clearSelection(); // bug 393
351 // Reset of font (not language) is requested.
352 // Used by InsetIndex (#11961).
353 Language const * lang = cur.getFont().language();
354 Font font(bparams.getFont().fontInfo(), lang);
355 cur.paragraph().resetFonts(font);
357 inset_text->fixParagraphsFont();
360 /* If the containing paragraph has kept its layout, reset the
361 * layout of the first paragraph of the inset.
364 cur.paragraph().setPlainOrDefaultLayout(bparams.documentClass());
365 // FIXME: what does this do?
366 if (cmd.action() == LFUN_FLEX_INSERT)
369 cur.leaveInset(*inset);
370 if (cmd.action() == LFUN_PREVIEW_INSERT
371 || cmd.action() == LFUN_IPA_INSERT)
373 notifyCursorLeavesOrEnters(old, cur);
375 cur.leaveInset(*inset);
376 // reset surrounding par to default
377 DocumentClass const & dc = bparams.documentClass();
378 docstring const layoutname = inset->usePlainLayout()
379 ? dc.plainLayoutName()
380 : dc.defaultLayoutName();
381 text->setLayout(cur, layoutname);
387 /// the type of outline operation
389 OutlineUp, // Move this header with text down
390 OutlineDown, // Move this header with text up
391 OutlineIn, // Make this header deeper
392 OutlineOut // Make this header shallower
396 static void insertSeparator(Cursor const & cur, depth_type const depth)
398 Buffer & buf = *cur.buffer();
399 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
400 DocumentClass const & tc = buf.params().documentClass();
401 lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") + tc.plainLayout().name()
402 + from_ascii("\" ignoreautonests")));
403 // FIXME: Bibitem mess!
404 if (cur.prevInset() && cur.prevInset()->lyxCode() == BIBITEM_CODE)
405 lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_BACKWARD));
406 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
407 while (cur.paragraph().params().depth() > depth)
408 lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
412 static void outline(OutlineOp mode, Cursor & cur, Text * text)
414 Buffer & buf = *cur.buffer();
415 pit_type & pit = cur.pit();
416 ParagraphList & pars = buf.text().paragraphs();
417 ParagraphList::iterator const bgn = pars.begin();
418 // The first paragraph of the area to be copied:
419 ParagraphList::iterator start = pars.iterator_at(pit);
420 // The final paragraph of area to be copied:
421 ParagraphList::iterator finish = start;
422 ParagraphList::iterator const end = pars.end();
423 depth_type const current_depth = cur.paragraph().params().depth();
425 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
428 // Move out (down) from this section header
432 // Seek the one (on same level) below
433 for (; finish != end; ++finish) {
434 toclevel = buf.text().getTocLevel(distance(bgn, finish));
435 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
441 if (start == pars.begin())
444 ParagraphList::iterator dest = start;
445 // Move out (up) from this header
448 // Search previous same-level header above
451 toclevel = buf.text().getTocLevel(distance(bgn, dest));
453 && (toclevel == Layout::NOT_IN_TOC
454 || toclevel > thistoclevel));
455 // Not found; do nothing
456 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
458 pit_type newpit = distance(bgn, dest);
459 pit_type const len = distance(start, finish);
460 pit_type const deletepit = pit + len;
461 buf.undo().recordUndo(cur, newpit, deletepit - 1);
462 // If we move an environment upwards, make sure it is
463 // separated from its new neighbour below:
464 // If an environment of the same layout follows, and the moved
465 // paragraph sequence does not end with a separator, insert one.
466 ParagraphList::iterator lastmoved = finish;
468 if (start->layout().isEnvironment()
469 && dest->layout() == start->layout()
470 && !lastmoved->isEnvSeparator(lastmoved->beginOfBody())) {
471 cur.pit() = distance(bgn, lastmoved);
472 cur.pos() = cur.lastpos();
473 insertSeparator(cur, current_depth);
476 // Likewise, if we moved an environment upwards, make sure it
477 // is separated from its new neighbour above.
478 // The paragraph before the target of movement
480 ParagraphList::iterator before = dest;
482 // Get the parent paragraph (outer in nested context)
483 pit_type const parent =
484 before->params().depth() > current_depth
485 ? text->depthHook(distance(bgn, before), current_depth)
486 : distance(bgn, before);
487 // If a environment with same layout preceeds the moved one in the new
488 // position, and there is no separator yet, insert one.
489 if (start->layout().isEnvironment()
490 && pars[parent].layout() == start->layout()
491 && !before->isEnvSeparator(before->beginOfBody())) {
492 cur.pit() = distance(bgn, before);
493 cur.pos() = cur.lastpos();
494 insertSeparator(cur, current_depth);
498 newpit = distance(bgn, dest);
499 pars.splice(dest, start, finish);
507 // Go one down from *this* header:
508 ParagraphList::iterator dest = next(finish, 1);
509 // Go further down to find header to insert in front of:
510 for (; dest != end; ++dest) {
511 toclevel = buf.text().getTocLevel(distance(bgn, dest));
512 if (toclevel != Layout::NOT_IN_TOC
513 && toclevel <= thistoclevel)
516 // One such was found, so go on...
517 // If we move an environment downwards, make sure it is
518 // separated from its new neighbour above.
519 pit_type newpit = distance(bgn, dest);
520 buf.undo().recordUndo(cur, pit, newpit - 1);
521 // The paragraph before the target of movement
522 ParagraphList::iterator before = dest;
524 // Get the parent paragraph (outer in nested context)
525 pit_type const parent =
526 before->params().depth() > current_depth
527 ? text->depthHook(distance(bgn, before), current_depth)
528 : distance(bgn, before);
529 // If a environment with same layout preceeds the moved one in the new
530 // position, and there is no separator yet, insert one.
531 if (start->layout().isEnvironment()
532 && pars[parent].layout() == start->layout()
533 && !before->isEnvSeparator(before->beginOfBody())) {
534 cur.pit() = distance(bgn, before);
535 cur.pos() = cur.lastpos();
536 insertSeparator(cur, current_depth);
539 // Likewise, make sure moved environments are separated
540 // from their new neighbour below:
541 // If an environment of the same layout follows, and the moved
542 // paragraph sequence does not end with a separator, insert one.
543 ParagraphList::iterator lastmoved = finish;
546 && start->layout().isEnvironment()
547 && dest->layout() == start->layout()
548 && !lastmoved->isEnvSeparator(lastmoved->beginOfBody())) {
549 cur.pit() = distance(bgn, lastmoved);
550 cur.pos() = cur.lastpos();
551 insertSeparator(cur, current_depth);
554 newpit = distance(bgn, dest);
555 pit_type const len = distance(start, finish);
556 pars.splice(dest, start, finish);
557 cur.pit() = newpit - len;
562 pit_type const len = distance(start, finish);
563 buf.undo().recordUndo(cur, pit, pit + len - 1);
564 for (; start != finish; ++start) {
565 toclevel = buf.text().getTocLevel(distance(bgn, start));
566 if (toclevel == Layout::NOT_IN_TOC)
569 DocumentClass const & tc = buf.params().documentClass();
570 int const newtoclevel =
571 (mode == OutlineIn ? toclevel + 1 : toclevel - 1);
572 LabelType const oldlabeltype = start->layout().labeltype;
574 for (auto const & lay : tc) {
575 if (lay.toclevel == newtoclevel &&
576 lay.labeltype == oldlabeltype) {
577 start->setLayout(lay);
588 void Text::number(Cursor & cur)
590 FontInfo font = ignore_font;
591 font.setNumber(FONT_TOGGLE);
592 toggleAndShow(cur, this, Font(font, ignore_language));
596 bool Text::isRTL(pit_type const pit) const
598 Buffer const & buffer = owner_->buffer();
599 return pars_[pit].isRTL(buffer.params());
605 Language const * getLanguage(Cursor const & cur, string const & lang)
607 return lang.empty() ? cur.getFont().language() : languages.getLanguage(lang);
611 docstring resolveLayout(docstring layout, DocIterator const & dit)
613 Paragraph const & par = dit.paragraph();
614 DocumentClass const & tclass = dit.buffer()->params().documentClass();
617 layout = tclass.defaultLayoutName();
619 if (dit.inset().forcePlainLayout(dit.idx()))
620 // in this case only the empty layout is allowed
621 layout = tclass.plainLayoutName();
622 else if (par.usePlainLayout()) {
623 // in this case, default layout maps to empty layout
624 if (layout == tclass.defaultLayoutName())
625 layout = tclass.plainLayoutName();
627 // otherwise, the empty layout maps to the default
628 if (layout == tclass.plainLayoutName())
629 layout = tclass.defaultLayoutName();
632 // If the entry is obsolete, use the new one instead.
633 if (tclass.hasLayout(layout)) {
634 docstring const & obs = tclass[layout].obsoleted_by();
638 if (!tclass.hasLayout(layout))
644 bool isAlreadyLayout(docstring const & layout, CursorData const & cur)
646 ParagraphList const & pars = cur.text()->paragraphs();
648 pit_type pit = cur.selBegin().pit();
649 pit_type const epit = cur.selEnd().pit() + 1;
650 for ( ; pit != epit; ++pit)
651 if (pars[pit].layout().name() != layout)
661 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
663 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
665 // Dispatch if the cursor is inside the text. It is not the
666 // case for context menus (bug 5797).
667 if (cur.text() != this) {
672 BufferView * bv = &cur.bv();
673 TextMetrics * tm = &bv->textMetrics(this);
674 if (!tm->contains(cur.pit())) {
675 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
676 tm = &bv->textMetrics(this);
679 // FIXME: We use the update flag to indicates wether a singlePar or a
680 // full screen update is needed. We reset it here but shall we restore it
682 cur.noScreenUpdate();
684 LBUFERR(this == cur.text());
686 // NOTE: This should NOT be a reference. See commit 94a5481a.
687 CursorSlice const oldTopSlice = cur.top();
688 bool const oldBoundary = cur.boundary();
689 bool const oldSelection = cur.selection();
690 // Signals that, even if needsUpdate == false, an update of the
691 // cursor paragraph is required
692 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action(),
693 LyXAction::SingleParUpdate);
694 // Signals that a full-screen update is required
695 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action(),
696 LyXAction::NoUpdate) || singleParUpdate);
697 bool const last_misspelled = lyxrc.spellcheck_continuously
698 && cur.paragraph().isMisspelled(cur.pos(), true);
700 FuncCode const act = cmd.action();
703 case LFUN_PARAGRAPH_MOVE_DOWN: {
704 pit_type const pit = cur.pit();
705 cur.recordUndo(pit, pit + 1);
706 pars_.swap(pit, pit + 1);
708 cur.forceBufferUpdate();
713 case LFUN_PARAGRAPH_MOVE_UP: {
714 pit_type const pit = cur.pit();
715 cur.recordUndo(pit - 1, pit);
717 pars_.swap(pit, pit - 1);
720 cur.forceBufferUpdate();
724 case LFUN_APPENDIX: {
725 Paragraph & par = cur.paragraph();
726 bool start = !par.params().startOfAppendix();
728 // FIXME: The code below only makes sense at top level.
729 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
730 // ensure that we have only one start_of_appendix in this document
731 // FIXME: this don't work for multipart document!
732 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
733 if (pars_[tmp].params().startOfAppendix()) {
734 cur.recordUndo(tmp, tmp);
735 pars_[tmp].params().startOfAppendix(false);
741 par.params().startOfAppendix(start);
743 // we can set the refreshing parameters now
744 cur.forceBufferUpdate();
748 case LFUN_WORD_DELETE_FORWARD:
750 cutSelection(cur, false);
752 deleteWordForward(cur, cmd.getArg(0) == "force");
753 finishChange(cur, false);
756 case LFUN_WORD_DELETE_BACKWARD:
758 cutSelection(cur, false);
760 deleteWordBackward(cur, cmd.getArg(0) == "force");
761 finishChange(cur, false);
764 case LFUN_LINE_DELETE_FORWARD:
766 cutSelection(cur, false);
768 tm->deleteLineForward(cur);
769 finishChange(cur, false);
772 case LFUN_BUFFER_BEGIN:
773 case LFUN_BUFFER_BEGIN_SELECT:
774 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_BEGIN_SELECT);
775 if (cur.depth() == 1)
776 needsUpdate |= cursorTop(cur);
779 cur.screenUpdateFlags(Update::FitCursor);
782 case LFUN_BUFFER_END:
783 case LFUN_BUFFER_END_SELECT:
784 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_END_SELECT);
785 if (cur.depth() == 1)
786 needsUpdate |= cursorBottom(cur);
789 cur.screenUpdateFlags(Update::FitCursor);
792 case LFUN_INSET_BEGIN:
793 case LFUN_INSET_BEGIN_SELECT:
794 needsUpdate |= cur.selHandle(act == LFUN_INSET_BEGIN_SELECT);
795 if (cur.depth() == 1 || !cur.top().at_begin())
796 needsUpdate |= cursorTop(cur);
799 cur.screenUpdateFlags(Update::FitCursor);
803 case LFUN_INSET_END_SELECT:
804 needsUpdate |= cur.selHandle(act == LFUN_INSET_END_SELECT);
805 if (cur.depth() == 1 || !cur.top().at_end())
806 needsUpdate |= cursorBottom(cur);
809 cur.screenUpdateFlags(Update::FitCursor);
812 case LFUN_CHAR_FORWARD:
813 case LFUN_CHAR_FORWARD_SELECT: {
814 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
815 needsUpdate |= cur.selHandle(act == LFUN_CHAR_FORWARD_SELECT);
816 bool const cur_moved = cursorForward(cur);
817 needsUpdate |= cur_moved;
819 if (!cur_moved && cur.depth() > 1
820 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
822 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
824 // we will be moving out the inset, so we should execute
825 // the depm-mechanism.
826 // The cursor hasn't changed yet. To give the DEPM the
827 // possibility of doing something we must provide it with
828 // two different cursors.
830 dummy.pos() = dummy.pit() = 0;
831 if (cur.bv().checkDepm(dummy, cur))
832 cur.forceBufferUpdate();
837 case LFUN_CHAR_BACKWARD:
838 case LFUN_CHAR_BACKWARD_SELECT: {
839 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
840 needsUpdate |= cur.selHandle(act == LFUN_CHAR_BACKWARD_SELECT);
841 bool const cur_moved = cursorBackward(cur);
842 needsUpdate |= cur_moved;
844 if (!cur_moved && cur.depth() > 1
845 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
847 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
849 // we will be moving out the inset, so we should execute
850 // the depm-mechanism.
851 // The cursor hasn't changed yet. To give the DEPM the
852 // possibility of doing something we must provide it with
853 // two different cursors.
855 dummy.pos() = cur.lastpos();
856 dummy.pit() = cur.lastpit();
857 if (cur.bv().checkDepm(dummy, cur))
858 cur.forceBufferUpdate();
864 case LFUN_CHAR_LEFT_SELECT:
865 if (lyxrc.visual_cursor) {
866 needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
867 bool const cur_moved = cursorVisLeft(cur);
868 needsUpdate |= cur_moved;
869 if (!cur_moved && cur.depth() > 1
870 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
872 cmd = FuncRequest(LFUN_FINISHED_LEFT);
875 if (cur.reverseDirectionNeeded()) {
876 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
877 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
879 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
880 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
887 case LFUN_CHAR_RIGHT:
888 case LFUN_CHAR_RIGHT_SELECT:
889 if (lyxrc.visual_cursor) {
890 needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
891 bool const cur_moved = cursorVisRight(cur);
892 needsUpdate |= cur_moved;
893 if (!cur_moved && cur.depth() > 1
894 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
896 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
899 if (cur.reverseDirectionNeeded()) {
900 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
901 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
903 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
904 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
913 case LFUN_DOWN_SELECT:
916 // stop/start the selection
917 bool const select = cmd.action() == LFUN_DOWN_SELECT
918 || cmd.action() == LFUN_UP_SELECT;
919 // move cursor up/down
920 bool const up = cmd.action() == LFUN_UP_SELECT || cmd.action() == LFUN_UP;
922 if (!cur.atFirstOrLastRow(up)) {
923 needsUpdate |= cur.selHandle(select);
924 cur.upDownInText(up, needsUpdate);
925 needsUpdate |= cur.beforeDispatchCursor().inMathed();
927 pos_type newpos = up ? 0 : cur.lastpos();
928 if (lyxrc.mac_like_cursor_movement && cur.pos() != newpos) {
929 needsUpdate |= cur.selHandle(select);
930 // we do not reset the targetx of the cursor
932 needsUpdate |= bv->checkDepm(cur, bv->cursor());
933 cur.updateTextTargetOffset();
935 cur.forceBufferUpdate();
938 needsUpdate |= cur.selHandle(select);
939 bool const can_move = cur.upDownInText(up, needsUpdate);
940 // if the cursor can be moved up or down at an upper level,
941 // delegate the dispatch to next level. Otherwise, we are
944 cmd = FuncRequest(up ? LFUN_FINISHED_UP : LFUN_FINISHED_DOWN);
952 case LFUN_FINISHED_UP:
953 case LFUN_FINISHED_DOWN: {
954 // move cursor up/down
955 bool const up = cmd.action() == LFUN_FINISHED_UP;
957 if (!cur.atFirstOrLastRow(up)) {
958 cur.upDownInText(up, needsUpdate);
959 needsUpdate |= cur.beforeDispatchCursor().inMathed();
961 bool const can_move = cur.upDownInText(up, needsUpdate);
962 // if the cursor can be moved up or down and we are not
963 // moving cusor at top level, wait for the next dispatch.
964 // Otherwise, we are done.
972 case LFUN_PARAGRAPH_SELECT:
974 needsUpdate |= setCursor(cur, cur.pit(), 0);
975 needsUpdate |= cur.selHandle(true);
976 if (cur.pos() < cur.lastpos())
977 needsUpdate |= setCursor(cur, cur.pit(), cur.lastpos());
980 case LFUN_PARAGRAPH_UP:
981 case LFUN_PARAGRAPH_UP_SELECT:
982 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_UP_SELECT);
983 needsUpdate |= cursorUpParagraph(cur);
986 case LFUN_PARAGRAPH_DOWN:
987 case LFUN_PARAGRAPH_DOWN_SELECT:
988 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_DOWN_SELECT);
989 needsUpdate |= cursorDownParagraph(cur);
992 case LFUN_LINE_BEGIN:
993 case LFUN_LINE_BEGIN_SELECT:
994 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_BEGIN_SELECT);
995 needsUpdate |= tm->cursorHome(cur);
999 case LFUN_LINE_END_SELECT:
1000 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_END_SELECT);
1001 needsUpdate |= tm->cursorEnd(cur);
1004 case LFUN_SECTION_SELECT: {
1005 Buffer const & buf = *cur.buffer();
1006 pit_type const pit = cur.pit();
1007 ParagraphList & pars = buf.text().paragraphs();
1008 ParagraphList::iterator bgn = pars.begin();
1009 // The first paragraph of the area to be selected:
1010 ParagraphList::iterator start = pars.iterator_at(pit);
1011 // The final paragraph of area to be selected:
1012 ParagraphList::iterator finish = start;
1013 ParagraphList::iterator end = pars.end();
1015 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
1016 if (thistoclevel == Layout::NOT_IN_TOC)
1020 Cursor const old_cur = cur;
1021 needsUpdate |= cur.selHandle(true);
1023 // Move out (down) from this section header
1027 // Seek the one (on same level) below
1028 for (; finish != end; ++finish, ++cur.pit()) {
1029 int const toclevel = buf.text().getTocLevel(distance(bgn, finish));
1030 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
1033 cur.pos() = cur.lastpos();
1034 cur.boundary(false);
1035 cur.setCurrentFont();
1037 needsUpdate |= cur != old_cur;
1041 case LFUN_WORD_RIGHT:
1042 case LFUN_WORD_RIGHT_SELECT:
1043 if (lyxrc.visual_cursor) {
1044 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
1045 bool const cur_moved = cursorVisRightOneWord(cur);
1046 needsUpdate |= cur_moved;
1047 if (!cur_moved && cur.depth() > 1
1048 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1050 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1053 if (cur.reverseDirectionNeeded()) {
1054 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
1055 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
1057 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
1058 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
1065 case LFUN_WORD_FORWARD:
1066 case LFUN_WORD_FORWARD_SELECT: {
1067 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_FORWARD_SELECT);
1068 bool const cur_moved = cursorForwardOneWord(cur);
1069 needsUpdate |= cur_moved;
1071 if (!cur_moved && cur.depth() > 1
1072 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1074 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1076 // we will be moving out the inset, so we should execute
1077 // the depm-mechanism.
1078 // The cursor hasn't changed yet. To give the DEPM the
1079 // possibility of doing something we must provide it with
1080 // two different cursors.
1082 dummy.pos() = dummy.pit() = 0;
1083 if (cur.bv().checkDepm(dummy, cur))
1084 cur.forceBufferUpdate();
1089 case LFUN_WORD_LEFT:
1090 case LFUN_WORD_LEFT_SELECT:
1091 if (lyxrc.visual_cursor) {
1092 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
1093 bool const cur_moved = cursorVisLeftOneWord(cur);
1094 needsUpdate |= cur_moved;
1095 if (!cur_moved && cur.depth() > 1
1096 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1098 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1101 if (cur.reverseDirectionNeeded()) {
1102 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
1103 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
1105 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
1106 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
1113 case LFUN_WORD_BACKWARD:
1114 case LFUN_WORD_BACKWARD_SELECT: {
1115 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_BACKWARD_SELECT);
1116 bool const cur_moved = cursorBackwardOneWord(cur);
1117 needsUpdate |= cur_moved;
1119 if (!cur_moved && cur.depth() > 1
1120 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1122 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1124 // we will be moving out the inset, so we should execute
1125 // the depm-mechanism.
1126 // The cursor hasn't changed yet. To give the DEPM the
1127 // possibility of doing something we must provide it with
1128 // two different cursors.
1130 dummy.pos() = cur.lastpos();
1131 dummy.pit() = cur.lastpit();
1132 if (cur.bv().checkDepm(dummy, cur))
1133 cur.forceBufferUpdate();
1138 case LFUN_WORD_SELECT: {
1139 selectWord(cur, WHOLE_WORD);
1140 finishChange(cur, true);
1144 case LFUN_NEWLINE_INSERT: {
1145 InsetNewlineParams inp;
1146 docstring const & arg = cmd.argument();
1147 if (arg == "linebreak")
1148 inp.kind = InsetNewlineParams::LINEBREAK;
1150 inp.kind = InsetNewlineParams::NEWLINE;
1151 cap::replaceSelection(cur);
1153 cur.insert(new InsetNewline(inp));
1155 moveCursor(cur, false);
1159 case LFUN_TAB_INSERT: {
1160 bool const multi_par_selection = cur.selection() &&
1161 cur.selBegin().pit() != cur.selEnd().pit();
1162 if (multi_par_selection) {
1163 // If there is a multi-paragraph selection, a tab is inserted
1164 // at the beginning of each paragraph.
1165 cur.recordUndoSelection();
1166 pit_type const pit_end = cur.selEnd().pit();
1167 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
1168 pars_[pit].insertChar(0, '\t',
1169 bv->buffer().params().track_changes);
1170 // Update the selection pos to make sure the selection does not
1171 // change as the inserted tab will increase the logical pos.
1172 if (cur.realAnchor().pit() == pit)
1173 cur.realAnchor().forwardPos();
1174 if (cur.pit() == pit)
1179 // Maybe we shouldn't allow tabs within a line, because they
1180 // are not (yet) aligned as one might do expect.
1181 FuncRequest ncmd(LFUN_SELF_INSERT, from_ascii("\t"));
1182 dispatch(cur, ncmd);
1187 case LFUN_TAB_DELETE: {
1188 bool const tc = bv->buffer().params().track_changes;
1189 if (cur.selection()) {
1190 // If there is a selection, a tab (if present) is removed from
1191 // the beginning of each paragraph.
1192 cur.recordUndoSelection();
1193 pit_type const pit_end = cur.selEnd().pit();
1194 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
1195 Paragraph & par = paragraphs()[pit];
1198 char_type const c = par.getChar(0);
1199 if (c == '\t' || c == ' ') {
1200 // remove either 1 tab or 4 spaces.
1201 int const n = (c == ' ' ? 4 : 1);
1202 for (int i = 0; i < n
1203 && !par.empty() && par.getChar(0) == c; ++i) {
1204 if (cur.pit() == pit)
1206 if (cur.realAnchor().pit() == pit
1207 && cur.realAnchor().pos() > 0 )
1208 cur.realAnchor().backwardPos();
1209 par.eraseChar(0, tc);
1215 // If there is no selection, try to remove a tab or some spaces
1216 // before the position of the cursor.
1217 Paragraph & par = paragraphs()[cur.pit()];
1218 pos_type const pos = cur.pos();
1223 char_type const c = par.getChar(pos - 1);
1227 par.eraseChar(cur.pos(), tc);
1229 for (int n_spaces = 0;
1231 && par.getChar(cur.pos() - 1) == ' '
1235 par.eraseChar(cur.pos(), tc);
1242 case LFUN_CHAR_DELETE_FORWARD:
1243 if (!cur.selection()) {
1244 if (cur.pos() == cur.paragraph().size())
1245 // Par boundary, force full-screen update
1246 singleParUpdate = false;
1247 else if (cmd.getArg(0) != "force" && cur.confirmDeletion()) {
1249 cur.selection(true);
1254 needsUpdate |= erase(cur);
1257 cutSelection(cur, false);
1258 cur.setCurrentFont();
1259 singleParUpdate = false;
1261 moveCursor(cur, false);
1264 case LFUN_CHAR_DELETE_BACKWARD:
1265 if (!cur.selection()) {
1266 if (bv->getIntl().getTransManager().backspace()) {
1267 bool par_boundary = cur.pos() == 0;
1268 bool first_par = cur.pit() == 0;
1269 // Par boundary, full-screen update
1271 singleParUpdate = false;
1272 else if (cmd.getArg(0) != "force" && cur.confirmDeletion(true)) {
1274 cur.selection(true);
1279 needsUpdate |= backspace(cur);
1281 if (par_boundary && !first_par && cur.pos() > 0
1282 && cur.paragraph().isEnvSeparator(cur.pos() - 1)) {
1283 needsUpdate |= backspace(cur);
1288 DocIterator const dit = cur.selectionBegin();
1289 cutSelection(cur, false);
1290 if (cur.buffer()->params().track_changes)
1291 // since we're doing backwards deletion,
1292 // and the selection is not really cut,
1293 // move cursor before selection (#11630)
1295 cur.setCurrentFont();
1296 singleParUpdate = false;
1300 case LFUN_PARAGRAPH_BREAK: {
1301 cap::replaceSelection(cur);
1302 pit_type pit = cur.pit();
1303 Paragraph const & par = pars_[pit];
1304 bool lastpar = (pit == pit_type(pars_.size() - 1));
1305 Paragraph const & nextpar = lastpar ? par : pars_[pit + 1];
1306 pit_type prev = pit > 0 ? depthHook(pit, par.getDepth()) : pit;
1307 if (prev < pit && cur.pos() == par.beginOfBody()
1308 && par.empty() && !par.isEnvSeparator(cur.pos())
1309 && !par.layout().keepempty
1310 && !par.layout().isCommand()
1311 && pars_[prev].layout() != par.layout()
1312 && pars_[prev].layout().isEnvironment()
1313 && !nextpar.isEnvSeparator(nextpar.beginOfBody())) {
1314 if (par.layout().isEnvironment()
1315 && pars_[prev].getDepth() == par.getDepth()) {
1316 docstring const layout = par.layout().name();
1317 DocumentClass const & tc = bv->buffer().params().documentClass();
1318 lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
1319 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1320 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1321 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1323 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1324 breakParagraph(cur);
1326 Font const f(inherit_font, cur.current_font.language());
1327 pars_[cur.pit() - 1].resetFonts(f);
1329 if (par.isEnvSeparator(cur.pos()) && cmd.getArg(1) != "ignoresep")
1331 breakParagraph(cur, cmd.getArg(0) == "inverse");
1334 // If we have a list and autoinsert item insets,
1336 Layout::LaTeXArgMap args = par.layout().args();
1337 for (auto const & thearg : args) {
1338 Layout::latexarg arg = thearg.second;
1339 if (arg.autoinsert && prefixIs(thearg.first, "item:")) {
1340 FuncRequest cmd2(LFUN_ARGUMENT_INSERT, thearg.first);
1341 lyx::dispatch(cmd2);
1347 case LFUN_INSET_INSERT: {
1350 // We have to avoid triggering InstantPreview loading
1351 // before inserting into the document. See bug #5626.
1352 bool loaded = bv->buffer().isFullyLoaded();
1353 bv->buffer().setFullyLoaded(false);
1354 Inset * inset = createInset(&bv->buffer(), cmd);
1355 bv->buffer().setFullyLoaded(loaded);
1358 // FIXME (Abdel 01/02/2006):
1359 // What follows would be a partial fix for bug 2154:
1360 // http://www.lyx.org/trac/ticket/2154
1361 // This automatically put the label inset _after_ a
1362 // numbered section. It should be possible to extend the mechanism
1363 // to any kind of LateX environement.
1364 // The correct way to fix that bug would be at LateX generation.
1365 // I'll let the code here for reference as it could be used for some
1366 // other feature like "automatic labelling".
1368 Paragraph & par = pars_[cur.pit()];
1369 if (inset->lyxCode() == LABEL_CODE
1370 && !par.layout().counter.empty()) {
1371 // Go to the end of the paragraph
1372 // Warning: Because of Change-Tracking, the last
1373 // position is 'size()' and not 'size()-1':
1374 cur.pos() = par.size();
1375 // Insert a new paragraph
1376 FuncRequest fr(LFUN_PARAGRAPH_BREAK);
1380 if (cur.selection())
1381 cutSelection(cur, false);
1383 cur.forceBufferUpdate();
1384 if (inset->editable() && inset->asInsetText())
1385 inset->edit(cur, true);
1389 // trigger InstantPreview now
1390 if (inset->lyxCode() == EXTERNAL_CODE) {
1391 InsetExternal & ins =
1392 static_cast<InsetExternal &>(*inset);
1393 ins.updatePreview();
1400 case LFUN_INSET_DISSOLVE: {
1401 if (dissolveInset(cur)) {
1403 cur.forceBufferUpdate();
1408 case LFUN_INSET_SPLIT: {
1409 if (splitInset(cur)) {
1411 cur.forceBufferUpdate();
1416 case LFUN_GRAPHICS_SET_GROUP: {
1417 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
1423 string id = to_utf8(cmd.argument());
1424 string grp = graphics::getGroupParams(bv->buffer(), id);
1425 InsetGraphicsParams tmp, inspar = ins->getParams();
1428 inspar.groupId = to_utf8(cmd.argument());
1430 InsetGraphics::string2params(grp, bv->buffer(), tmp);
1431 tmp.filename = inspar.filename;
1435 ins->setParams(inspar);
1439 case LFUN_SPACE_INSERT:
1440 if (cur.paragraph().layout().free_spacing)
1441 insertChar(cur, ' ');
1443 doInsertInset(cur, this, cmd, false, false);
1446 moveCursor(cur, false);
1449 case LFUN_SPECIALCHAR_INSERT: {
1450 string const name = to_utf8(cmd.argument());
1451 if (name == "hyphenation")
1452 specialChar(cur, InsetSpecialChar::HYPHENATION);
1453 else if (name == "allowbreak")
1454 specialChar(cur, InsetSpecialChar::ALLOWBREAK);
1455 else if (name == "ligature-break")
1456 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1457 else if (name == "slash")
1458 specialChar(cur, InsetSpecialChar::SLASH);
1459 else if (name == "nobreakdash")
1460 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1461 else if (name == "dots")
1462 specialChar(cur, InsetSpecialChar::LDOTS);
1463 else if (name == "end-of-sentence")
1464 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1465 else if (name == "menu-separator")
1466 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1467 else if (name == "lyx")
1468 specialChar(cur, InsetSpecialChar::PHRASE_LYX);
1469 else if (name == "tex")
1470 specialChar(cur, InsetSpecialChar::PHRASE_TEX);
1471 else if (name == "latex")
1472 specialChar(cur, InsetSpecialChar::PHRASE_LATEX);
1473 else if (name == "latex2e")
1474 specialChar(cur, InsetSpecialChar::PHRASE_LATEX2E);
1475 else if (name.empty())
1476 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1478 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1482 case LFUN_IPAMACRO_INSERT: {
1483 string const arg = cmd.getArg(0);
1484 if (arg == "deco") {
1485 // Open the inset, and move the current selection
1487 doInsertInset(cur, this, cmd, true, true);
1489 // Some insets are numbered, others are shown in the outline pane so
1490 // let's update the labels and the toc backend.
1491 cur.forceBufferUpdate();
1494 if (arg == "tone-falling")
1495 ipaChar(cur, InsetIPAChar::TONE_FALLING);
1496 else if (arg == "tone-rising")
1497 ipaChar(cur, InsetIPAChar::TONE_RISING);
1498 else if (arg == "tone-high-rising")
1499 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING);
1500 else if (arg == "tone-low-rising")
1501 ipaChar(cur, InsetIPAChar::TONE_LOW_RISING);
1502 else if (arg == "tone-high-rising-falling")
1503 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING_FALLING);
1504 else if (arg.empty())
1505 lyxerr << "LyX function 'ipamacro-insert' needs an argument." << endl;
1507 lyxerr << "Wrong argument for LyX function 'ipamacro-insert'." << endl;
1511 case LFUN_WORD_UPCASE:
1512 changeCase(cur, text_uppercase, cmd.getArg(0) == "partial");
1515 case LFUN_WORD_LOWCASE:
1516 changeCase(cur, text_lowercase, cmd.getArg(0) == "partial");
1519 case LFUN_WORD_CAPITALIZE:
1520 changeCase(cur, text_capitalization, cmd.getArg(0) == "partial");
1523 case LFUN_CHARS_TRANSPOSE:
1524 charsTranspose(cur);
1528 cur.message(_("Paste"));
1529 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), break);
1530 cap::replaceSelection(cur);
1532 // without argument?
1533 string const arg = to_utf8(cmd.argument());
1535 bool tryGraphics = true;
1536 if (theClipboard().isInternal())
1537 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1538 else if (theClipboard().hasTextContents()) {
1539 if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1540 !cur.paragraph().parbreakIsNewline(),
1541 Clipboard::AnyTextType))
1542 tryGraphics = false;
1544 if (tryGraphics && theClipboard().hasGraphicsContents())
1545 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1546 } else if (isStrUnsignedInt(arg)) {
1547 // we have a numerical argument
1548 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1549 convert<unsigned int>(arg));
1550 } else if (arg == "html" || arg == "latex") {
1551 Clipboard::TextType type = (arg == "html") ?
1552 Clipboard::HtmlTextType : Clipboard::LaTeXTextType;
1553 pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type);
1555 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1557 type = Clipboard::PdfGraphicsType;
1558 else if (arg == "png")
1559 type = Clipboard::PngGraphicsType;
1560 else if (arg == "jpeg")
1561 type = Clipboard::JpegGraphicsType;
1562 else if (arg == "linkback")
1563 type = Clipboard::LinkBackGraphicsType;
1564 else if (arg == "emf")
1565 type = Clipboard::EmfGraphicsType;
1566 else if (arg == "wmf")
1567 type = Clipboard::WmfGraphicsType;
1569 // we also check in getStatus()
1570 LYXERR0("Unrecognized graphics type: " << arg);
1572 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1575 bv->buffer().errors("Paste");
1576 bv->buffer().updatePreviews(); // bug 11619
1577 cur.clearSelection(); // bug 393
1583 cutSelection(cur, true);
1584 cur.message(_("Cut"));
1587 case LFUN_SERVER_GET_XY:
1588 cur.message(from_utf8(
1589 convert<string>(tm->cursorX(cur.top(), cur.boundary()))
1590 + ' ' + convert<string>(tm->cursorY(cur.top(), cur.boundary()))));
1593 case LFUN_SERVER_SET_XY: {
1596 istringstream is(to_utf8(cmd.argument()));
1599 lyxerr << "SETXY: Could not parse coordinates in '"
1600 << to_utf8(cmd.argument()) << endl;
1602 tm->setCursorFromCoordinates(cur, x, y);
1606 case LFUN_SERVER_GET_LAYOUT:
1607 cur.message(cur.paragraph().layout().name());
1611 case LFUN_LAYOUT_TOGGLE: {
1612 bool const ignoreautonests = cmd.getArg(1) == "ignoreautonests";
1613 docstring req_layout = ignoreautonests ? from_utf8(cmd.getArg(0)) : cmd.argument();
1614 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(req_layout));
1616 docstring layout = resolveLayout(req_layout, cur);
1617 if (layout.empty()) {
1618 cur.errorMessage(from_utf8(N_("Layout ")) + req_layout +
1619 from_utf8(N_(" not known")));
1623 docstring const old_layout = cur.paragraph().layout().name();
1624 bool change_layout = !isAlreadyLayout(layout, cur);
1626 if (cmd.action() == LFUN_LAYOUT_TOGGLE && !change_layout) {
1627 change_layout = true;
1628 layout = resolveLayout(docstring(), cur);
1631 if (change_layout) {
1632 setLayout(cur, layout);
1633 if (cur.pit() > 0 && !ignoreautonests) {
1634 pit_type prev_pit = cur.pit() - 1;
1635 depth_type const cur_depth = pars_[cur.pit()].getDepth();
1636 // Scan for the previous par on same nesting level
1637 while (prev_pit > 0 && pars_[prev_pit].getDepth() > cur_depth)
1639 set<docstring> const & autonests =
1640 pars_[prev_pit].layout().autonests();
1641 set<docstring> const & autonested =
1642 pars_[cur.pit()].layout().isAutonestedBy();
1643 if (autonests.find(layout) != autonests.end()
1644 || autonested.find(old_layout) != autonested.end())
1645 lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
1649 DocumentClass const & tclass = bv->buffer().params().documentClass();
1650 bool inautoarg = false;
1651 for (auto const & la_pair : tclass[layout].args()) {
1652 Layout::latexarg const & arg = la_pair.second;
1653 if (arg.autoinsert) {
1654 // If we had already inserted an arg automatically,
1655 // leave this now in order to insert the next one.
1657 cur.leaveInset(cur.inset());
1660 FuncRequest const cmd2(LFUN_ARGUMENT_INSERT, la_pair.first);
1661 lyx::dispatch(cmd2);
1669 case LFUN_ENVIRONMENT_SPLIT: {
1670 bool const outer = cmd.argument() == "outer";
1671 bool const previous = cmd.argument() == "previous";
1672 bool const before = cmd.argument() == "before";
1673 bool const normal = cmd.argument().empty();
1674 Paragraph const & para = cur.paragraph();
1676 if (para.layout().isEnvironment())
1677 layout = para.layout().name();
1678 depth_type split_depth = cur.paragraph().params().depth();
1679 vector<depth_type> nextpars_depth;
1680 if (outer || previous) {
1681 // check if we have an environment in our scope
1682 pit_type pit = cur.pit();
1683 Paragraph cpar = pars_[pit];
1689 if (layout.empty() && previous
1690 && cpar.layout().isEnvironment()
1691 && cpar.params().depth() <= split_depth)
1692 layout = cpar.layout().name();
1693 if (cpar.params().depth() < split_depth
1694 && cpar.layout().isEnvironment()) {
1696 layout = cpar.layout().name();
1697 split_depth = cpar.params().depth();
1699 if (cpar.params().depth() == 0)
1703 if ((outer || normal) && cur.pit() < cur.lastpit()) {
1704 // save nesting of following paragraphs if they are deeper
1706 pit_type offset = 1;
1707 depth_type cur_depth = pars_[cur.pit()].params().depth();
1708 while (cur.pit() + offset <= cur.lastpit()) {
1709 Paragraph cpar = pars_[cur.pit() + offset];
1710 depth_type nextpar_depth = cpar.params().depth();
1711 if (cur_depth <= nextpar_depth && nextpar_depth > 0) {
1712 nextpars_depth.push_back(nextpar_depth);
1713 cur_depth = nextpar_depth;
1720 cur.top().setPitPos(cur.pit(), 0);
1721 if (before || cur.pos() > 0)
1722 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
1723 else if (previous && cur.nextInset() && cur.nextInset()->lyxCode() == SEPARATOR_CODE)
1724 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse ignoresep"));
1726 while (cur.paragraph().params().depth() > split_depth)
1727 lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
1729 DocumentClass const & tc = bv->buffer().params().documentClass();
1730 lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") + tc.plainLayout().name()
1731 + from_ascii("\" ignoreautonests")));
1732 // FIXME: Bibitem mess!
1733 if (cur.prevInset() && cur.prevInset()->lyxCode() == BIBITEM_CODE)
1734 lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_BACKWARD));
1735 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1738 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse ignoresep"));
1739 while (cur.paragraph().params().depth() < split_depth)
1740 lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
1743 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1744 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1745 if ((outer || normal) && !nextpars_depth.empty()) {
1746 // restore nesting of following paragraphs
1747 DocIterator scur = cur;
1748 depth_type max_depth = cur.paragraph().params().depth() + 1;
1749 for (auto nextpar_depth : nextpars_depth) {
1751 while (cur.paragraph().params().depth() < min(nextpar_depth, max_depth)) {
1752 depth_type const olddepth = cur.paragraph().params().depth();
1753 lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
1754 if (olddepth == cur.paragraph().params().depth())
1755 // leave loop if no incrementation happens
1758 max_depth = cur.paragraph().params().depth() + 1;
1760 cur.setCursor(scur);
1766 case LFUN_CLIPBOARD_PASTE:
1767 cap::replaceSelection(cur);
1768 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1769 cmd.argument() == "paragraph");
1770 bv->buffer().errors("Paste");
1773 case LFUN_CLIPBOARD_PASTE_SIMPLE:
1774 cap::replaceSelection(cur);
1775 pasteSimpleText(cur, cmd.argument() == "paragraph");
1778 case LFUN_PRIMARY_SELECTION_PASTE:
1779 cap::replaceSelection(cur);
1780 pasteString(cur, theSelection().get(),
1781 cmd.argument() == "paragraph");
1784 case LFUN_SELECTION_PASTE:
1785 // Copy the selection buffer to the clipboard stack,
1786 // because we want it to appear in the "Edit->Paste
1788 cap::replaceSelection(cur);
1789 cap::copySelectionToStack();
1790 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1791 bv->buffer().errors("Paste");
1794 case LFUN_QUOTE_INSERT: {
1795 cap::replaceSelection(cur);
1798 Paragraph const & par = cur.paragraph();
1799 pos_type pos = cur.pos();
1800 // Ignore deleted text before cursor
1801 while (pos > 0 && par.isDeleted(pos - 1))
1804 bool const inner = (cmd.getArg(0) == "single" || cmd.getArg(0) == "inner");
1806 // Guess quote side.
1807 // A space triggers an opening quote. This is passed if the preceding
1808 // char/inset is a space or at paragraph start.
1810 if (pos > 0 && !par.isSpace(pos - 1)) {
1811 if (cur.prevInset() && cur.prevInset()->lyxCode() == QUOTE_CODE) {
1812 // If an opening double quotation mark precedes, and this
1813 // is a single quote, make it opening as well
1815 static_cast<InsetQuotes &>(*cur.prevInset());
1816 string const type = ins.getType();
1817 if (!suffixIs(type, "ld") || !inner)
1818 c = par.getChar(pos - 1);
1820 else if (!cur.prevInset()
1821 || (cur.prevInset() && cur.prevInset()->isChar()))
1822 // If a char precedes, pass that and let InsetQuote decide
1823 c = par.getChar(pos - 1);
1826 if (par.getInset(pos - 1)
1827 && !par.getInset(pos - 1)->isPartOfTextSequence()) {
1828 // skip "invisible" insets
1832 c = par.getChar(pos - 1);
1837 QuoteLevel const quote_level = inner
1838 ? QuoteLevel::Secondary : QuoteLevel::Primary;
1839 cur.insert(new InsetQuotes(cur.buffer(), c, quote_level, cmd.getArg(1), cmd.getArg(2)));
1840 cur.buffer()->updateBuffer();
1845 case LFUN_MOUSE_TRIPLE:
1846 if (cmd.button() == mouse_button::button1) {
1848 setCursor(cur, cur.pit(), 0);
1851 if (cur.pos() < cur.lastpos())
1852 setCursor(cur, cur.pit(), cur.lastpos());
1858 case LFUN_MOUSE_DOUBLE:
1859 if (cmd.button() == mouse_button::button1) {
1860 selectWord(cur, WHOLE_WORD);
1865 // Single-click on work area
1866 case LFUN_MOUSE_PRESS: {
1867 // We are not marking a selection with the keyboard in any case.
1868 Cursor & bvcur = cur.bv().cursor();
1869 bvcur.setMark(false);
1870 switch (cmd.button()) {
1871 case mouse_button::button1:
1872 if (!bvcur.selection())
1874 bvcur.resetAnchor();
1875 if (!bv->mouseSetCursor(cur, cmd.modifier() == ShiftModifier))
1876 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1877 // FIXME: move this to mouseSetCursor?
1878 if (bvcur.wordSelection() && bvcur.inTexted())
1879 expandWordSel(bvcur);
1882 case mouse_button::button2:
1883 if (lyxrc.mouse_middlebutton_paste) {
1884 // Middle mouse pasting.
1885 bv->mouseSetCursor(cur);
1887 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1888 "selection-paste ; primary-selection-paste paragraph"));
1890 cur.noScreenUpdate();
1893 case mouse_button::button3: {
1894 // Don't do anything if we right-click a
1895 // selection, a context menu will popup.
1896 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1897 && cur <= bvcur.selectionEnd()) {
1898 cur.noScreenUpdate();
1901 if (!bv->mouseSetCursor(cur, false))
1902 cur.screenUpdateFlags(Update::FitCursor);
1908 } // switch (cmd.button())
1911 case LFUN_MOUSE_MOTION: {
1912 // Mouse motion with right or middle mouse do nothing for now.
1913 if (cmd.button() != mouse_button::button1) {
1914 cur.noScreenUpdate();
1917 // ignore motions deeper nested than the real anchor
1918 Cursor & bvcur = cur.bv().cursor();
1919 if (!bvcur.realAnchor().hasPart(cur)) {
1923 CursorSlice old = bvcur.top();
1925 int const wh = bv->workHeight();
1926 int const y = max(0, min(wh - 1, cmd.y()));
1928 tm->setCursorFromCoordinates(cur, cmd.x(), y);
1929 cur.setTargetX(cmd.x());
1930 // Don't allow selecting a separator inset
1931 if (cur.pos() && cur.paragraph().isEnvSeparator(cur.pos() - 1))
1934 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1935 else if (cmd.y() < 0)
1936 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1937 // This is to allow jumping over large insets
1938 if (cur.top() == old) {
1940 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1941 else if (cmd.y() < 0)
1942 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1944 // We continue with our existing selection or start a new one, so don't
1945 // reset the anchor.
1946 bvcur.setCursor(cur);
1947 if (bvcur.wordSelection() && bvcur.inTexted())
1948 expandWordSel(bvcur);
1949 bvcur.selection(true);
1950 bvcur.setCurrentFont();
1951 if (cur.top() == old) {
1952 // We didn't move one iota, so no need to update the screen.
1953 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1954 //cur.noScreenUpdate();
1960 case LFUN_MOUSE_RELEASE:
1961 switch (cmd.button()) {
1962 case mouse_button::button1:
1963 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1964 // If there is a new selection, update persistent selection;
1965 // otherwise, single click does not clear persistent selection
1967 if (cur.selection()) {
1968 // Finish selection. If double click,
1969 // cur is moved to the end of word by
1970 // selectWord but bvcur is current
1972 cur.bv().cursor().setSelection();
1973 // We might have removed an empty but drawn selection
1974 // (probably a margin)
1975 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1977 cur.noScreenUpdate();
1978 // FIXME: We could try to handle drag and drop of selection here.
1981 case mouse_button::button2:
1982 // Middle mouse pasting is handled at mouse press time,
1983 // see LFUN_MOUSE_PRESS.
1984 cur.noScreenUpdate();
1987 case mouse_button::button3:
1988 // Cursor was set at LFUN_MOUSE_PRESS time.
1989 // FIXME: If there is a selection we could try to handle a special
1990 // drag & drop context menu.
1991 cur.noScreenUpdate();
1994 case mouse_button::none:
1995 case mouse_button::button4:
1996 case mouse_button::button5:
1998 } // switch (cmd.button())
2002 case LFUN_SELF_INSERT: {
2003 if (cmd.argument().empty())
2006 // Automatically delete the currently selected
2007 // text and replace it with what is being
2008 // typed in now. Depends on lyxrc settings
2009 // "auto_region_delete", which defaults to
2012 if (lyxrc.auto_region_delete && cur.selection()) {
2013 cutSelection(cur, false);
2014 cur.setCurrentFont();
2016 cur.clearSelection();
2018 for (char_type c : cmd.argument())
2019 bv->translateAndInsert(c, this, cur);
2022 moveCursor(cur, false);
2023 cur.markNewWordPosition();
2024 bv->bookmarkEditPosition();
2028 case LFUN_HREF_INSERT: {
2029 docstring content = cmd.argument();
2030 if (content.empty() && cur.selection())
2031 content = cur.selectionAsString(false);
2033 InsetCommandParams p(HYPERLINK_CODE);
2034 if (!content.empty()){
2035 // if it looks like a link, we'll put it as target,
2036 // otherwise as name (bug #8792).
2039 // regex_match(to_utf8(content), matches, link_re)
2040 // because smatch stores pointers to the substrings rather
2041 // than making copies of them. And those pointers become
2042 // invalid after regex_match returns, since it is then
2043 // being given a temporary object. (Thanks to Georg for
2044 // figuring that out.)
2045 regex const link_re("^([a-z]+):.*");
2047 string const c = to_utf8(lowercase(content));
2049 if (c.substr(0,7) == "mailto:") {
2050 p["target"] = content;
2051 p["type"] = from_ascii("mailto:");
2052 } else if (regex_match(c, matches, link_re)) {
2053 p["target"] = content;
2054 string protocol = matches.str(1);
2055 if (protocol == "file")
2056 p["type"] = from_ascii("file:");
2058 p["name"] = content;
2060 string const data = InsetCommand::params2string(p);
2062 // we need to have a target. if we already have one, then
2063 // that gets used at the default for the name, too, which
2064 // is probably what is wanted.
2065 if (p["target"].empty()) {
2066 bv->showDialog("href", data);
2068 FuncRequest fr(LFUN_INSET_INSERT, data);
2074 case LFUN_LABEL_INSERT: {
2075 InsetCommandParams p(LABEL_CODE);
2076 // Try to generate a valid label
2077 p["name"] = (cmd.argument().empty()) ?
2078 cur.getPossibleLabel() :
2080 string const data = InsetCommand::params2string(p);
2082 if (cmd.argument().empty()) {
2083 bv->showDialog("label", data);
2085 FuncRequest fr(LFUN_INSET_INSERT, data);
2091 case LFUN_INFO_INSERT: {
2092 if (cmd.argument().empty()) {
2093 bv->showDialog("info", cur.current_font.language()->lang());
2096 inset = createInset(cur.buffer(), cmd);
2100 insertInset(cur, inset);
2101 cur.forceBufferUpdate();
2106 case LFUN_CAPTION_INSERT:
2107 case LFUN_FOOTNOTE_INSERT:
2108 case LFUN_NOTE_INSERT:
2109 case LFUN_BOX_INSERT:
2110 case LFUN_BRANCH_INSERT:
2111 case LFUN_PHANTOM_INSERT:
2112 case LFUN_ERT_INSERT:
2113 case LFUN_LISTING_INSERT:
2114 case LFUN_MARGINALNOTE_INSERT:
2115 case LFUN_ARGUMENT_INSERT:
2116 case LFUN_INDEX_INSERT:
2117 case LFUN_PREVIEW_INSERT:
2118 case LFUN_SCRIPT_INSERT:
2119 case LFUN_IPA_INSERT: {
2120 // Indexes reset font formatting (#11961)
2121 bool const resetfont = cmd.action() == LFUN_INDEX_INSERT;
2122 // Open the inset, and move the current selection
2124 doInsertInset(cur, this, cmd, true, true, resetfont);
2126 cur.setCurrentFont();
2127 // Some insets are numbered, others are shown in the outline pane so
2128 // let's update the labels and the toc backend.
2129 cur.forceBufferUpdate();
2133 case LFUN_FLEX_INSERT: {
2134 // Open the inset, and move the current selection
2136 bool const sel = cur.selection();
2137 doInsertInset(cur, this, cmd, true, true);
2138 // Insert auto-insert arguments
2139 bool autoargs = false, inautoarg = false;
2140 Layout::LaTeXArgMap args = cur.inset().getLayout().args();
2141 for (auto const & argt : args) {
2142 Layout::latexarg arg = argt.second;
2143 if (!inautoarg && arg.insertonnewline && cur.pos() > 0) {
2144 FuncRequest cmd2(LFUN_PARAGRAPH_BREAK);
2145 lyx::dispatch(cmd2);
2147 if (arg.autoinsert) {
2148 // The cursor might have been invalidated by the replaceSelection.
2149 cur.buffer()->changed(true);
2150 // If we had already inserted an arg automatically,
2151 // leave this now in order to insert the next one.
2153 cur.leaveInset(cur.inset());
2154 cur.setCurrentFont();
2156 if (arg.insertonnewline && cur.pos() > 0) {
2157 FuncRequest cmd2(LFUN_PARAGRAPH_BREAK);
2158 lyx::dispatch(cmd2);
2161 FuncRequest cmd2(LFUN_ARGUMENT_INSERT, argt.first);
2162 lyx::dispatch(cmd2);
2169 cur.leaveInset(cur.inset());
2172 // Some insets are numbered, others are shown in the outline pane so
2173 // let's update the labels and the toc backend.
2174 cur.forceBufferUpdate();
2178 case LFUN_TABULAR_INSERT: {
2179 // if there were no arguments, just open the dialog
2180 if (cmd.argument().empty()) {
2181 bv->showDialog("tabularcreate");
2183 } else if (cur.buffer()->masterParams().tablestyle != "default"
2184 || bv->buffer().params().documentClass().tablestyle() != "default") {
2185 string tabstyle = cur.buffer()->masterParams().tablestyle;
2186 if (tabstyle == "default")
2187 tabstyle = bv->buffer().params().documentClass().tablestyle();
2188 if (!libFileSearch("tabletemplates", tabstyle + ".lyx").empty()) {
2189 FuncRequest fr(LFUN_TABULAR_STYLE_INSERT,
2190 tabstyle + " " + to_ascii(cmd.argument()));
2194 // Unknown style. Report and fall back to default.
2195 cur.errorMessage(from_utf8(N_("Table Style ")) + from_utf8(tabstyle) +
2196 from_utf8(N_(" not known")));
2198 if (doInsertInset(cur, this, cmd, false, true))
2203 case LFUN_TABULAR_STYLE_INSERT: {
2204 string const style = cmd.getArg(0);
2205 string const rows = cmd.getArg(1);
2206 string const cols = cmd.getArg(2);
2207 if (cols.empty() || !isStrInt(cols)
2208 || rows.empty() || !isStrInt(rows))
2210 int const r = convert<int>(rows);
2211 int const c = convert<int>(cols);
2218 FileName const tabstyle = libFileSearch("tabletemplates",
2219 style + suffix + ".lyx", "lyx");
2220 if (tabstyle.empty())
2222 UndoGroupHelper ugh(cur.buffer());
2224 FuncRequest cmd2(LFUN_FILE_INSERT, tabstyle.absFileName() + " ignorelang");
2225 lyx::dispatch(cmd2);
2229 // move one cell up to middle cell
2231 // add the missing rows
2232 int const addrows = r - 3;
2233 for (int i = 0 ; i < addrows ; ++i) {
2234 FuncRequest fr(LFUN_TABULAR_FEATURE, "append-row");
2238 // add the missing columns
2239 int const addcols = c - 1;
2240 for (int i = 0 ; i < addcols ; ++i) {
2241 FuncRequest fr(LFUN_TABULAR_FEATURE, "append-column");
2250 case LFUN_FLOAT_INSERT:
2251 case LFUN_FLOAT_WIDE_INSERT:
2252 case LFUN_WRAP_INSERT: {
2253 // will some content be moved into the inset?
2254 bool const content = cur.selection();
2255 // does the content consist of multiple paragraphs?
2256 bool const singlepar = (cur.selBegin().pit() == cur.selEnd().pit());
2258 doInsertInset(cur, this, cmd, true, true);
2261 // If some single-par content is moved into the inset,
2262 // doInsertInset puts the cursor outside the inset.
2263 // To insert the caption we put it back into the inset.
2264 // FIXME cleanup doInsertInset to avoid such dances!
2265 if (content && singlepar)
2268 ParagraphList & pars = cur.text()->paragraphs();
2270 DocumentClass const & tclass = bv->buffer().params().documentClass();
2272 // add a separate paragraph for the caption inset
2273 pars.push_back(Paragraph());
2274 pars.back().setInsetOwner(&cur.text()->inset());
2275 pars.back().setPlainOrDefaultLayout(tclass);
2276 int cap_pit = pars.size() - 1;
2278 // if an empty inset was created, we create an additional empty
2279 // paragraph at the bottom so that the user can choose where to put
2280 // the graphics (or table).
2282 pars.push_back(Paragraph());
2283 pars.back().setInsetOwner(&cur.text()->inset());
2284 pars.back().setPlainOrDefaultLayout(tclass);
2287 // reposition the cursor to the caption
2288 cur.pit() = cap_pit;
2290 // FIXME: This Text/Cursor dispatch handling is a mess!
2291 // We cannot use Cursor::dispatch here it needs access to up to
2293 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
2294 doInsertInset(cur, cur.text(), cmd_caption, true, false);
2295 cur.forceBufferUpdate();
2296 cur.screenUpdateFlags(Update::Force);
2297 // FIXME: When leaving the Float (or Wrap) inset we should
2298 // delete any empty paragraph left above or below the
2303 case LFUN_NOMENCL_INSERT: {
2304 InsetCommandParams p(NOMENCL_CODE);
2305 if (cmd.argument().empty()) {
2307 bv->cursor().innerText()->getStringForDialog(bv->cursor());
2308 cur.clearSelection();
2310 p["symbol"] = cmd.argument();
2311 string const data = InsetCommand::params2string(p);
2312 bv->showDialog("nomenclature", data);
2316 case LFUN_INDEX_PRINT: {
2317 InsetCommandParams p(INDEX_PRINT_CODE);
2318 if (cmd.argument().empty())
2319 p["type"] = from_ascii("idx");
2321 p["type"] = cmd.argument();
2322 string const data = InsetCommand::params2string(p);
2323 FuncRequest fr(LFUN_INSET_INSERT, data);
2328 case LFUN_NOMENCL_PRINT:
2329 case LFUN_NEWPAGE_INSERT:
2331 doInsertInset(cur, this, cmd, false, false);
2335 case LFUN_SEPARATOR_INSERT: {
2336 doInsertInset(cur, this, cmd, false, false);
2338 // remove a following space
2339 Paragraph & par = cur.paragraph();
2340 if (cur.pos() != cur.lastpos() && par.isLineSeparator(cur.pos()))
2341 par.eraseChar(cur.pos(), cur.buffer()->params().track_changes);
2345 case LFUN_DEPTH_DECREMENT:
2346 changeDepth(cur, DEC_DEPTH);
2349 case LFUN_DEPTH_INCREMENT:
2350 changeDepth(cur, INC_DEPTH);
2353 case LFUN_REGEXP_MODE:
2354 regexpDispatch(cur, cmd);
2357 case LFUN_MATH_MODE: {
2358 if (cmd.argument() == "on" || cmd.argument() == "") {
2359 // don't pass "on" as argument
2360 // (it would appear literally in the first cell)
2361 docstring sel = cur.selectionAsString(false);
2362 InsetMathMacroTemplate * macro = new InsetMathMacroTemplate(cur.buffer());
2363 // create a macro template if we see "\\newcommand" somewhere, and
2364 // an ordinary formula otherwise
2366 && (sel.find(from_ascii("\\newcommand")) != string::npos
2367 || sel.find(from_ascii("\\newlyxcommand")) != string::npos
2368 || sel.find(from_ascii("\\def")) != string::npos)
2369 && macro->fromString(sel)) {
2371 replaceSelection(cur);
2374 // no meaningful macro template was found
2376 mathDispatch(cur,FuncRequest(LFUN_MATH_MODE));
2379 // The argument is meaningful
2380 // We replace cmd with LFUN_MATH_INSERT because LFUN_MATH_MODE
2381 // has a different meaning in math mode
2382 mathDispatch(cur, FuncRequest(LFUN_MATH_INSERT,cmd.argument()));
2386 case LFUN_MATH_MACRO:
2387 if (cmd.argument().empty())
2388 cur.errorMessage(from_utf8(N_("Missing argument")));
2391 string s = to_utf8(cmd.argument());
2392 string const s1 = token(s, ' ', 1);
2393 int const nargs = s1.empty() ? 0 : convert<int>(s1);
2394 string const s2 = token(s, ' ', 2);
2395 MacroType type = MacroTypeNewcommand;
2397 type = MacroTypeDef;
2398 InsetMathMacroTemplate * inset = new InsetMathMacroTemplate(cur.buffer(),
2399 from_utf8(token(s, ' ', 0)), nargs, false, type);
2400 inset->setBuffer(bv->buffer());
2401 insertInset(cur, inset);
2403 // enter macro inset and select the name
2405 cur.top().pos() = cur.top().lastpos();
2407 cur.selection(true);
2408 cur.top().pos() = 0;
2412 case LFUN_MATH_DISPLAY:
2413 case LFUN_MATH_SUBSCRIPT:
2414 case LFUN_MATH_SUPERSCRIPT:
2415 case LFUN_MATH_INSERT:
2416 case LFUN_MATH_AMS_MATRIX:
2417 case LFUN_MATH_MATRIX:
2418 case LFUN_MATH_DELIM:
2419 case LFUN_MATH_BIGDELIM:
2420 mathDispatch(cur, cmd);
2423 case LFUN_FONT_EMPH: {
2424 Font font(ignore_font, ignore_language);
2425 font.fontInfo().setEmph(FONT_TOGGLE);
2426 toggleAndShow(cur, this, font);
2430 case LFUN_FONT_ITAL: {
2431 Font font(ignore_font, ignore_language);
2432 font.fontInfo().setShape(ITALIC_SHAPE);
2433 toggleAndShow(cur, this, font);
2437 case LFUN_FONT_BOLD:
2438 case LFUN_FONT_BOLDSYMBOL: {
2439 Font font(ignore_font, ignore_language);
2440 font.fontInfo().setSeries(BOLD_SERIES);
2441 toggleAndShow(cur, this, font);
2445 case LFUN_FONT_NOUN: {
2446 Font font(ignore_font, ignore_language);
2447 font.fontInfo().setNoun(FONT_TOGGLE);
2448 toggleAndShow(cur, this, font);
2452 case LFUN_FONT_TYPEWRITER: {
2453 Font font(ignore_font, ignore_language);
2454 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
2455 toggleAndShow(cur, this, font);
2459 case LFUN_FONT_SANS: {
2460 Font font(ignore_font, ignore_language);
2461 font.fontInfo().setFamily(SANS_FAMILY);
2462 toggleAndShow(cur, this, font);
2466 case LFUN_FONT_ROMAN: {
2467 Font font(ignore_font, ignore_language);
2468 font.fontInfo().setFamily(ROMAN_FAMILY);
2469 toggleAndShow(cur, this, font);
2473 case LFUN_FONT_DEFAULT: {
2474 Font font(inherit_font, ignore_language);
2475 toggleAndShow(cur, this, font);
2479 case LFUN_FONT_STRIKEOUT: {
2480 Font font(ignore_font, ignore_language);
2481 font.fontInfo().setStrikeout(FONT_TOGGLE);
2482 toggleAndShow(cur, this, font);
2486 case LFUN_FONT_CROSSOUT: {
2487 Font font(ignore_font, ignore_language);
2488 font.fontInfo().setXout(FONT_TOGGLE);
2489 toggleAndShow(cur, this, font);
2493 case LFUN_FONT_UNDERUNDERLINE: {
2494 Font font(ignore_font, ignore_language);
2495 font.fontInfo().setUuline(FONT_TOGGLE);
2496 toggleAndShow(cur, this, font);
2500 case LFUN_FONT_UNDERWAVE: {
2501 Font font(ignore_font, ignore_language);
2502 font.fontInfo().setUwave(FONT_TOGGLE);
2503 toggleAndShow(cur, this, font);
2507 case LFUN_FONT_UNDERLINE: {
2508 Font font(ignore_font, ignore_language);
2509 font.fontInfo().setUnderbar(FONT_TOGGLE);
2510 toggleAndShow(cur, this, font);
2514 case LFUN_FONT_NO_SPELLCHECK: {
2515 Font font(ignore_font, ignore_language);
2516 font.fontInfo().setNoSpellcheck(FONT_TOGGLE);
2517 toggleAndShow(cur, this, font);
2521 case LFUN_FONT_SIZE: {
2522 Font font(ignore_font, ignore_language);
2523 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
2524 toggleAndShow(cur, this, font);
2528 case LFUN_LANGUAGE: {
2529 string const lang_arg = cmd.getArg(0);
2530 bool const reset = (lang_arg.empty() || lang_arg == "reset");
2531 Language const * lang =
2532 reset ? reset_language
2533 : languages.getLanguage(lang_arg);
2534 // we allow reset_language, which is 0, but only if it
2535 // was requested via empty or "reset" arg.
2536 if (!lang && !reset)
2538 bool const toggle = (cmd.getArg(1) != "set");
2539 selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
2540 Font font(ignore_font, lang);
2541 toggleAndShow(cur, this, font, toggle);
2545 case LFUN_TEXTSTYLE_APPLY: {
2546 unsigned int num = 0;
2547 string const arg = to_utf8(cmd.argument());
2550 if (isStrUnsignedInt(arg)) {
2551 num = convert<uint>(arg);
2552 if (num >= freeFonts.size()) {
2553 cur.message(_("Invalid argument (number exceeds stack size)!"));
2557 cur.message(_("Invalid argument (must be a non-negative number)!"));
2561 toggleAndShow(cur, this, freeFonts[num].second, toggleall);
2562 cur.message(bformat(_("Text properties applied: %1$s"), freeFonts[num].first));
2566 // Set the freefont using the contents of \param data dispatched from
2567 // the frontends and apply it at the current cursor location.
2568 case LFUN_TEXTSTYLE_UPDATE: {
2569 Font font(ignore_font, ignore_language);
2571 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
2572 docstring const props = font.stateText(&bv->buffer().params(), true);
2573 freeFonts.push(make_pair(props, font));
2575 toggleAndShow(cur, this, font, toggleall);
2576 cur.message(bformat(_("Text properties applied: %1$s"), props));
2578 LYXERR0("Invalid argument of textstyle-update");
2582 case LFUN_FINISHED_LEFT:
2583 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
2584 // We're leaving an inset, going left. If the inset is LTR, we're
2585 // leaving from the front, so we should not move (remain at --- but
2586 // not in --- the inset). If the inset is RTL, move left, without
2587 // entering the inset itself; i.e., move to after the inset.
2588 if (cur.paragraph().getFontSettings(
2589 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2590 cursorVisLeft(cur, true);
2593 case LFUN_FINISHED_RIGHT:
2594 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
2595 // We're leaving an inset, going right. If the inset is RTL, we're
2596 // leaving from the front, so we should not move (remain at --- but
2597 // not in --- the inset). If the inset is LTR, move right, without
2598 // entering the inset itself; i.e., move to after the inset.
2599 if (!cur.paragraph().getFontSettings(
2600 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2601 cursorVisRight(cur, true);
2604 case LFUN_FINISHED_BACKWARD:
2605 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
2606 cur.setCurrentFont();
2609 case LFUN_FINISHED_FORWARD:
2610 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
2612 cur.setCurrentFont();
2615 case LFUN_LAYOUT_PARAGRAPH: {
2617 params2string(cur.paragraph(), data);
2618 data = "show\n" + data;
2619 bv->showDialog("paragraph", data);
2623 case LFUN_PARAGRAPH_UPDATE: {
2625 params2string(cur.paragraph(), data);
2627 // Will the paragraph accept changes from the dialog?
2629 cur.inset().allowParagraphCustomization(cur.idx());
2631 data = "update " + convert<string>(accept) + '\n' + data;
2632 bv->updateDialog("paragraph", data);
2636 case LFUN_ACCENT_UMLAUT:
2637 case LFUN_ACCENT_CIRCUMFLEX:
2638 case LFUN_ACCENT_GRAVE:
2639 case LFUN_ACCENT_ACUTE:
2640 case LFUN_ACCENT_TILDE:
2641 case LFUN_ACCENT_PERISPOMENI:
2642 case LFUN_ACCENT_CEDILLA:
2643 case LFUN_ACCENT_MACRON:
2644 case LFUN_ACCENT_DOT:
2645 case LFUN_ACCENT_UNDERDOT:
2646 case LFUN_ACCENT_UNDERBAR:
2647 case LFUN_ACCENT_CARON:
2648 case LFUN_ACCENT_BREVE:
2649 case LFUN_ACCENT_TIE:
2650 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2651 case LFUN_ACCENT_CIRCLE:
2652 case LFUN_ACCENT_OGONEK:
2653 theApp()->handleKeyFunc(cmd.action());
2654 if (!cmd.argument().empty())
2655 // FIXME: Are all these characters encoded in one byte in utf8?
2656 bv->translateAndInsert(cmd.argument()[0], this, cur);
2657 cur.screenUpdateFlags(Update::FitCursor);
2660 case LFUN_FLOAT_LIST_INSERT: {
2661 DocumentClass const & tclass = bv->buffer().params().documentClass();
2662 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
2664 if (cur.selection())
2665 cutSelection(cur, false);
2666 breakParagraph(cur);
2668 if (cur.lastpos() != 0) {
2669 cursorBackward(cur);
2670 breakParagraph(cur);
2673 docstring const laystr = cur.inset().usePlainLayout() ?
2674 tclass.plainLayoutName() :
2675 tclass.defaultLayoutName();
2676 setLayout(cur, laystr);
2677 ParagraphParameters p;
2678 // FIXME If this call were replaced with one to clearParagraphParams(),
2679 // then we could get rid of this method altogether.
2680 setParagraphs(cur, p);
2681 // FIXME This should be simplified when InsetFloatList takes a
2682 // Buffer in its constructor.
2683 InsetFloatList * ifl = new InsetFloatList(cur.buffer(), to_utf8(cmd.argument()));
2684 ifl->setBuffer(bv->buffer());
2685 insertInset(cur, ifl);
2688 lyxerr << "Non-existent float type: "
2689 << to_utf8(cmd.argument()) << endl;
2694 case LFUN_CHANGE_ACCEPT: {
2695 acceptOrRejectChanges(cur, ACCEPT);
2699 case LFUN_CHANGE_REJECT: {
2700 acceptOrRejectChanges(cur, REJECT);
2704 case LFUN_THESAURUS_ENTRY: {
2705 Language const * language = cur.getFont().language();
2706 docstring arg = cmd.argument();
2708 arg = cur.selectionAsString(false);
2709 // Too large. We unselect if needed and try to get
2710 // the first word in selection or under cursor
2711 if (arg.size() > 100 || arg.empty()) {
2712 if (cur.selection()) {
2713 DocIterator selbeg = cur.selectionBegin();
2714 cur.clearSelection();
2715 setCursorIntern(cur, selbeg.pit(), selbeg.pos());
2716 cur.screenUpdateFlags(Update::Force);
2718 // Get word or selection
2719 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2720 arg = cur.selectionAsString(false);
2721 arg += " lang=" + from_ascii(language->lang());
2724 string lang = cmd.getArg(1);
2725 // This duplicates the code in GuiThesaurus::initialiseParams
2726 if (prefixIs(lang, "lang=")) {
2727 language = languages.getLanguage(lang.substr(5));
2729 language = cur.getFont().language();
2732 string lang = language->code();
2733 if (lyxrc.thesaurusdir_path.empty() && !thesaurus.thesaurusInstalled(from_ascii(lang))) {
2734 LYXERR(Debug::ACTION, "Command " << cmd << ". Thesaurus not found for language " << lang);
2735 frontend::Alert::warning(_("Path to thesaurus directory not set!"),
2736 _("The path to the thesaurus directory has not been specified.\n"
2737 "The thesaurus is not functional.\n"
2738 "Please refer to sec. 6.15.1 of the User's Guide for setup\n"
2741 bv->showDialog("thesaurus", to_utf8(arg));
2745 case LFUN_SPELLING_ADD: {
2746 Language const * language = getLanguage(cur, cmd.getArg(1));
2747 docstring word = from_utf8(cmd.getArg(0));
2749 word = cur.selectionAsString(false);
2751 if (word.size() > 100 || word.empty()) {
2752 // Get word or selection
2753 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2754 word = cur.selectionAsString(false);
2757 WordLangTuple wl(word, language);
2758 theSpellChecker()->insert(wl);
2762 case LFUN_SPELLING_ADD_LOCAL: {
2763 Language const * language = getLanguage(cur, cmd.getArg(1));
2764 docstring word = from_utf8(cmd.getArg(0));
2766 word = cur.selectionAsString(false);
2767 if (word.size() > 100)
2770 // Get word or selection
2771 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2772 word = cur.selectionAsString(false);
2775 WordLangTuple wl(word, language);
2776 if (!bv->buffer().params().spellignored(wl)) {
2777 cur.recordUndoBufferParams();
2778 bv->buffer().params().spellignore().push_back(wl);
2780 // trigger re-check of whole buffer
2781 bv->buffer().requestSpellcheck();
2786 case LFUN_SPELLING_REMOVE_LOCAL: {
2787 Language const * language = getLanguage(cur, cmd.getArg(1));
2788 docstring word = from_utf8(cmd.getArg(0));
2790 word = cur.selectionAsString(false);
2791 if (word.size() > 100)
2794 // Get word or selection
2795 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2796 word = cur.selectionAsString(false);
2799 WordLangTuple wl(word, language);
2800 bool has_item = false;
2801 vector<WordLangTuple>::const_iterator it = bv->buffer().params().spellignore().begin();
2802 for (; it != bv->buffer().params().spellignore().end(); ++it) {
2803 if (it->lang()->code() != wl.lang()->code())
2805 if (it->word() == wl.word()) {
2811 cur.recordUndoBufferParams();
2812 bv->buffer().params().spellignore().erase(it);
2814 // trigger re-check of whole buffer
2815 bv->buffer().requestSpellcheck();
2821 case LFUN_SPELLING_IGNORE: {
2822 Language const * language = getLanguage(cur, cmd.getArg(1));
2823 docstring word = from_utf8(cmd.getArg(0));
2825 word = cur.selectionAsString(false);
2827 if (word.size() > 100 || word.empty()) {
2828 // Get word or selection
2829 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2830 word = cur.selectionAsString(false);
2833 WordLangTuple wl(word, language);
2834 theSpellChecker()->accept(wl);
2838 case LFUN_SPELLING_REMOVE: {
2839 Language const * language = getLanguage(cur, cmd.getArg(1));
2840 docstring word = from_utf8(cmd.getArg(0));
2842 word = cur.selectionAsString(false);
2844 if (word.size() > 100 || word.empty()) {
2845 // Get word or selection
2846 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2847 word = cur.selectionAsString(false);
2850 WordLangTuple wl(word, language);
2851 theSpellChecker()->remove(wl);
2855 case LFUN_PARAGRAPH_PARAMS_APPLY: {
2856 // Given data, an encoding of the ParagraphParameters
2857 // generated in the Paragraph dialog, this function sets
2858 // the current paragraph, or currently selected paragraphs,
2860 // NOTE: This function overrides all existing settings.
2861 setParagraphs(cur, cmd.argument());
2862 cur.message(_("Paragraph layout set"));
2866 case LFUN_PARAGRAPH_PARAMS: {
2867 // Given data, an encoding of the ParagraphParameters as we'd
2868 // find them in a LyX file, this function modifies the current paragraph,
2869 // or currently selected paragraphs.
2870 // NOTE: This function only modifies, and does not override, existing
2872 setParagraphs(cur, cmd.argument(), true);
2873 cur.message(_("Paragraph layout set"));
2878 if (cur.selection()) {
2879 cur.selection(false);
2882 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
2883 // correct, but I'm not 100% sure -- dov, 071019
2884 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
2888 case LFUN_OUTLINE_UP: {
2889 pos_type const opos = cur.pos();
2890 outline(OutlineUp, cur, this);
2891 setCursor(cur, cur.pit(), opos);
2892 cur.forceBufferUpdate();
2897 case LFUN_OUTLINE_DOWN: {
2898 pos_type const opos = cur.pos();
2899 outline(OutlineDown, cur, this);
2900 setCursor(cur, cur.pit(), opos);
2901 cur.forceBufferUpdate();
2906 case LFUN_OUTLINE_IN:
2907 outline(OutlineIn, cur, this);
2908 cur.forceBufferUpdate();
2912 case LFUN_OUTLINE_OUT:
2913 outline(OutlineOut, cur, this);
2914 cur.forceBufferUpdate();
2918 case LFUN_SERVER_GET_STATISTICS: {
2919 DocIterator from, to;
2920 if (cur.selection()) {
2921 from = cur.selectionBegin();
2922 to = cur.selectionEnd();
2924 from = doc_iterator_begin(cur.buffer());
2925 to = doc_iterator_end(cur.buffer());
2928 cur.buffer()->updateStatistics(from, to);
2929 string const arg0 = cmd.getArg(0);
2930 if (arg0 == "words") {
2931 cur.message(convert<docstring>(cur.buffer()->wordCount()));
2932 } else if (arg0 == "chars") {
2933 cur.message(convert<docstring>(cur.buffer()->charCount(false)));
2934 } else if (arg0 == "chars-space") {
2935 cur.message(convert<docstring>(cur.buffer()->charCount(true)));
2937 cur.message(convert<docstring>(cur.buffer()->wordCount()) + " "
2938 + convert<docstring>(cur.buffer()->charCount(false)) + " "
2939 + convert<docstring>(cur.buffer()->charCount(true)));
2945 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
2950 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
2952 if (lyxrc.spellcheck_continuously && !needsUpdate) {
2953 // Check for misspelled text
2954 // The redraw is useful because of the painting of
2955 // misspelled markers depends on the cursor position.
2956 // Trigger a redraw for cursor moves inside misspelled text.
2957 if (!cur.inTexted()) {
2958 // move from regular text to math
2959 needsUpdate = last_misspelled;
2960 } else if (oldTopSlice != cur.top() || oldBoundary != cur.boundary()) {
2961 // move inside regular text
2962 needsUpdate = last_misspelled
2963 || cur.paragraph().isMisspelled(cur.pos(), true);
2967 // FIXME: The cursor flag is reset two lines below
2968 // so we need to check here if some of the LFUN did touch that.
2969 // for now only Text::erase() and Text::backspace() do that.
2970 // The plan is to verify all the LFUNs and then to remove this
2971 // singleParUpdate boolean altogether.
2972 if (cur.result().screenUpdate() & Update::Force) {
2973 singleParUpdate = false;
2977 // FIXME: the following code should go in favor of fine grained
2978 // update flag treatment.
2979 if (singleParUpdate) {
2980 // Inserting characters does not change par height in general. So, try
2981 // to update _only_ this paragraph. BufferView will detect if a full
2982 // metrics update is needed anyway.
2983 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
2987 && &oldTopSlice.inset() == &cur.inset()
2988 && oldTopSlice.idx() == cur.idx()
2989 && !oldSelection // oldSelection is a backup of cur.selection() at the beginning of the function.
2990 && !cur.selection())
2991 // FIXME: it would be better if we could just do this
2993 //if (cur.result().update() != Update::FitCursor)
2994 // cur.noScreenUpdate();
2996 // But some LFUNs do not set Update::FitCursor when needed, so we
2997 // do it for all. This is not very harmfull as FitCursor will provoke
2998 // a full redraw only if needed but still, a proper review of all LFUN
2999 // should be done and this needsUpdate boolean can then be removed.
3000 cur.screenUpdateFlags(Update::FitCursor);
3002 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
3006 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
3007 FuncStatus & status) const
3009 LBUFERR(this == cur.text());
3011 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
3013 bool allow_in_passthru = false;
3014 InsetCode code = NO_CODE;
3016 switch (cmd.action()) {
3018 case LFUN_DEPTH_DECREMENT:
3019 enable = changeDepthAllowed(cur, DEC_DEPTH);
3022 case LFUN_DEPTH_INCREMENT:
3023 enable = changeDepthAllowed(cur, INC_DEPTH);
3027 // FIXME We really should not allow this to be put, e.g.,
3028 // in a footnote, or in ERT. But it would make sense in a
3029 // branch, so I'm not sure what to do.
3030 status.setOnOff(cur.paragraph().params().startOfAppendix());
3033 case LFUN_DIALOG_SHOW_NEW_INSET:
3034 if (cmd.argument() == "bibitem")
3035 code = BIBITEM_CODE;
3036 else if (cmd.argument() == "bibtex") {
3038 // not allowed in description items
3039 enable = !inDescriptionItem(cur);
3041 else if (cmd.argument() == "box")
3043 else if (cmd.argument() == "branch")
3045 else if (cmd.argument() == "citation")
3047 else if (cmd.argument() == "counter")
3048 code = COUNTER_CODE;
3049 else if (cmd.argument() == "ert")
3051 else if (cmd.argument() == "external")
3052 code = EXTERNAL_CODE;
3053 else if (cmd.argument() == "float")
3055 else if (cmd.argument() == "graphics")
3056 code = GRAPHICS_CODE;
3057 else if (cmd.argument() == "href")
3058 code = HYPERLINK_CODE;
3059 else if (cmd.argument() == "include")
3060 code = INCLUDE_CODE;
3061 else if (cmd.argument() == "index")
3063 else if (cmd.argument() == "index_print")
3064 code = INDEX_PRINT_CODE;
3065 else if (cmd.argument() == "listings")
3066 code = LISTINGS_CODE;
3067 else if (cmd.argument() == "mathspace")
3068 code = MATH_HULL_CODE;
3069 else if (cmd.argument() == "nomenclature")
3070 code = NOMENCL_CODE;
3071 else if (cmd.argument() == "nomencl_print")
3072 code = NOMENCL_PRINT_CODE;
3073 else if (cmd.argument() == "label")
3075 else if (cmd.argument() == "line")
3077 else if (cmd.argument() == "note")
3079 else if (cmd.argument() == "phantom")
3080 code = PHANTOM_CODE;
3081 else if (cmd.argument() == "ref")
3083 else if (cmd.argument() == "space")
3085 else if (cmd.argument() == "toc")
3087 else if (cmd.argument() == "vspace")
3089 else if (cmd.argument() == "wrap")
3093 case LFUN_ERT_INSERT:
3096 case LFUN_LISTING_INSERT:
3097 code = LISTINGS_CODE;
3098 // not allowed in description items
3099 enable = !inDescriptionItem(cur);
3101 case LFUN_FOOTNOTE_INSERT:
3104 case LFUN_TABULAR_INSERT:
3105 code = TABULAR_CODE;
3107 case LFUN_TABULAR_STYLE_INSERT:
3108 code = TABULAR_CODE;
3110 case LFUN_MARGINALNOTE_INSERT:
3113 case LFUN_FLOAT_INSERT:
3114 case LFUN_FLOAT_WIDE_INSERT:
3115 // FIXME: If there is a selection, we should check whether there
3116 // are floats in the selection, but this has performance issues, see
3117 // LFUN_CHANGE_ACCEPT/REJECT.
3119 if (inDescriptionItem(cur))
3120 // not allowed in description items
3123 InsetCode const inset_code = cur.inset().lyxCode();
3125 // algorithm floats cannot be put in another float
3126 if (to_utf8(cmd.argument()) == "algorithm") {
3127 enable = inset_code != WRAP_CODE && inset_code != FLOAT_CODE;
3131 // for figures and tables: only allow in another
3132 // float or wrap if it is of the same type and
3133 // not a subfloat already
3134 if(cur.inset().lyxCode() == code) {
3135 InsetFloat const & ins =
3136 static_cast<InsetFloat const &>(cur.inset());
3137 enable = ins.params().type == to_utf8(cmd.argument())
3138 && !ins.params().subfloat;
3139 } else if(cur.inset().lyxCode() == WRAP_CODE) {
3140 InsetWrap const & ins =
3141 static_cast<InsetWrap const &>(cur.inset());
3142 enable = ins.params().type == to_utf8(cmd.argument());
3146 case LFUN_WRAP_INSERT:
3148 // not allowed in description items
3149 enable = !inDescriptionItem(cur);
3151 case LFUN_FLOAT_LIST_INSERT: {
3152 code = FLOAT_LIST_CODE;
3153 // not allowed in description items
3154 enable = !inDescriptionItem(cur);
3156 FloatList const & floats = cur.buffer()->params().documentClass().floats();
3157 FloatList::const_iterator cit = floats[to_ascii(cmd.argument())];
3158 // make sure we know about such floats
3159 if (cit == floats.end() ||
3160 // and that we know how to generate a list of them
3161 (!cit->second.usesFloatPkg() && cit->second.listCommand().empty())) {
3162 status.setUnknown(true);
3163 // probably not necessary, but...
3169 case LFUN_CAPTION_INSERT: {
3170 code = CAPTION_CODE;
3171 string arg = cmd.getArg(0);
3172 bool varia = arg != "Unnumbered"
3173 && cur.inset().allowsCaptionVariation(arg);
3174 // not allowed in description items,
3175 // and in specific insets
3176 enable = !inDescriptionItem(cur)
3177 && (varia || arg.empty() || arg == "Standard");
3180 case LFUN_NOTE_INSERT:
3183 case LFUN_FLEX_INSERT: {
3185 docstring s = from_utf8(cmd.getArg(0));
3186 // Prepend "Flex:" prefix if not there
3187 if (!prefixIs(s, from_ascii("Flex:")))
3188 s = from_ascii("Flex:") + s;
3189 if (!cur.buffer()->params().documentClass().hasInsetLayout(s))
3193 cur.buffer()->params().documentClass().insetLayout(s).lyxtype();
3194 if (ilt != InsetLyXType::CHARSTYLE
3195 && ilt != InsetLyXType::CUSTOM
3196 && ilt != InsetLyXType::STANDARD)
3201 case LFUN_BOX_INSERT:
3204 case LFUN_BRANCH_INSERT:
3206 if (cur.buffer()->masterBuffer()->params().branchlist().empty()
3207 && cur.buffer()->params().branchlist().empty())
3210 case LFUN_IPA_INSERT:
3213 case LFUN_PHANTOM_INSERT:
3214 code = PHANTOM_CODE;
3216 case LFUN_LABEL_INSERT:
3219 case LFUN_INFO_INSERT:
3221 enable = cmd.argument().empty()
3222 || infoparams.validateArgument(cur.buffer(), cmd.argument(), true);
3224 case LFUN_ARGUMENT_INSERT: {
3226 allow_in_passthru = true;
3227 string const arg = cmd.getArg(0);
3232 Layout const & lay = cur.paragraph().layout();
3233 Layout::LaTeXArgMap args = lay.args();
3234 Layout::LaTeXArgMap::const_iterator const lait =
3236 if (lait != args.end()) {
3238 pit_type pit = cur.pit();
3239 pit_type lastpit = cur.pit();
3240 if (lay.isEnvironment() && !prefixIs(arg, "item:")) {
3241 // In a sequence of "merged" environment layouts, we only allow
3242 // non-item arguments once.
3243 lastpit = cur.lastpit();
3244 // get the first paragraph in sequence with this layout
3245 depth_type const current_depth = cur.paragraph().params().depth();
3249 Paragraph cpar = pars_[pit - 1];
3250 if (cpar.layout() == lay && cpar.params().depth() == current_depth)
3256 for (; pit <= lastpit; ++pit) {
3257 if (pars_[pit].layout() != lay)
3259 for (auto const & table : pars_[pit].insetList())
3260 if (InsetArgument const * ins = table.inset->asInsetArgument())
3261 if (ins->name() == arg) {
3262 // we have this already
3271 case LFUN_INDEX_INSERT:
3274 case LFUN_INDEX_PRINT:
3275 code = INDEX_PRINT_CODE;
3276 // not allowed in description items
3277 enable = !inDescriptionItem(cur);
3279 case LFUN_NOMENCL_INSERT:
3280 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
3284 code = NOMENCL_CODE;
3286 case LFUN_NOMENCL_PRINT:
3287 code = NOMENCL_PRINT_CODE;
3288 // not allowed in description items
3289 enable = !inDescriptionItem(cur);
3291 case LFUN_HREF_INSERT:
3292 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
3296 code = HYPERLINK_CODE;
3298 case LFUN_IPAMACRO_INSERT: {
3299 string const arg = cmd.getArg(0);
3301 code = IPADECO_CODE;
3303 code = IPACHAR_CODE;
3306 case LFUN_QUOTE_INSERT:
3307 // always allow this, since we will inset a raw quote
3308 // if an inset is not allowed.
3309 allow_in_passthru = true;
3311 case LFUN_SPECIALCHAR_INSERT:
3312 code = SPECIALCHAR_CODE;
3314 case LFUN_SPACE_INSERT:
3315 // slight hack: we know this is allowed in math mode
3319 case LFUN_PREVIEW_INSERT:
3320 code = PREVIEW_CODE;
3322 case LFUN_SCRIPT_INSERT:
3326 case LFUN_MATH_INSERT:
3327 case LFUN_MATH_AMS_MATRIX:
3328 case LFUN_MATH_MATRIX:
3329 case LFUN_MATH_DELIM:
3330 case LFUN_MATH_BIGDELIM:
3331 case LFUN_MATH_DISPLAY:
3332 case LFUN_MATH_MODE:
3333 case LFUN_MATH_MACRO:
3334 case LFUN_MATH_SUBSCRIPT:
3335 case LFUN_MATH_SUPERSCRIPT:
3336 code = MATH_HULL_CODE;
3339 case LFUN_REGEXP_MODE:
3340 code = MATH_HULL_CODE;
3341 enable = cur.buffer()->isInternal() && !cur.inRegexped();
3344 case LFUN_INSET_MODIFY:
3345 // We need to disable this, because we may get called for a
3347 // InsetTabular::getStatus() -> InsetText::getStatus()
3348 // and we don't handle LFUN_INSET_MODIFY.
3352 case LFUN_FONT_EMPH:
3353 status.setOnOff(fontinfo.emph() == FONT_ON);
3354 enable = !cur.paragraph().isPassThru();
3357 case LFUN_FONT_ITAL:
3358 status.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
3359 enable = !cur.paragraph().isPassThru();
3362 case LFUN_FONT_NOUN:
3363 status.setOnOff(fontinfo.noun() == FONT_ON);
3364 enable = !cur.paragraph().isPassThru();
3367 case LFUN_FONT_BOLD:
3368 case LFUN_FONT_BOLDSYMBOL:
3369 status.setOnOff(fontinfo.series() == BOLD_SERIES);
3370 enable = !cur.paragraph().isPassThru();
3373 case LFUN_FONT_SANS:
3374 status.setOnOff(fontinfo.family() == SANS_FAMILY);
3375 enable = !cur.paragraph().isPassThru();
3378 case LFUN_FONT_ROMAN:
3379 status.setOnOff(fontinfo.family() == ROMAN_FAMILY);
3380 enable = !cur.paragraph().isPassThru();
3383 case LFUN_FONT_TYPEWRITER:
3384 status.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
3385 enable = !cur.paragraph().isPassThru();
3389 enable = cur.selection();
3393 if (cmd.argument().empty()) {
3394 if (theClipboard().isInternal())
3395 enable = cap::numberOfSelections() > 0;
3397 enable = !theClipboard().empty();
3401 // we have an argument
3402 string const arg = to_utf8(cmd.argument());
3403 if (isStrUnsignedInt(arg)) {
3404 // it's a number and therefore means the internal stack
3405 unsigned int n = convert<unsigned int>(arg);
3406 enable = cap::numberOfSelections() > n;
3410 // explicit text type?
3411 if (arg == "html") {
3412 // Do not enable for PlainTextType, since some tidying in the
3413 // frontend is needed for HTML, which is too unsafe for plain text.
3414 enable = theClipboard().hasTextContents(Clipboard::HtmlTextType);
3416 } else if (arg == "latex") {
3417 // LaTeX is usually not available on the clipboard with
3418 // the correct MIME type, but in plain text.
3419 enable = theClipboard().hasTextContents(Clipboard::PlainTextType) ||
3420 theClipboard().hasTextContents(Clipboard::LaTeXTextType);
3424 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
3426 type = Clipboard::PdfGraphicsType;
3427 else if (arg == "png")
3428 type = Clipboard::PngGraphicsType;
3429 else if (arg == "jpeg")
3430 type = Clipboard::JpegGraphicsType;
3431 else if (arg == "linkback")
3432 type = Clipboard::LinkBackGraphicsType;
3433 else if (arg == "emf")
3434 type = Clipboard::EmfGraphicsType;
3435 else if (arg == "wmf")
3436 type = Clipboard::WmfGraphicsType;
3439 LYXERR0("Unrecognized graphics type: " << arg);
3440 // we don't want to assert if the user just mistyped the LFUN
3441 LATTEST(cmd.origin() != FuncRequest::INTERNAL);
3445 enable = theClipboard().hasGraphicsContents(type);
3449 case LFUN_CLIPBOARD_PASTE:
3450 case LFUN_CLIPBOARD_PASTE_SIMPLE:
3451 enable = !theClipboard().empty();
3454 case LFUN_PRIMARY_SELECTION_PASTE:
3455 status.setUnknown(!theSelection().supported());
3456 enable = cur.selection() || !theSelection().empty();
3459 case LFUN_SELECTION_PASTE:
3460 enable = cap::selection();
3463 case LFUN_PARAGRAPH_MOVE_UP:
3464 enable = cur.pit() > 0 && !cur.selection();
3467 case LFUN_PARAGRAPH_MOVE_DOWN:
3468 enable = cur.pit() < cur.lastpit() && !cur.selection();
3471 case LFUN_CHANGE_ACCEPT:
3472 case LFUN_CHANGE_REJECT:
3473 if (!cur.selection())
3474 enable = cur.paragraph().isChanged(cur.pos());
3476 // will enable if there is a change in the selection
3479 // cheap improvement for efficiency: using cached
3480 // buffer variable, if there is no change in the
3481 // document, no need to check further.
3482 if (!cur.buffer()->areChangesPresent())
3485 for (DocIterator it = cur.selectionBegin(); ; it.forwardPar()) {
3486 pos_type const beg = it.pos();
3488 bool const in_last_par = (it.pit() == cur.selectionEnd().pit() &&
3489 it.idx() == cur.selectionEnd().idx());
3491 end = cur.selectionEnd().pos();
3493 // the +1 is needed for cases, e.g., where there is a
3494 // paragraph break. See #11629.
3495 end = it.lastpos() + 1;
3496 if (beg != end && it.paragraph().isChanged(beg, end)) {
3500 if (beg != end && it.paragraph().hasChangedInsets(beg, end)) {
3510 case LFUN_OUTLINE_UP:
3511 case LFUN_OUTLINE_DOWN:
3512 case LFUN_OUTLINE_IN:
3513 case LFUN_OUTLINE_OUT:
3514 // FIXME: LyX is not ready for outlining within inset.
3515 enable = isMainText()
3516 && cur.buffer()->text().getTocLevel(cur.pit()) != Layout::NOT_IN_TOC;
3519 case LFUN_NEWLINE_INSERT:
3520 // LaTeX restrictions (labels or empty par)
3521 enable = !cur.paragraph().isPassThru()
3522 && cur.pos() > cur.paragraph().beginOfBody();
3525 case LFUN_SEPARATOR_INSERT:
3526 // Always enabled for now
3530 case LFUN_TAB_INSERT:
3531 case LFUN_TAB_DELETE:
3532 enable = cur.paragraph().isPassThru();
3535 case LFUN_GRAPHICS_SET_GROUP: {
3536 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
3540 status.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
3544 case LFUN_NEWPAGE_INSERT:
3545 // not allowed in description items
3546 code = NEWPAGE_CODE;
3547 enable = !inDescriptionItem(cur);
3551 enable = !cur.paragraph().isPassThru();
3552 status.setOnOff(cmd.getArg(0) == cur.real_current_font.language()->lang());
3555 case LFUN_PARAGRAPH_BREAK:
3556 enable = inset().allowMultiPar();
3559 case LFUN_SPELLING_ADD:
3560 case LFUN_SPELLING_ADD_LOCAL:
3561 case LFUN_SPELLING_REMOVE_LOCAL:
3562 case LFUN_SPELLING_IGNORE:
3563 case LFUN_SPELLING_REMOVE:
3564 enable = theSpellChecker() != nullptr;
3565 if (enable && !cmd.getArg(1).empty()) {
3566 // validate explicitly given language
3567 Language const * const lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
3568 enable &= lang != nullptr;
3573 case LFUN_LAYOUT_TOGGLE: {
3574 bool const ignoreautonests = cmd.getArg(1) == "ignoreautonests";
3575 docstring const req_layout = ignoreautonests ? from_utf8(cmd.getArg(0)) : cmd.argument();
3576 docstring const layout = resolveLayout(req_layout, cur);
3578 // FIXME: make this work in multicell selection case
3579 enable = !owner_->forcePlainLayout() && !layout.empty() && !cur.selIsMultiCell();
3580 status.setOnOff(!owner_->forcePlainLayout() && !cur.selIsMultiCell()
3581 && isAlreadyLayout(layout, cur));
3585 case LFUN_ENVIRONMENT_SPLIT: {
3586 if (cmd.argument() == "outer") {
3587 // check if we have an environment in our nesting hierarchy
3589 depth_type const current_depth = cur.paragraph().params().depth();
3590 pit_type pit = cur.pit();
3591 Paragraph cpar = pars_[pit];
3593 if (pit == 0 || cpar.params().depth() == 0)
3597 if (cpar.params().depth() < current_depth)
3598 res = cpar.layout().isEnvironment();
3603 else if (cmd.argument() == "previous") {
3604 // look if we have an environment in the previous par
3605 pit_type pit = cur.pit();
3606 Paragraph cpar = pars_[pit];
3610 enable = cpar.layout().isEnvironment();
3616 else if (cur.paragraph().layout().isEnvironment()) {
3617 enable = cmd.argument() == "before"
3618 || cur.pos() > 0 || !isFirstInSequence(cur.pit());
3625 case LFUN_LAYOUT_PARAGRAPH:
3626 case LFUN_PARAGRAPH_PARAMS:
3627 case LFUN_PARAGRAPH_PARAMS_APPLY:
3628 case LFUN_PARAGRAPH_UPDATE:
3629 enable = owner_->allowParagraphCustomization();
3632 // FIXME: why are accent lfuns forbidden with pass_thru layouts?
3633 // Because they insert COMBINING DIACRITICAL Unicode characters,
3634 // that cannot be handled by LaTeX but must be converted according
3635 // to the definition in lib/unicodesymbols?
3636 case LFUN_ACCENT_ACUTE:
3637 case LFUN_ACCENT_BREVE:
3638 case LFUN_ACCENT_CARON:
3639 case LFUN_ACCENT_CEDILLA:
3640 case LFUN_ACCENT_CIRCLE:
3641 case LFUN_ACCENT_CIRCUMFLEX:
3642 case LFUN_ACCENT_DOT:
3643 case LFUN_ACCENT_GRAVE:
3644 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
3645 case LFUN_ACCENT_MACRON:
3646 case LFUN_ACCENT_OGONEK:
3647 case LFUN_ACCENT_TIE:
3648 case LFUN_ACCENT_TILDE:
3649 case LFUN_ACCENT_PERISPOMENI:
3650 case LFUN_ACCENT_UMLAUT:
3651 case LFUN_ACCENT_UNDERBAR:
3652 case LFUN_ACCENT_UNDERDOT:
3653 case LFUN_FONT_FRAK:
3654 case LFUN_FONT_SIZE:
3655 case LFUN_FONT_STATE:
3656 case LFUN_FONT_UNDERLINE:
3657 case LFUN_FONT_STRIKEOUT:
3658 case LFUN_FONT_CROSSOUT:
3659 case LFUN_FONT_UNDERUNDERLINE:
3660 case LFUN_FONT_UNDERWAVE:
3661 case LFUN_FONT_NO_SPELLCHECK:
3662 case LFUN_TEXTSTYLE_UPDATE:
3663 enable = !cur.paragraph().isPassThru();
3666 case LFUN_FONT_DEFAULT: {
3667 Font font(inherit_font, ignore_language);
3668 BufferParams const & bp = cur.buffer()->masterParams();
3669 if (cur.selection()) {
3671 // Check if we have a non-default font attribute
3672 // in the selection range.
3673 DocIterator const from = cur.selectionBegin();
3674 DocIterator const to = cur.selectionEnd();
3675 for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) {
3676 if (!dit.inTexted()) {
3680 Paragraph const & par = dit.paragraph();
3681 pos_type const pos = dit.pos();
3682 Font tmp = par.getFontSettings(bp, pos);
3683 if (tmp.fontInfo() != font.fontInfo()
3684 || tmp.language() != bp.language) {
3692 // Disable if all is default already.
3693 enable = (cur.current_font.fontInfo() != font.fontInfo()
3694 || cur.current_font.language() != bp.language);
3698 case LFUN_TEXTSTYLE_APPLY:
3699 enable = !freeFonts.empty();
3702 case LFUN_WORD_DELETE_FORWARD:
3703 case LFUN_WORD_DELETE_BACKWARD:
3704 case LFUN_LINE_DELETE_FORWARD:
3705 case LFUN_WORD_FORWARD:
3706 case LFUN_WORD_BACKWARD:
3707 case LFUN_WORD_RIGHT:
3708 case LFUN_WORD_LEFT:
3709 case LFUN_CHAR_FORWARD:
3710 case LFUN_CHAR_FORWARD_SELECT:
3711 case LFUN_CHAR_BACKWARD:
3712 case LFUN_CHAR_BACKWARD_SELECT:
3713 case LFUN_CHAR_LEFT:
3714 case LFUN_CHAR_LEFT_SELECT:
3715 case LFUN_CHAR_RIGHT:
3716 case LFUN_CHAR_RIGHT_SELECT:
3718 case LFUN_UP_SELECT:
3720 case LFUN_DOWN_SELECT:
3721 case LFUN_PARAGRAPH_SELECT:
3722 case LFUN_PARAGRAPH_UP_SELECT:
3723 case LFUN_PARAGRAPH_DOWN_SELECT:
3724 case LFUN_LINE_BEGIN_SELECT:
3725 case LFUN_LINE_END_SELECT:
3726 case LFUN_WORD_FORWARD_SELECT:
3727 case LFUN_WORD_BACKWARD_SELECT:
3728 case LFUN_WORD_RIGHT_SELECT:
3729 case LFUN_WORD_LEFT_SELECT:
3730 case LFUN_WORD_SELECT:
3731 case LFUN_SECTION_SELECT:
3732 case LFUN_BUFFER_BEGIN:
3733 case LFUN_BUFFER_END:
3734 case LFUN_BUFFER_BEGIN_SELECT:
3735 case LFUN_BUFFER_END_SELECT:
3736 case LFUN_INSET_BEGIN:
3737 case LFUN_INSET_END:
3738 case LFUN_INSET_BEGIN_SELECT:
3739 case LFUN_INSET_END_SELECT:
3740 case LFUN_PARAGRAPH_UP:
3741 case LFUN_PARAGRAPH_DOWN:
3742 case LFUN_LINE_BEGIN:
3744 case LFUN_CHAR_DELETE_FORWARD:
3745 case LFUN_CHAR_DELETE_BACKWARD:
3746 case LFUN_WORD_UPCASE:
3747 case LFUN_WORD_LOWCASE:
3748 case LFUN_WORD_CAPITALIZE:
3749 case LFUN_CHARS_TRANSPOSE:
3750 case LFUN_SERVER_GET_XY:
3751 case LFUN_SERVER_SET_XY:
3752 case LFUN_SERVER_GET_LAYOUT:
3753 case LFUN_SELF_INSERT:
3754 case LFUN_UNICODE_INSERT:
3755 case LFUN_THESAURUS_ENTRY:
3757 case LFUN_SERVER_GET_STATISTICS:
3758 // these are handled in our dispatch()
3762 case LFUN_INSET_INSERT: {
3763 string const type = cmd.getArg(0);
3764 if (type == "toc") {
3766 // not allowed in description items
3767 //FIXME: couldn't this be merged in Inset::insetAllowed()?
3768 enable = !inDescriptionItem(cur);
3775 case LFUN_SEARCH_IGNORE: {
3776 bool const value = cmd.getArg(1) == "true";
3777 setIgnoreFormat(cmd.getArg(0), value);
3787 || !cur.inset().insetAllowed(code)
3788 || (cur.paragraph().layout().pass_thru && !allow_in_passthru)))
3791 status.setEnabled(enable);
3796 void Text::pasteString(Cursor & cur, docstring const & clip,
3799 if (!clip.empty()) {
3802 insertStringAsParagraphs(cur, clip, cur.current_font);
3804 insertStringAsLines(cur, clip, cur.current_font);
3809 // FIXME: an item inset would make things much easier.
3810 bool Text::inDescriptionItem(Cursor const & cur) const
3812 Paragraph const & par = cur.paragraph();
3813 pos_type const pos = cur.pos();
3814 pos_type const body_pos = par.beginOfBody();
3816 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
3817 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
3818 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
3821 return (pos < body_pos
3823 && (pos == 0 || par.getChar(pos - 1) != ' ')));
3827 std::vector<docstring> Text::getFreeFonts() const
3829 vector<docstring> ffList;
3831 for (auto const & f : freeFonts)
3832 ffList.push_back(f.first);