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/InsetIndexMacro.h"
62 #include "insets/InsetIPAMacro.h"
63 #include "insets/InsetNewline.h"
64 #include "insets/InsetQuotes.h"
65 #include "insets/InsetSpecialChar.h"
66 #include "insets/InsetText.h"
67 #include "insets/InsetWrap.h"
69 #include "support/convert.h"
70 #include "support/debug.h"
71 #include "support/docstring_list.h"
72 #include "support/filetools.h"
73 #include "support/gettext.h"
74 #include "support/lassert.h"
75 #include "support/limited_stack.h"
76 #include "support/lstrings.h"
78 #include "mathed/InsetMathHull.h"
79 #include "mathed/InsetMathMacroTemplate.h"
87 using namespace lyx::support;
91 using cap::copySelection;
92 using cap::copySelectionToTemp;
93 using cap::cutSelection;
94 using cap::cutSelectionToTemp;
95 using cap::pasteFromStack;
96 using cap::pasteFromTemp;
97 using cap::pasteClipboardText;
98 using cap::pasteClipboardGraphics;
99 using cap::replaceSelection;
100 using cap::grabAndEraseSelection;
101 using cap::selClearOrDel;
102 using cap::pasteSimpleText;
103 using frontend::Clipboard;
106 typedef limited_stack<pair<docstring, Font>> FontStack;
107 static FontStack freeFonts(15);
108 static bool toggleall = false;
110 static void toggleAndShow(Cursor & cur, Text * text,
111 Font const & font, bool togall = true)
113 text->toggleFree(cur, font, togall);
115 if (font.language() != ignore_language ||
116 font.fontInfo().number() != FONT_IGNORE) {
117 TextMetrics const & tm = cur.bv().textMetrics(text);
118 if (cur.boundary() != tm.isRTLBoundary(cur.pit(), cur.pos(),
119 cur.real_current_font))
120 text->setCursor(cur, cur.pit(), cur.pos(),
121 false, !cur.boundary());
122 if (font.language() != ignore_language)
123 // We need a buffer update if we change the language
124 // (e.g., with info insets or if the selection contains
126 cur.forceBufferUpdate();
131 static void moveCursor(Cursor & cur, bool selecting)
133 if (selecting || cur.mark())
138 static void finishChange(Cursor & cur, bool selecting)
141 moveCursor(cur, selecting);
145 static void mathDispatch(Cursor & cur, FuncRequest const & cmd)
148 docstring sel = cur.selectionAsString(false);
150 // It may happen that sel is empty but there is a selection
151 replaceSelection(cur);
153 // Is this a valid formula?
157 #ifdef ENABLE_ASSERTIONS
158 const int old_pos = cur.pos();
160 cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
161 #ifdef ENABLE_ASSERTIONS
162 LATTEST(old_pos == cur.pos());
164 cur.nextInset()->edit(cur, true);
165 if (cmd.action() != LFUN_MATH_MODE)
166 // LFUN_MATH_MODE has a different meaning in math mode
169 InsetMathHull * formula = new InsetMathHull(cur.buffer());
170 string const selstr = to_utf8(sel);
171 istringstream is(selstr);
174 if (!formula->readQuiet(lex)) {
175 // No valid formula, let's try with delims
176 is.str("$" + selstr + "$");
178 if (!formula->readQuiet(lex)) {
179 // Still not valid, leave it as is
187 cur.nextInset()->edit(cur, true);
188 LASSERT(cur.inMathed(), return);
192 cur.pos() = cur.lastpos();
193 if (cmd.action() != LFUN_MATH_MODE)
194 // LFUN_MATH_MODE has a different meaning in math mode
196 cur.clearSelection();
197 cur.pos() = cur.lastpos();
201 cur.message(from_utf8(N_("Math editor mode")));
203 cur.message(from_utf8(N_("No valid math formula")));
207 void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
209 LASSERT(cmd.action() == LFUN_REGEXP_MODE, return);
210 if (cur.inRegexped()) {
211 cur.message(_("Already in regular expression mode"));
215 docstring sel = cur.selectionAsString(false);
217 // It may happen that sel is empty but there is a selection
218 replaceSelection(cur);
220 cur.insert(new InsetMathHull(cur.buffer(), hullRegexp));
221 cur.nextInset()->edit(cur, true);
224 cur.message(_("Regexp editor mode"));
228 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
231 cap::replaceSelection(cur);
232 cur.insert(new InsetSpecialChar(kind));
237 static void ipaChar(Cursor & cur, InsetIPAChar::Kind kind)
240 cap::replaceSelection(cur);
241 cur.insert(new InsetIPAChar(kind));
246 static bool doInsertInset(Cursor & cur, Text * text,
247 FuncRequest const & cmd, bool edit,
248 bool pastesel, bool resetfont = false)
250 Buffer & buffer = cur.bv().buffer();
251 BufferParams const & bparams = buffer.params();
252 Inset * inset = createInset(&buffer, cmd);
256 if (InsetCollapsible * ci = inset->asInsetCollapsible())
257 ci->setButtonLabel();
260 if (cmd.action() == LFUN_ARGUMENT_INSERT) {
261 bool cotextinsert = false;
262 InsetArgument * const ia = static_cast<InsetArgument *>(inset);
263 Layout const & lay = cur.paragraph().layout();
264 Layout::LaTeXArgMap args = lay.args();
265 Layout::LaTeXArgMap::const_iterator const lait = args.find(ia->name());
266 if (lait != args.end())
267 cotextinsert = (*lait).second.insertcotext;
269 InsetLayout const & il = cur.inset().getLayout();
271 Layout::LaTeXArgMap::const_iterator const ilait = args.find(ia->name());
272 if (ilait != args.end())
273 cotextinsert = (*ilait).second.insertcotext;
275 // The argument requests to insert a copy of the co-text to the inset
278 // If we have a selection within a paragraph, use this
279 if (cur.selection() && cur.selBegin().pit() == cur.selEnd().pit())
280 ds = cur.selectionAsString(false);
281 // else use the whole paragraph
283 ds = cur.paragraph().asString();
284 text->insertInset(cur, inset);
285 ia->init(cur.paragraph());
287 inset->edit(cur, true);
288 // Now put co-text into inset
289 Font const f(inherit_font, cur.current_font.language());
291 cur.text()->insertStringAsLines(cur, ds, f);
292 cur.leaveInset(*inset);
299 bool move_layout = false;
300 if (cur.selection()) {
301 if (cmd.action() == LFUN_INDEX_INSERT)
302 copySelectionToTemp(cur);
304 cutSelectionToTemp(cur, pastesel);
305 /* Move layout information inside the inset if the whole
306 * paragraph and the inset allows setting layout
307 * FIXME: this does not work as expected when change tracking is on
308 * However, we do not really know what to do in this case.
309 * FIXME: figure out a good test in the environment case (see #12251).
311 if (cur.paragraph().layout().isCommand()
312 && cur.paragraph().empty()
313 && !inset->forcePlainLayout()) {
314 cur.paragraph().setPlainOrDefaultLayout(bparams.documentClass());
318 cur.clearSelection();
320 } else if (cmd.action() == LFUN_INDEX_INSERT) {
321 gotsel = text->selectWordWhenUnderCursor(cur, WHOLE_WORD);
322 copySelectionToTemp(cur);
323 cur.clearSelection();
325 text->insertInset(cur, inset);
327 InsetText * inset_text = inset->asInsetText();
329 Font const & font = inset->inheritFont()
330 ? cur.bv().textMetrics(text).displayFont(cur.pit(), cur.pos())
332 inset_text->setOuterFont(cur.bv(), font.fontInfo());
335 if (cmd.action() == LFUN_ARGUMENT_INSERT) {
336 InsetArgument * const ia = static_cast<InsetArgument *>(inset);
337 ia->init(cur.paragraph());
341 inset->edit(cur, true);
343 if (!gotsel || !pastesel)
346 pasteFromTemp(cur, cur.buffer()->errorList("Paste"));
347 cur.buffer()->errors("Paste");
348 cur.clearSelection(); // bug 393
352 // Reset of font (not language) is requested.
353 // Used by InsetIndex (#11961).
354 Language const * lang = cur.getFont().language();
355 Font font(bparams.getFont().fontInfo(), lang);
356 cur.paragraph().resetFonts(font);
358 inset_text->fixParagraphsFont();
361 /* If the containing paragraph has kept its layout, reset the
362 * layout of the first paragraph of the inset.
365 cur.paragraph().setPlainOrDefaultLayout(bparams.documentClass());
366 // FIXME: what does this do?
367 if (cmd.action() == LFUN_FLEX_INSERT)
370 cur.leaveInset(*inset);
371 if (cmd.action() == LFUN_PREVIEW_INSERT
372 || cmd.action() == LFUN_IPA_INSERT)
374 notifyCursorLeavesOrEnters(old, cur);
376 cur.leaveInset(*inset);
377 // reset surrounding par to default
378 DocumentClass const & dc = bparams.documentClass();
379 docstring const layoutname = inset->usePlainLayout()
380 ? dc.plainLayoutName()
381 : dc.defaultLayoutName();
382 text->setLayout(cur, layoutname);
388 /// the type of outline operation
390 OutlineUp, // Move this header with text down
391 OutlineDown, // Move this header with text up
392 OutlineIn, // Make this header deeper
393 OutlineOut // Make this header shallower
397 static void insertSeparator(Cursor const & cur, depth_type const depth)
399 Buffer & buf = *cur.buffer();
400 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
401 DocumentClass const & tc = buf.params().documentClass();
402 lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") + tc.plainLayout().name()
403 + from_ascii("\" ignoreautonests")));
404 // FIXME: Bibitem mess!
405 if (cur.prevInset() && cur.prevInset()->lyxCode() == BIBITEM_CODE)
406 lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_BACKWARD));
407 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
408 while (cur.paragraph().params().depth() > depth)
409 lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
413 static void outline(OutlineOp mode, Cursor & cur, Text * text)
415 Buffer & buf = *cur.buffer();
416 pit_type & pit = cur.pit();
417 ParagraphList & pars = buf.text().paragraphs();
418 ParagraphList::iterator const bgn = pars.begin();
419 // The first paragraph of the area to be copied:
420 ParagraphList::iterator start = pars.iterator_at(pit);
421 // The final paragraph of area to be copied:
422 ParagraphList::iterator finish = start;
423 ParagraphList::iterator const end = pars.end();
424 depth_type const current_depth = cur.paragraph().params().depth();
426 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
429 // Move out (down) from this section header
433 // Seek the one (on same level) below
434 for (; finish != end; ++finish) {
435 toclevel = buf.text().getTocLevel(distance(bgn, finish));
436 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
442 if (start == pars.begin())
445 ParagraphList::iterator dest = start;
446 // Move out (up) from this header
449 // Search previous same-level header above
452 toclevel = buf.text().getTocLevel(distance(bgn, dest));
454 && (toclevel == Layout::NOT_IN_TOC
455 || toclevel > thistoclevel));
456 // Not found; do nothing
457 if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
459 pit_type newpit = distance(bgn, dest);
460 pit_type const len = distance(start, finish);
461 pit_type const deletepit = pit + len;
462 buf.undo().recordUndo(cur, newpit, deletepit - 1);
463 // If we move an environment upwards, make sure it is
464 // separated from its new neighbour below:
465 // If an environment of the same layout follows, and the moved
466 // paragraph sequence does not end with a separator, insert one.
467 ParagraphList::iterator lastmoved = finish;
469 if (start->layout().isEnvironment()
470 && dest->layout() == start->layout()
471 && !lastmoved->isEnvSeparator(lastmoved->beginOfBody())) {
472 cur.pit() = distance(bgn, lastmoved);
473 cur.pos() = cur.lastpos();
474 insertSeparator(cur, current_depth);
477 // Likewise, if we moved an environment upwards, make sure it
478 // is separated from its new neighbour above.
479 // The paragraph before the target of movement
481 ParagraphList::iterator before = dest;
483 // Get the parent paragraph (outer in nested context)
484 pit_type const parent =
485 before->params().depth() > current_depth
486 ? text->depthHook(distance(bgn, before), current_depth)
487 : distance(bgn, before);
488 // If a environment with same layout preceeds the moved one in the new
489 // position, and there is no separator yet, insert one.
490 if (start->layout().isEnvironment()
491 && pars[parent].layout() == start->layout()
492 && !before->isEnvSeparator(before->beginOfBody())) {
493 cur.pit() = distance(bgn, before);
494 cur.pos() = cur.lastpos();
495 insertSeparator(cur, current_depth);
499 newpit = distance(bgn, dest);
500 pars.splice(dest, start, finish);
508 // Go one down from *this* header:
509 ParagraphList::iterator dest = next(finish, 1);
510 // Go further down to find header to insert in front of:
511 for (; dest != end; ++dest) {
512 toclevel = buf.text().getTocLevel(distance(bgn, dest));
513 if (toclevel != Layout::NOT_IN_TOC
514 && toclevel <= thistoclevel)
517 // One such was found, so go on...
518 // If we move an environment downwards, make sure it is
519 // separated from its new neighbour above.
520 pit_type newpit = distance(bgn, dest);
521 buf.undo().recordUndo(cur, pit, newpit - 1);
522 // The paragraph before the target of movement
523 ParagraphList::iterator before = dest;
525 // Get the parent paragraph (outer in nested context)
526 pit_type const parent =
527 before->params().depth() > current_depth
528 ? text->depthHook(distance(bgn, before), current_depth)
529 : distance(bgn, before);
530 // If a environment with same layout preceeds the moved one in the new
531 // position, and there is no separator yet, insert one.
532 if (start->layout().isEnvironment()
533 && pars[parent].layout() == start->layout()
534 && !before->isEnvSeparator(before->beginOfBody())) {
535 cur.pit() = distance(bgn, before);
536 cur.pos() = cur.lastpos();
537 insertSeparator(cur, current_depth);
540 // Likewise, make sure moved environments are separated
541 // from their new neighbour below:
542 // If an environment of the same layout follows, and the moved
543 // paragraph sequence does not end with a separator, insert one.
544 ParagraphList::iterator lastmoved = finish;
547 && start->layout().isEnvironment()
548 && dest->layout() == start->layout()
549 && !lastmoved->isEnvSeparator(lastmoved->beginOfBody())) {
550 cur.pit() = distance(bgn, lastmoved);
551 cur.pos() = cur.lastpos();
552 insertSeparator(cur, current_depth);
555 newpit = distance(bgn, dest);
556 pit_type const len = distance(start, finish);
557 pars.splice(dest, start, finish);
558 cur.pit() = newpit - len;
563 pit_type const len = distance(start, finish);
564 buf.undo().recordUndo(cur, pit, pit + len - 1);
565 for (; start != finish; ++start) {
566 toclevel = buf.text().getTocLevel(distance(bgn, start));
567 if (toclevel == Layout::NOT_IN_TOC)
570 DocumentClass const & tc = buf.params().documentClass();
571 int const newtoclevel =
572 (mode == OutlineIn ? toclevel + 1 : toclevel - 1);
573 LabelType const oldlabeltype = start->layout().labeltype;
575 for (auto const & lay : tc) {
576 if (lay.toclevel == newtoclevel &&
577 lay.labeltype == oldlabeltype) {
578 start->setLayout(lay);
589 void Text::number(Cursor & cur)
591 FontInfo font = ignore_font;
592 font.setNumber(FONT_TOGGLE);
593 toggleAndShow(cur, this, Font(font, ignore_language));
597 bool Text::isRTL(pit_type const pit) const
599 Buffer const & buffer = owner_->buffer();
600 return pars_[pit].isRTL(buffer.params());
606 Language const * getLanguage(Cursor const & cur, string const & lang)
608 return lang.empty() ? cur.getFont().language() : languages.getLanguage(lang);
612 docstring resolveLayout(docstring layout, DocIterator const & dit)
614 Paragraph const & par = dit.paragraph();
615 DocumentClass const & tclass = dit.buffer()->params().documentClass();
618 layout = tclass.defaultLayoutName();
620 if (dit.inset().forcePlainLayout(dit.idx()))
621 // in this case only the empty layout is allowed
622 layout = tclass.plainLayoutName();
623 else if (par.usePlainLayout()) {
624 // in this case, default layout maps to empty layout
625 if (layout == tclass.defaultLayoutName())
626 layout = tclass.plainLayoutName();
628 // otherwise, the empty layout maps to the default
629 if (layout == tclass.plainLayoutName())
630 layout = tclass.defaultLayoutName();
633 // If the entry is obsolete, use the new one instead.
634 if (tclass.hasLayout(layout)) {
635 docstring const & obs = tclass[layout].obsoleted_by();
639 if (!tclass.hasLayout(layout))
645 bool isAlreadyLayout(docstring const & layout, CursorData const & cur)
647 ParagraphList const & pars = cur.text()->paragraphs();
649 pit_type pit = cur.selBegin().pit();
650 pit_type const epit = cur.selEnd().pit() + 1;
651 for ( ; pit != epit; ++pit)
652 if (pars[pit].layout().name() != layout)
662 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
664 LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
666 // Dispatch if the cursor is inside the text. It is not the
667 // case for context menus (bug 5797).
668 if (cur.text() != this) {
673 BufferView * bv = &cur.bv();
674 TextMetrics * tm = &bv->textMetrics(this);
675 if (!tm->contains(cur.pit())) {
676 lyx::dispatch(FuncRequest(LFUN_SCREEN_SHOW_CURSOR));
677 tm = &bv->textMetrics(this);
680 // FIXME: We use the update flag to indicates wether a singlePar or a
681 // full screen update is needed. We reset it here but shall we restore it
683 cur.noScreenUpdate();
685 LBUFERR(this == cur.text());
687 // NOTE: This should NOT be a reference. See commit 94a5481a.
688 CursorSlice const oldTopSlice = cur.top();
689 bool const oldBoundary = cur.boundary();
690 bool const oldSelection = cur.selection();
691 // Signals that, even if needsUpdate == false, an update of the
692 // cursor paragraph is required
693 bool singleParUpdate = lyxaction.funcHasFlag(cmd.action(),
694 LyXAction::SingleParUpdate);
695 // Signals that a full-screen update is required
696 bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action(),
697 LyXAction::NoUpdate) || singleParUpdate);
698 bool const last_misspelled = lyxrc.spellcheck_continuously
699 && cur.paragraph().isMisspelled(cur.pos(), true);
701 FuncCode const act = cmd.action();
704 case LFUN_PARAGRAPH_MOVE_DOWN: {
705 pit_type const pit = cur.pit();
706 cur.recordUndo(pit, pit + 1);
707 pars_.swap(pit, pit + 1);
709 cur.forceBufferUpdate();
714 case LFUN_PARAGRAPH_MOVE_UP: {
715 pit_type const pit = cur.pit();
716 cur.recordUndo(pit - 1, pit);
718 pars_.swap(pit, pit - 1);
721 cur.forceBufferUpdate();
725 case LFUN_APPENDIX: {
726 Paragraph & par = cur.paragraph();
727 bool start = !par.params().startOfAppendix();
729 // FIXME: The code below only makes sense at top level.
730 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
731 // ensure that we have only one start_of_appendix in this document
732 // FIXME: this don't work for multipart document!
733 for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
734 if (pars_[tmp].params().startOfAppendix()) {
735 cur.recordUndo(tmp, tmp);
736 pars_[tmp].params().startOfAppendix(false);
742 par.params().startOfAppendix(start);
744 // we can set the refreshing parameters now
745 cur.forceBufferUpdate();
749 case LFUN_WORD_DELETE_FORWARD:
751 cutSelection(cur, false);
753 deleteWordForward(cur, cmd.getArg(0) == "force");
754 finishChange(cur, false);
757 case LFUN_WORD_DELETE_BACKWARD:
759 cutSelection(cur, false);
761 deleteWordBackward(cur, cmd.getArg(0) == "force");
762 finishChange(cur, false);
765 case LFUN_LINE_DELETE_FORWARD:
767 cutSelection(cur, false);
769 tm->deleteLineForward(cur);
770 finishChange(cur, false);
773 case LFUN_BUFFER_BEGIN:
774 case LFUN_BUFFER_BEGIN_SELECT:
775 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_BEGIN_SELECT);
776 if (cur.depth() == 1)
777 needsUpdate |= cursorTop(cur);
780 cur.screenUpdateFlags(Update::FitCursor);
783 case LFUN_BUFFER_END:
784 case LFUN_BUFFER_END_SELECT:
785 needsUpdate |= cur.selHandle(act == LFUN_BUFFER_END_SELECT);
786 if (cur.depth() == 1)
787 needsUpdate |= cursorBottom(cur);
790 cur.screenUpdateFlags(Update::FitCursor);
793 case LFUN_INSET_BEGIN:
794 case LFUN_INSET_BEGIN_SELECT:
795 needsUpdate |= cur.selHandle(act == LFUN_INSET_BEGIN_SELECT);
796 if (cur.depth() == 1 || !cur.top().at_begin())
797 needsUpdate |= cursorTop(cur);
800 cur.screenUpdateFlags(Update::FitCursor);
804 case LFUN_INSET_END_SELECT:
805 needsUpdate |= cur.selHandle(act == LFUN_INSET_END_SELECT);
806 if (cur.depth() == 1 || !cur.top().at_end())
807 needsUpdate |= cursorBottom(cur);
810 cur.screenUpdateFlags(Update::FitCursor);
813 case LFUN_CHAR_FORWARD:
814 case LFUN_CHAR_FORWARD_SELECT: {
815 //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
816 needsUpdate |= cur.selHandle(act == LFUN_CHAR_FORWARD_SELECT);
817 bool const cur_moved = cursorForward(cur);
818 needsUpdate |= cur_moved;
820 if (!cur_moved && cur.depth() > 1
821 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
823 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
825 // we will be moving out the inset, so we should execute
826 // the depm-mechanism.
827 // The cursor hasn't changed yet. To give the DEPM the
828 // possibility of doing something we must provide it with
829 // two different cursors.
831 dummy.pos() = dummy.pit() = 0;
832 if (cur.bv().checkDepm(dummy, cur))
833 cur.forceBufferUpdate();
838 case LFUN_CHAR_BACKWARD:
839 case LFUN_CHAR_BACKWARD_SELECT: {
840 //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
841 needsUpdate |= cur.selHandle(act == LFUN_CHAR_BACKWARD_SELECT);
842 bool const cur_moved = cursorBackward(cur);
843 needsUpdate |= cur_moved;
845 if (!cur_moved && cur.depth() > 1
846 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
848 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
850 // we will be moving out the inset, so we should execute
851 // the depm-mechanism.
852 // The cursor hasn't changed yet. To give the DEPM the
853 // possibility of doing something we must provide it with
854 // two different cursors.
856 dummy.pos() = cur.lastpos();
857 dummy.pit() = cur.lastpit();
858 if (cur.bv().checkDepm(dummy, cur))
859 cur.forceBufferUpdate();
865 case LFUN_CHAR_LEFT_SELECT:
866 if (lyxrc.visual_cursor) {
867 needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
868 bool const cur_moved = cursorVisLeft(cur);
869 needsUpdate |= cur_moved;
870 if (!cur_moved && cur.depth() > 1
871 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
873 cmd = FuncRequest(LFUN_FINISHED_LEFT);
876 if (cur.reverseDirectionNeeded()) {
877 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
878 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
880 cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
881 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
888 case LFUN_CHAR_RIGHT:
889 case LFUN_CHAR_RIGHT_SELECT:
890 if (lyxrc.visual_cursor) {
891 needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
892 bool const cur_moved = cursorVisRight(cur);
893 needsUpdate |= cur_moved;
894 if (!cur_moved && cur.depth() > 1
895 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
897 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
900 if (cur.reverseDirectionNeeded()) {
901 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
902 LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
904 cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
905 LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
914 case LFUN_DOWN_SELECT:
917 // stop/start the selection
918 bool const select = cmd.action() == LFUN_DOWN_SELECT
919 || cmd.action() == LFUN_UP_SELECT;
920 // move cursor up/down
921 bool const up = cmd.action() == LFUN_UP_SELECT || cmd.action() == LFUN_UP;
923 if (!cur.atFirstOrLastRow(up)) {
924 needsUpdate |= cur.selHandle(select);
925 cur.upDownInText(up, needsUpdate);
926 needsUpdate |= cur.beforeDispatchCursor().inMathed();
928 pos_type newpos = up ? 0 : cur.lastpos();
929 if (lyxrc.mac_like_cursor_movement && cur.pos() != newpos) {
930 needsUpdate |= cur.selHandle(select);
931 // we do not reset the targetx of the cursor
933 needsUpdate |= bv->checkDepm(cur, bv->cursor());
934 cur.updateTextTargetOffset();
936 cur.forceBufferUpdate();
939 needsUpdate |= cur.selHandle(select);
940 bool const can_move = cur.upDownInText(up, needsUpdate);
941 // if the cursor can be moved up or down at an upper level,
942 // delegate the dispatch to next level. Otherwise, we are
945 cmd = FuncRequest(up ? LFUN_FINISHED_UP : LFUN_FINISHED_DOWN);
953 case LFUN_FINISHED_UP:
954 case LFUN_FINISHED_DOWN: {
955 // move cursor up/down
956 bool const up = cmd.action() == LFUN_FINISHED_UP;
958 if (!cur.atFirstOrLastRow(up)) {
959 cur.upDownInText(up, needsUpdate);
960 needsUpdate |= cur.beforeDispatchCursor().inMathed();
962 bool const can_move = cur.upDownInText(up, needsUpdate);
963 // if the cursor can be moved up or down and we are not
964 // moving cusor at top level, wait for the next dispatch.
965 // Otherwise, we are done.
973 case LFUN_PARAGRAPH_SELECT:
975 needsUpdate |= setCursor(cur, cur.pit(), 0);
976 needsUpdate |= cur.selHandle(true);
977 if (cur.pos() < cur.lastpos())
978 needsUpdate |= setCursor(cur, cur.pit(), cur.lastpos());
981 case LFUN_PARAGRAPH_UP:
982 case LFUN_PARAGRAPH_UP_SELECT:
983 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_UP_SELECT);
984 needsUpdate |= cursorUpParagraph(cur);
987 case LFUN_PARAGRAPH_DOWN:
988 case LFUN_PARAGRAPH_DOWN_SELECT:
989 needsUpdate |= cur.selHandle(cmd.action() == LFUN_PARAGRAPH_DOWN_SELECT);
990 needsUpdate |= cursorDownParagraph(cur);
993 case LFUN_LINE_BEGIN:
994 case LFUN_LINE_BEGIN_SELECT:
995 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_BEGIN_SELECT);
996 needsUpdate |= tm->cursorHome(cur);
1000 case LFUN_LINE_END_SELECT:
1001 needsUpdate |= cur.selHandle(cmd.action() == LFUN_LINE_END_SELECT);
1002 needsUpdate |= tm->cursorEnd(cur);
1005 case LFUN_SECTION_SELECT: {
1006 Buffer const & buf = *cur.buffer();
1007 pit_type const pit = cur.pit();
1008 ParagraphList & pars = buf.text().paragraphs();
1009 ParagraphList::iterator bgn = pars.begin();
1010 // The first paragraph of the area to be selected:
1011 ParagraphList::iterator start = pars.iterator_at(pit);
1012 // The final paragraph of area to be selected:
1013 ParagraphList::iterator finish = start;
1014 ParagraphList::iterator end = pars.end();
1016 int const thistoclevel = buf.text().getTocLevel(distance(bgn, start));
1017 if (thistoclevel == Layout::NOT_IN_TOC)
1021 Cursor const old_cur = cur;
1022 needsUpdate |= cur.selHandle(true);
1024 // Move out (down) from this section header
1028 // Seek the one (on same level) below
1029 for (; finish != end; ++finish, ++cur.pit()) {
1030 int const toclevel = buf.text().getTocLevel(distance(bgn, finish));
1031 if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
1034 cur.pos() = cur.lastpos();
1035 cur.boundary(false);
1036 cur.setCurrentFont();
1038 needsUpdate |= cur != old_cur;
1042 case LFUN_WORD_RIGHT:
1043 case LFUN_WORD_RIGHT_SELECT:
1044 if (lyxrc.visual_cursor) {
1045 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
1046 bool const cur_moved = cursorVisRightOneWord(cur);
1047 needsUpdate |= cur_moved;
1048 if (!cur_moved && cur.depth() > 1
1049 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1051 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1054 if (cur.reverseDirectionNeeded()) {
1055 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
1056 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
1058 cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
1059 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
1066 case LFUN_WORD_FORWARD:
1067 case LFUN_WORD_FORWARD_SELECT: {
1068 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_FORWARD_SELECT);
1069 bool const cur_moved = cursorForwardOneWord(cur);
1070 needsUpdate |= cur_moved;
1072 if (!cur_moved && cur.depth() > 1
1073 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1075 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1077 // we will be moving out the inset, so we should execute
1078 // the depm-mechanism.
1079 // The cursor hasn't changed yet. To give the DEPM the
1080 // possibility of doing something we must provide it with
1081 // two different cursors.
1083 dummy.pos() = dummy.pit() = 0;
1084 if (cur.bv().checkDepm(dummy, cur))
1085 cur.forceBufferUpdate();
1090 case LFUN_WORD_LEFT:
1091 case LFUN_WORD_LEFT_SELECT:
1092 if (lyxrc.visual_cursor) {
1093 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
1094 bool const cur_moved = cursorVisLeftOneWord(cur);
1095 needsUpdate |= cur_moved;
1096 if (!cur_moved && cur.depth() > 1
1097 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1099 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1102 if (cur.reverseDirectionNeeded()) {
1103 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
1104 LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
1106 cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
1107 LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
1114 case LFUN_WORD_BACKWARD:
1115 case LFUN_WORD_BACKWARD_SELECT: {
1116 needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_BACKWARD_SELECT);
1117 bool const cur_moved = cursorBackwardOneWord(cur);
1118 needsUpdate |= cur_moved;
1120 if (!cur_moved && cur.depth() > 1
1121 && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
1123 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1125 // we will be moving out the inset, so we should execute
1126 // the depm-mechanism.
1127 // The cursor hasn't changed yet. To give the DEPM the
1128 // possibility of doing something we must provide it with
1129 // two different cursors.
1131 dummy.pos() = cur.lastpos();
1132 dummy.pit() = cur.lastpit();
1133 if (cur.bv().checkDepm(dummy, cur))
1134 cur.forceBufferUpdate();
1139 case LFUN_WORD_SELECT: {
1140 selectWord(cur, WHOLE_WORD);
1141 finishChange(cur, true);
1145 case LFUN_NEWLINE_INSERT: {
1146 InsetNewlineParams inp;
1147 docstring const & arg = cmd.argument();
1148 if (arg == "linebreak")
1149 inp.kind = InsetNewlineParams::LINEBREAK;
1151 inp.kind = InsetNewlineParams::NEWLINE;
1152 cap::replaceSelection(cur);
1154 cur.insert(new InsetNewline(inp));
1156 moveCursor(cur, false);
1160 case LFUN_TAB_INSERT: {
1161 bool const multi_par_selection = cur.selection() &&
1162 cur.selBegin().pit() != cur.selEnd().pit();
1163 if (multi_par_selection) {
1164 // If there is a multi-paragraph selection, a tab is inserted
1165 // at the beginning of each paragraph.
1166 cur.recordUndoSelection();
1167 pit_type const pit_end = cur.selEnd().pit();
1168 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
1169 pars_[pit].insertChar(0, '\t',
1170 bv->buffer().params().track_changes);
1171 // Update the selection pos to make sure the selection does not
1172 // change as the inserted tab will increase the logical pos.
1173 if (cur.realAnchor().pit() == pit)
1174 cur.realAnchor().forwardPos();
1175 if (cur.pit() == pit)
1180 // Maybe we shouldn't allow tabs within a line, because they
1181 // are not (yet) aligned as one might do expect.
1182 FuncRequest ncmd(LFUN_SELF_INSERT, from_ascii("\t"));
1183 dispatch(cur, ncmd);
1188 case LFUN_TAB_DELETE: {
1189 bool const tc = bv->buffer().params().track_changes;
1190 if (cur.selection()) {
1191 // If there is a selection, a tab (if present) is removed from
1192 // the beginning of each paragraph.
1193 cur.recordUndoSelection();
1194 pit_type const pit_end = cur.selEnd().pit();
1195 for (pit_type pit = cur.selBegin().pit(); pit <= pit_end; pit++) {
1196 Paragraph & par = paragraphs()[pit];
1199 char_type const c = par.getChar(0);
1200 if (c == '\t' || c == ' ') {
1201 // remove either 1 tab or 4 spaces.
1202 int const n = (c == ' ' ? 4 : 1);
1203 for (int i = 0; i < n
1204 && !par.empty() && par.getChar(0) == c; ++i) {
1205 if (cur.pit() == pit)
1207 if (cur.realAnchor().pit() == pit
1208 && cur.realAnchor().pos() > 0 )
1209 cur.realAnchor().backwardPos();
1210 par.eraseChar(0, tc);
1216 // If there is no selection, try to remove a tab or some spaces
1217 // before the position of the cursor.
1218 Paragraph & par = paragraphs()[cur.pit()];
1219 pos_type const pos = cur.pos();
1224 char_type const c = par.getChar(pos - 1);
1228 par.eraseChar(cur.pos(), tc);
1230 for (int n_spaces = 0;
1232 && par.getChar(cur.pos() - 1) == ' '
1236 par.eraseChar(cur.pos(), tc);
1243 case LFUN_CHAR_DELETE_FORWARD:
1244 if (!cur.selection()) {
1245 if (cur.pos() == cur.paragraph().size())
1246 // Par boundary, force full-screen update
1247 singleParUpdate = false;
1248 else if (cmd.getArg(0) != "force" && cur.confirmDeletion()) {
1250 cur.selection(true);
1255 needsUpdate |= erase(cur);
1258 cutSelection(cur, false);
1259 cur.setCurrentFont();
1260 singleParUpdate = false;
1262 moveCursor(cur, false);
1265 case LFUN_CHAR_DELETE_BACKWARD:
1266 if (!cur.selection()) {
1267 if (bv->getIntl().getTransManager().backspace()) {
1268 bool par_boundary = cur.pos() == 0;
1269 bool first_par = cur.pit() == 0;
1270 // Par boundary, full-screen update
1272 singleParUpdate = false;
1273 else if (cmd.getArg(0) != "force" && cur.confirmDeletion(true)) {
1275 cur.selection(true);
1280 needsUpdate |= backspace(cur);
1282 if (par_boundary && !first_par && cur.pos() > 0
1283 && cur.paragraph().isEnvSeparator(cur.pos() - 1)) {
1284 needsUpdate |= backspace(cur);
1289 DocIterator const dit = cur.selectionBegin();
1290 cutSelection(cur, false);
1291 if (cur.buffer()->params().track_changes)
1292 // since we're doing backwards deletion,
1293 // and the selection is not really cut,
1294 // move cursor before selection (#11630)
1296 cur.setCurrentFont();
1297 singleParUpdate = false;
1301 case LFUN_PARAGRAPH_BREAK: {
1302 cap::replaceSelection(cur);
1303 pit_type pit = cur.pit();
1304 Paragraph const & par = pars_[pit];
1305 bool lastpar = (pit == pit_type(pars_.size() - 1));
1306 Paragraph const & nextpar = lastpar ? par : pars_[pit + 1];
1307 pit_type prev = pit > 0 ? depthHook(pit, par.getDepth()) : pit;
1308 if (prev < pit && cur.pos() == par.beginOfBody()
1309 && par.empty() && !par.isEnvSeparator(cur.pos())
1310 && !par.layout().keepempty
1311 && !par.layout().isCommand()
1312 && pars_[prev].layout() != par.layout()
1313 && pars_[prev].layout().isEnvironment()
1314 && !nextpar.isEnvSeparator(nextpar.beginOfBody())) {
1315 if (par.layout().isEnvironment()
1316 && pars_[prev].getDepth() == par.getDepth()) {
1317 docstring const layout = par.layout().name();
1318 DocumentClass const & tc = bv->buffer().params().documentClass();
1319 lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
1320 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1321 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1322 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1324 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1325 breakParagraph(cur);
1327 Font const f(inherit_font, cur.current_font.language());
1328 pars_[cur.pit() - 1].resetFonts(f);
1330 if (par.isEnvSeparator(cur.pos()) && cmd.getArg(1) != "ignoresep")
1332 breakParagraph(cur, cmd.getArg(0) == "inverse");
1335 // If we have a list and autoinsert item insets,
1337 Layout::LaTeXArgMap args = par.layout().args();
1338 for (auto const & thearg : args) {
1339 Layout::latexarg arg = thearg.second;
1340 if (arg.autoinsert && prefixIs(thearg.first, "item:")) {
1341 FuncRequest cmd2(LFUN_ARGUMENT_INSERT, thearg.first);
1342 lyx::dispatch(cmd2);
1348 case LFUN_INSET_INSERT: {
1351 // We have to avoid triggering InstantPreview loading
1352 // before inserting into the document. See bug #5626.
1353 bool loaded = bv->buffer().isFullyLoaded();
1354 bv->buffer().setFullyLoaded(false);
1355 Inset * inset = createInset(&bv->buffer(), cmd);
1356 bv->buffer().setFullyLoaded(loaded);
1359 // FIXME (Abdel 01/02/2006):
1360 // What follows would be a partial fix for bug 2154:
1361 // http://www.lyx.org/trac/ticket/2154
1362 // This automatically put the label inset _after_ a
1363 // numbered section. It should be possible to extend the mechanism
1364 // to any kind of LateX environement.
1365 // The correct way to fix that bug would be at LateX generation.
1366 // I'll let the code here for reference as it could be used for some
1367 // other feature like "automatic labelling".
1369 Paragraph & par = pars_[cur.pit()];
1370 if (inset->lyxCode() == LABEL_CODE
1371 && !par.layout().counter.empty()) {
1372 // Go to the end of the paragraph
1373 // Warning: Because of Change-Tracking, the last
1374 // position is 'size()' and not 'size()-1':
1375 cur.pos() = par.size();
1376 // Insert a new paragraph
1377 FuncRequest fr(LFUN_PARAGRAPH_BREAK);
1381 if (cur.selection())
1382 cutSelection(cur, false);
1384 cur.forceBufferUpdate();
1385 if (inset->editable() && inset->asInsetText())
1386 inset->edit(cur, true);
1390 // trigger InstantPreview now
1391 if (inset->lyxCode() == EXTERNAL_CODE) {
1392 InsetExternal & ins =
1393 static_cast<InsetExternal &>(*inset);
1394 ins.updatePreview();
1401 case LFUN_INSET_DISSOLVE: {
1402 if (dissolveInset(cur)) {
1404 cur.forceBufferUpdate();
1409 case LFUN_INSET_SPLIT: {
1410 if (splitInset(cur)) {
1412 cur.forceBufferUpdate();
1417 case LFUN_GRAPHICS_SET_GROUP: {
1418 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
1424 string id = to_utf8(cmd.argument());
1425 string grp = graphics::getGroupParams(bv->buffer(), id);
1426 InsetGraphicsParams tmp, inspar = ins->getParams();
1429 inspar.groupId = to_utf8(cmd.argument());
1431 InsetGraphics::string2params(grp, bv->buffer(), tmp);
1432 tmp.filename = inspar.filename;
1436 ins->setParams(inspar);
1440 case LFUN_SPACE_INSERT:
1441 if (cur.paragraph().layout().free_spacing)
1442 insertChar(cur, ' ');
1444 doInsertInset(cur, this, cmd, false, false);
1447 moveCursor(cur, false);
1450 case LFUN_SPECIALCHAR_INSERT: {
1451 string const name = to_utf8(cmd.argument());
1452 if (name == "hyphenation")
1453 specialChar(cur, InsetSpecialChar::HYPHENATION);
1454 else if (name == "allowbreak")
1455 specialChar(cur, InsetSpecialChar::ALLOWBREAK);
1456 else if (name == "ligature-break")
1457 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
1458 else if (name == "slash")
1459 specialChar(cur, InsetSpecialChar::SLASH);
1460 else if (name == "nobreakdash")
1461 specialChar(cur, InsetSpecialChar::NOBREAKDASH);
1462 else if (name == "dots")
1463 specialChar(cur, InsetSpecialChar::LDOTS);
1464 else if (name == "end-of-sentence")
1465 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
1466 else if (name == "menu-separator")
1467 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
1468 else if (name == "lyx")
1469 specialChar(cur, InsetSpecialChar::PHRASE_LYX);
1470 else if (name == "tex")
1471 specialChar(cur, InsetSpecialChar::PHRASE_TEX);
1472 else if (name == "latex")
1473 specialChar(cur, InsetSpecialChar::PHRASE_LATEX);
1474 else if (name == "latex2e")
1475 specialChar(cur, InsetSpecialChar::PHRASE_LATEX2E);
1476 else if (name.empty())
1477 lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
1479 lyxerr << "Wrong argument for LyX function 'specialchar-insert'." << endl;
1483 case LFUN_IPAMACRO_INSERT: {
1484 string const arg = cmd.getArg(0);
1485 if (arg == "deco") {
1486 // Open the inset, and move the current selection
1488 doInsertInset(cur, this, cmd, true, true);
1490 // Some insets are numbered, others are shown in the outline pane so
1491 // let's update the labels and the toc backend.
1492 cur.forceBufferUpdate();
1495 if (arg == "tone-falling")
1496 ipaChar(cur, InsetIPAChar::TONE_FALLING);
1497 else if (arg == "tone-rising")
1498 ipaChar(cur, InsetIPAChar::TONE_RISING);
1499 else if (arg == "tone-high-rising")
1500 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING);
1501 else if (arg == "tone-low-rising")
1502 ipaChar(cur, InsetIPAChar::TONE_LOW_RISING);
1503 else if (arg == "tone-high-rising-falling")
1504 ipaChar(cur, InsetIPAChar::TONE_HIGH_RISING_FALLING);
1505 else if (arg.empty())
1506 lyxerr << "LyX function 'ipamacro-insert' needs an argument." << endl;
1508 lyxerr << "Wrong argument for LyX function 'ipamacro-insert'." << endl;
1512 case LFUN_WORD_UPCASE:
1513 changeCase(cur, text_uppercase, cmd.getArg(0) == "partial");
1516 case LFUN_WORD_LOWCASE:
1517 changeCase(cur, text_lowercase, cmd.getArg(0) == "partial");
1520 case LFUN_WORD_CAPITALIZE:
1521 changeCase(cur, text_capitalization, cmd.getArg(0) == "partial");
1524 case LFUN_CHARS_TRANSPOSE:
1525 charsTranspose(cur);
1529 cur.message(_("Paste"));
1530 LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), break);
1531 cap::replaceSelection(cur);
1533 // without argument?
1534 string const arg = to_utf8(cmd.argument());
1536 bool tryGraphics = true;
1537 if (theClipboard().isInternal())
1538 pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
1539 else if (theClipboard().hasTextContents()) {
1540 if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1541 !cur.paragraph().parbreakIsNewline(),
1542 Clipboard::AnyTextType))
1543 tryGraphics = false;
1545 if (tryGraphics && theClipboard().hasGraphicsContents())
1546 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
1547 } else if (isStrUnsignedInt(arg)) {
1548 // we have a numerical argument
1549 pasteFromStack(cur, bv->buffer().errorList("Paste"),
1550 convert<unsigned int>(arg));
1551 } else if (arg == "html" || arg == "latex") {
1552 Clipboard::TextType type = (arg == "html") ?
1553 Clipboard::HtmlTextType : Clipboard::LaTeXTextType;
1554 pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type);
1556 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
1558 type = Clipboard::PdfGraphicsType;
1559 else if (arg == "png")
1560 type = Clipboard::PngGraphicsType;
1561 else if (arg == "jpeg")
1562 type = Clipboard::JpegGraphicsType;
1563 else if (arg == "linkback")
1564 type = Clipboard::LinkBackGraphicsType;
1565 else if (arg == "emf")
1566 type = Clipboard::EmfGraphicsType;
1567 else if (arg == "wmf")
1568 type = Clipboard::WmfGraphicsType;
1570 // we also check in getStatus()
1571 LYXERR0("Unrecognized graphics type: " << arg);
1573 pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
1576 bv->buffer().errors("Paste");
1577 bv->buffer().updatePreviews(); // bug 11619
1578 cur.clearSelection(); // bug 393
1584 cutSelection(cur, true);
1585 cur.message(_("Cut"));
1588 case LFUN_SERVER_GET_XY:
1589 cur.message(from_utf8(
1590 convert<string>(tm->cursorX(cur.top(), cur.boundary()))
1591 + ' ' + convert<string>(tm->cursorY(cur.top(), cur.boundary()))));
1594 case LFUN_SERVER_SET_XY: {
1597 istringstream is(to_utf8(cmd.argument()));
1600 lyxerr << "SETXY: Could not parse coordinates in '"
1601 << to_utf8(cmd.argument()) << endl;
1603 tm->setCursorFromCoordinates(cur, x, y);
1607 case LFUN_SERVER_GET_LAYOUT:
1608 cur.message(cur.paragraph().layout().name());
1612 case LFUN_LAYOUT_TOGGLE: {
1613 bool const ignoreautonests = cmd.getArg(1) == "ignoreautonests";
1614 docstring req_layout = ignoreautonests ? from_utf8(cmd.getArg(0)) : cmd.argument();
1615 LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(req_layout));
1617 docstring layout = resolveLayout(req_layout, cur);
1618 if (layout.empty()) {
1619 cur.errorMessage(from_utf8(N_("Layout ")) + req_layout +
1620 from_utf8(N_(" not known")));
1624 docstring const old_layout = cur.paragraph().layout().name();
1625 bool change_layout = !isAlreadyLayout(layout, cur);
1627 if (cmd.action() == LFUN_LAYOUT_TOGGLE && !change_layout) {
1628 change_layout = true;
1629 layout = resolveLayout(docstring(), cur);
1632 if (change_layout) {
1633 setLayout(cur, layout);
1634 if (cur.pit() > 0 && !ignoreautonests) {
1635 pit_type prev_pit = cur.pit() - 1;
1636 depth_type const cur_depth = pars_[cur.pit()].getDepth();
1637 // Scan for the previous par on same nesting level
1638 while (prev_pit > 0 && pars_[prev_pit].getDepth() > cur_depth)
1640 set<docstring> const & autonests =
1641 pars_[prev_pit].layout().autonests();
1642 set<docstring> const & autonested =
1643 pars_[cur.pit()].layout().isAutonestedBy();
1644 if (autonests.find(layout) != autonests.end()
1645 || autonested.find(old_layout) != autonested.end())
1646 lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
1650 DocumentClass const & tclass = bv->buffer().params().documentClass();
1651 bool inautoarg = false;
1652 for (auto const & la_pair : tclass[layout].args()) {
1653 Layout::latexarg const & arg = la_pair.second;
1654 if (arg.autoinsert) {
1655 // If we had already inserted an arg automatically,
1656 // leave this now in order to insert the next one.
1658 cur.leaveInset(cur.inset());
1661 FuncRequest const cmd2(LFUN_ARGUMENT_INSERT, la_pair.first);
1662 lyx::dispatch(cmd2);
1670 case LFUN_ENVIRONMENT_SPLIT: {
1671 bool const outer = cmd.argument() == "outer";
1672 bool const previous = cmd.argument() == "previous";
1673 bool const before = cmd.argument() == "before";
1674 bool const normal = cmd.argument().empty();
1675 Paragraph const & para = cur.paragraph();
1677 if (para.layout().isEnvironment())
1678 layout = para.layout().name();
1679 depth_type split_depth = cur.paragraph().params().depth();
1680 vector<depth_type> nextpars_depth;
1681 if (outer || previous) {
1682 // check if we have an environment in our scope
1683 pit_type pit = cur.pit();
1684 Paragraph cpar = pars_[pit];
1690 if (layout.empty() && previous
1691 && cpar.layout().isEnvironment()
1692 && cpar.params().depth() <= split_depth)
1693 layout = cpar.layout().name();
1694 if (cpar.params().depth() < split_depth
1695 && cpar.layout().isEnvironment()) {
1697 layout = cpar.layout().name();
1698 split_depth = cpar.params().depth();
1700 if (cpar.params().depth() == 0)
1704 if ((outer || normal) && cur.pit() < cur.lastpit()) {
1705 // save nesting of following paragraphs if they are deeper
1707 pit_type offset = 1;
1708 depth_type cur_depth = pars_[cur.pit()].params().depth();
1709 while (cur.pit() + offset <= cur.lastpit()) {
1710 Paragraph cpar = pars_[cur.pit() + offset];
1711 depth_type nextpar_depth = cpar.params().depth();
1712 if (cur_depth <= nextpar_depth && nextpar_depth > 0) {
1713 nextpars_depth.push_back(nextpar_depth);
1714 cur_depth = nextpar_depth;
1721 cur.top().setPitPos(cur.pit(), 0);
1722 if (before || cur.pos() > 0)
1723 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
1724 else if (previous && cur.nextInset() && cur.nextInset()->lyxCode() == SEPARATOR_CODE)
1725 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse ignoresep"));
1727 while (cur.paragraph().params().depth() > split_depth)
1728 lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
1730 DocumentClass const & tc = bv->buffer().params().documentClass();
1731 lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") + tc.plainLayout().name()
1732 + from_ascii("\" ignoreautonests")));
1733 // FIXME: Bibitem mess!
1734 if (cur.prevInset() && cur.prevInset()->lyxCode() == BIBITEM_CODE)
1735 lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_BACKWARD));
1736 lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
1739 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse ignoresep"));
1740 while (cur.paragraph().params().depth() < split_depth)
1741 lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
1744 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
1745 lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
1746 if ((outer || normal) && !nextpars_depth.empty()) {
1747 // restore nesting of following paragraphs
1748 DocIterator scur = cur;
1749 depth_type max_depth = cur.paragraph().params().depth() + 1;
1750 for (auto nextpar_depth : nextpars_depth) {
1752 while (cur.paragraph().params().depth() < min(nextpar_depth, max_depth)) {
1753 depth_type const olddepth = cur.paragraph().params().depth();
1754 lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
1755 if (olddepth == cur.paragraph().params().depth())
1756 // leave loop if no incrementation happens
1759 max_depth = cur.paragraph().params().depth() + 1;
1761 cur.setCursor(scur);
1767 case LFUN_CLIPBOARD_PASTE:
1768 cap::replaceSelection(cur);
1769 pasteClipboardText(cur, bv->buffer().errorList("Paste"),
1770 cmd.argument() == "paragraph");
1771 bv->buffer().errors("Paste");
1774 case LFUN_CLIPBOARD_PASTE_SIMPLE:
1775 cap::replaceSelection(cur);
1776 pasteSimpleText(cur, cmd.argument() == "paragraph");
1779 case LFUN_PRIMARY_SELECTION_PASTE:
1780 cap::replaceSelection(cur);
1781 pasteString(cur, theSelection().get(),
1782 cmd.argument() == "paragraph");
1785 case LFUN_SELECTION_PASTE:
1786 // Copy the selection buffer to the clipboard stack,
1787 // because we want it to appear in the "Edit->Paste
1789 cap::replaceSelection(cur);
1790 cap::copySelectionToStack();
1791 cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste"));
1792 bv->buffer().errors("Paste");
1795 case LFUN_QUOTE_INSERT: {
1796 cap::replaceSelection(cur);
1799 Paragraph const & par = cur.paragraph();
1800 pos_type pos = cur.pos();
1801 // Ignore deleted text before cursor
1802 while (pos > 0 && par.isDeleted(pos - 1))
1805 bool const inner = (cmd.getArg(0) == "single" || cmd.getArg(0) == "inner");
1807 // Guess quote side.
1808 // A space triggers an opening quote. This is passed if the preceding
1809 // char/inset is a space or at paragraph start.
1811 if (pos > 0 && !par.isSpace(pos - 1)) {
1812 if (cur.prevInset() && cur.prevInset()->lyxCode() == QUOTE_CODE) {
1813 // If an opening double quotation mark precedes, and this
1814 // is a single quote, make it opening as well
1816 static_cast<InsetQuotes &>(*cur.prevInset());
1817 string const type = ins.getType();
1818 if (!suffixIs(type, "ld") || !inner)
1819 c = par.getChar(pos - 1);
1821 else if (!cur.prevInset()
1822 || (cur.prevInset() && cur.prevInset()->isChar()))
1823 // If a char precedes, pass that and let InsetQuote decide
1824 c = par.getChar(pos - 1);
1827 if (par.getInset(pos - 1)
1828 && !par.getInset(pos - 1)->isPartOfTextSequence()) {
1829 // skip "invisible" insets
1833 c = par.getChar(pos - 1);
1838 QuoteLevel const quote_level = inner
1839 ? QuoteLevel::Secondary : QuoteLevel::Primary;
1840 cur.insert(new InsetQuotes(cur.buffer(), c, quote_level, cmd.getArg(1), cmd.getArg(2)));
1841 cur.buffer()->updateBuffer();
1846 case LFUN_MOUSE_TRIPLE:
1847 if (cmd.button() == mouse_button::button1) {
1849 setCursor(cur, cur.pit(), 0);
1852 if (cur.pos() < cur.lastpos())
1853 setCursor(cur, cur.pit(), cur.lastpos());
1859 case LFUN_MOUSE_DOUBLE:
1860 if (cmd.button() == mouse_button::button1) {
1861 selectWord(cur, WHOLE_WORD);
1866 // Single-click on work area
1867 case LFUN_MOUSE_PRESS: {
1868 // We are not marking a selection with the keyboard in any case.
1869 Cursor & bvcur = cur.bv().cursor();
1870 bvcur.setMark(false);
1871 switch (cmd.button()) {
1872 case mouse_button::button1:
1873 if (!bvcur.selection())
1875 bvcur.resetAnchor();
1876 if (!bv->mouseSetCursor(cur, cmd.modifier() == ShiftModifier))
1877 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1878 // FIXME: move this to mouseSetCursor?
1879 if (bvcur.wordSelection() && bvcur.inTexted())
1880 expandWordSel(bvcur);
1883 case mouse_button::button2:
1884 if (lyxrc.mouse_middlebutton_paste) {
1885 // Middle mouse pasting.
1886 bv->mouseSetCursor(cur);
1888 FuncRequest(LFUN_COMMAND_ALTERNATIVES,
1889 "selection-paste ; primary-selection-paste paragraph"));
1891 cur.noScreenUpdate();
1894 case mouse_button::button3: {
1895 // Don't do anything if we right-click a
1896 // selection, a context menu will popup.
1897 if (bvcur.selection() && cur >= bvcur.selectionBegin()
1898 && cur <= bvcur.selectionEnd()) {
1899 cur.noScreenUpdate();
1902 if (!bv->mouseSetCursor(cur, false))
1903 cur.screenUpdateFlags(Update::FitCursor);
1909 } // switch (cmd.button())
1912 case LFUN_MOUSE_MOTION: {
1913 // Mouse motion with right or middle mouse do nothing for now.
1914 if (cmd.button() != mouse_button::button1) {
1915 cur.noScreenUpdate();
1918 // ignore motions deeper nested than the real anchor
1919 Cursor & bvcur = cur.bv().cursor();
1920 if (!bvcur.realAnchor().hasPart(cur)) {
1924 CursorSlice old = bvcur.top();
1926 int const wh = bv->workHeight();
1927 int const y = max(0, min(wh - 1, cmd.y()));
1929 tm->setCursorFromCoordinates(cur, cmd.x(), y);
1930 cur.setTargetX(cmd.x());
1931 // Don't allow selecting a separator inset
1932 if (cur.pos() && cur.paragraph().isEnvSeparator(cur.pos() - 1))
1935 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1936 else if (cmd.y() < 0)
1937 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1938 // This is to allow jumping over large insets
1939 if (cur.top() == old) {
1941 lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
1942 else if (cmd.y() < 0)
1943 lyx::dispatch(FuncRequest(LFUN_UP_SELECT));
1945 // We continue with our existing selection or start a new one, so don't
1946 // reset the anchor.
1947 bvcur.setCursor(cur);
1948 if (bvcur.wordSelection() && bvcur.inTexted())
1949 expandWordSel(bvcur);
1950 bvcur.selection(true);
1951 bvcur.setCurrentFont();
1952 if (cur.top() == old) {
1953 // We didn't move one iota, so no need to update the screen.
1954 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1955 //cur.noScreenUpdate();
1961 case LFUN_MOUSE_RELEASE:
1962 switch (cmd.button()) {
1963 case mouse_button::button1:
1964 // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time.
1965 // If there is a new selection, update persistent selection;
1966 // otherwise, single click does not clear persistent selection
1968 if (cur.selection()) {
1969 // Finish selection. If double click,
1970 // cur is moved to the end of word by
1971 // selectWord but bvcur is current
1973 cur.bv().cursor().setSelection();
1974 // We might have removed an empty but drawn selection
1975 // (probably a margin)
1976 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
1978 cur.noScreenUpdate();
1979 // FIXME: We could try to handle drag and drop of selection here.
1982 case mouse_button::button2:
1983 // Middle mouse pasting is handled at mouse press time,
1984 // see LFUN_MOUSE_PRESS.
1985 cur.noScreenUpdate();
1988 case mouse_button::button3:
1989 // Cursor was set at LFUN_MOUSE_PRESS time.
1990 // FIXME: If there is a selection we could try to handle a special
1991 // drag & drop context menu.
1992 cur.noScreenUpdate();
1995 case mouse_button::none:
1996 case mouse_button::button4:
1997 case mouse_button::button5:
1999 } // switch (cmd.button())
2003 case LFUN_SELF_INSERT: {
2004 if (cmd.argument().empty())
2007 // Automatically delete the currently selected
2008 // text and replace it with what is being
2009 // typed in now. Depends on lyxrc settings
2010 // "auto_region_delete", which defaults to
2013 if (lyxrc.auto_region_delete && cur.selection()) {
2014 cutSelection(cur, false);
2015 cur.setCurrentFont();
2017 cur.clearSelection();
2019 for (char_type c : cmd.argument())
2020 bv->translateAndInsert(c, this, cur);
2023 moveCursor(cur, false);
2024 cur.markNewWordPosition();
2025 bv->bookmarkEditPosition();
2029 case LFUN_HREF_INSERT: {
2030 docstring content = cmd.argument();
2031 if (content.empty() && cur.selection())
2032 content = cur.selectionAsString(false);
2034 InsetCommandParams p(HYPERLINK_CODE);
2035 if (!content.empty()){
2036 // if it looks like a link, we'll put it as target,
2037 // otherwise as name (bug #8792).
2040 // regex_match(to_utf8(content), matches, link_re)
2041 // because smatch stores pointers to the substrings rather
2042 // than making copies of them. And those pointers become
2043 // invalid after regex_match returns, since it is then
2044 // being given a temporary object. (Thanks to Georg for
2045 // figuring that out.)
2046 regex const link_re("^([a-z]+):.*");
2048 string const c = to_utf8(lowercase(content));
2050 if (c.substr(0,7) == "mailto:") {
2051 p["target"] = content;
2052 p["type"] = from_ascii("mailto:");
2053 } else if (regex_match(c, matches, link_re)) {
2054 p["target"] = content;
2055 string protocol = matches.str(1);
2056 if (protocol == "file")
2057 p["type"] = from_ascii("file:");
2059 p["name"] = content;
2061 string const data = InsetCommand::params2string(p);
2063 // we need to have a target. if we already have one, then
2064 // that gets used at the default for the name, too, which
2065 // is probably what is wanted.
2066 if (p["target"].empty()) {
2067 bv->showDialog("href", data);
2069 FuncRequest fr(LFUN_INSET_INSERT, data);
2075 case LFUN_LABEL_INSERT: {
2076 InsetCommandParams p(LABEL_CODE);
2077 // Try to generate a valid label
2078 p["name"] = (cmd.argument().empty()) ?
2079 cur.getPossibleLabel() :
2081 string const data = InsetCommand::params2string(p);
2083 if (cmd.argument().empty()) {
2084 bv->showDialog("label", data);
2086 FuncRequest fr(LFUN_INSET_INSERT, data);
2092 case LFUN_INFO_INSERT: {
2093 if (cmd.argument().empty()) {
2094 bv->showDialog("info", cur.current_font.language()->lang());
2097 inset = createInset(cur.buffer(), cmd);
2101 insertInset(cur, inset);
2102 cur.forceBufferUpdate();
2107 case LFUN_CAPTION_INSERT:
2108 case LFUN_FOOTNOTE_INSERT:
2109 case LFUN_NOTE_INSERT:
2110 case LFUN_BOX_INSERT:
2111 case LFUN_BRANCH_INSERT:
2112 case LFUN_PHANTOM_INSERT:
2113 case LFUN_ERT_INSERT:
2114 case LFUN_INDEXMACRO_INSERT:
2115 case LFUN_LISTING_INSERT:
2116 case LFUN_MARGINALNOTE_INSERT:
2117 case LFUN_ARGUMENT_INSERT:
2118 case LFUN_INDEX_INSERT:
2119 case LFUN_PREVIEW_INSERT:
2120 case LFUN_SCRIPT_INSERT:
2121 case LFUN_IPA_INSERT: {
2122 // Indexes reset font formatting (#11961)
2123 bool const resetfont = cmd.action() == LFUN_INDEX_INSERT;
2124 // Open the inset, and move the current selection
2126 doInsertInset(cur, this, cmd, true, true, resetfont);
2128 cur.setCurrentFont();
2129 // Some insets are numbered, others are shown in the outline pane so
2130 // let's update the labels and the toc backend.
2131 cur.forceBufferUpdate();
2135 case LFUN_FLEX_INSERT: {
2136 // Open the inset, and move the current selection
2138 bool const sel = cur.selection();
2139 doInsertInset(cur, this, cmd, true, true);
2140 // Insert auto-insert arguments
2141 bool autoargs = false, inautoarg = false;
2142 Layout::LaTeXArgMap args = cur.inset().getLayout().args();
2143 for (auto const & argt : args) {
2144 Layout::latexarg arg = argt.second;
2145 if (!inautoarg && arg.insertonnewline && cur.pos() > 0) {
2146 FuncRequest cmd2(LFUN_PARAGRAPH_BREAK);
2147 lyx::dispatch(cmd2);
2149 if (arg.autoinsert) {
2150 // The cursor might have been invalidated by the replaceSelection.
2151 cur.buffer()->changed(true);
2152 // If we had already inserted an arg automatically,
2153 // leave this now in order to insert the next one.
2155 cur.leaveInset(cur.inset());
2156 cur.setCurrentFont();
2158 if (arg.insertonnewline && cur.pos() > 0) {
2159 FuncRequest cmd2(LFUN_PARAGRAPH_BREAK);
2160 lyx::dispatch(cmd2);
2163 FuncRequest cmd2(LFUN_ARGUMENT_INSERT, argt.first);
2164 lyx::dispatch(cmd2);
2171 cur.leaveInset(cur.inset());
2174 // Some insets are numbered, others are shown in the outline pane so
2175 // let's update the labels and the toc backend.
2176 cur.forceBufferUpdate();
2180 case LFUN_TABULAR_INSERT: {
2181 // if there were no arguments, just open the dialog
2182 if (cmd.argument().empty()) {
2183 bv->showDialog("tabularcreate");
2185 } else if (cur.buffer()->masterParams().tablestyle != "default"
2186 || bv->buffer().params().documentClass().tablestyle() != "default") {
2187 string tabstyle = cur.buffer()->masterParams().tablestyle;
2188 if (tabstyle == "default")
2189 tabstyle = bv->buffer().params().documentClass().tablestyle();
2190 if (!libFileSearch("tabletemplates", tabstyle + ".lyx").empty()) {
2191 FuncRequest fr(LFUN_TABULAR_STYLE_INSERT,
2192 tabstyle + " " + to_ascii(cmd.argument()));
2196 // Unknown style. Report and fall back to default.
2197 cur.errorMessage(from_utf8(N_("Table Style ")) + from_utf8(tabstyle) +
2198 from_utf8(N_(" not known")));
2200 if (doInsertInset(cur, this, cmd, false, true))
2205 case LFUN_TABULAR_STYLE_INSERT: {
2206 string const style = cmd.getArg(0);
2207 string const rows = cmd.getArg(1);
2208 string const cols = cmd.getArg(2);
2209 if (cols.empty() || !isStrInt(cols)
2210 || rows.empty() || !isStrInt(rows))
2212 int const r = convert<int>(rows);
2213 int const c = convert<int>(cols);
2220 FileName const tabstyle = libFileSearch("tabletemplates",
2221 style + suffix + ".lyx", "lyx");
2222 if (tabstyle.empty())
2224 UndoGroupHelper ugh(cur.buffer());
2226 FuncRequest cmd2(LFUN_FILE_INSERT, tabstyle.absFileName() + " ignorelang");
2227 lyx::dispatch(cmd2);
2231 // move one cell up to middle cell
2233 // add the missing rows
2234 int const addrows = r - 3;
2235 for (int i = 0 ; i < addrows ; ++i) {
2236 FuncRequest fr(LFUN_TABULAR_FEATURE, "append-row");
2240 // add the missing columns
2241 int const addcols = c - 1;
2242 for (int i = 0 ; i < addcols ; ++i) {
2243 FuncRequest fr(LFUN_TABULAR_FEATURE, "append-column");
2252 case LFUN_FLOAT_INSERT:
2253 case LFUN_FLOAT_WIDE_INSERT:
2254 case LFUN_WRAP_INSERT: {
2255 // will some content be moved into the inset?
2256 bool const content = cur.selection();
2257 // does the content consist of multiple paragraphs?
2258 bool const singlepar = (cur.selBegin().pit() == cur.selEnd().pit());
2260 doInsertInset(cur, this, cmd, true, true);
2263 // If some single-par content is moved into the inset,
2264 // doInsertInset puts the cursor outside the inset.
2265 // To insert the caption we put it back into the inset.
2266 // FIXME cleanup doInsertInset to avoid such dances!
2267 if (content && singlepar)
2270 ParagraphList & pars = cur.text()->paragraphs();
2272 DocumentClass const & tclass = bv->buffer().params().documentClass();
2274 // add a separate paragraph for the caption inset
2275 pars.push_back(Paragraph());
2276 pars.back().setInsetOwner(&cur.text()->inset());
2277 pars.back().setPlainOrDefaultLayout(tclass);
2278 int cap_pit = pars.size() - 1;
2280 // if an empty inset was created, we create an additional empty
2281 // paragraph at the bottom so that the user can choose where to put
2282 // the graphics (or table).
2284 pars.push_back(Paragraph());
2285 pars.back().setInsetOwner(&cur.text()->inset());
2286 pars.back().setPlainOrDefaultLayout(tclass);
2289 // reposition the cursor to the caption
2290 cur.pit() = cap_pit;
2292 // FIXME: This Text/Cursor dispatch handling is a mess!
2293 // We cannot use Cursor::dispatch here it needs access to up to
2295 FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
2296 doInsertInset(cur, cur.text(), cmd_caption, true, false);
2297 cur.forceBufferUpdate();
2298 cur.screenUpdateFlags(Update::Force);
2299 // FIXME: When leaving the Float (or Wrap) inset we should
2300 // delete any empty paragraph left above or below the
2305 case LFUN_NOMENCL_INSERT: {
2306 InsetCommandParams p(NOMENCL_CODE);
2307 if (cmd.argument().empty()) {
2309 bv->cursor().innerText()->getStringForDialog(bv->cursor());
2310 cur.clearSelection();
2312 p["symbol"] = cmd.argument();
2313 string const data = InsetCommand::params2string(p);
2314 bv->showDialog("nomenclature", data);
2318 case LFUN_INDEX_PRINT: {
2319 InsetCommandParams p(INDEX_PRINT_CODE);
2320 if (cmd.argument().empty())
2321 p["type"] = from_ascii("idx");
2323 p["type"] = cmd.argument();
2324 string const data = InsetCommand::params2string(p);
2325 FuncRequest fr(LFUN_INSET_INSERT, data);
2330 case LFUN_NOMENCL_PRINT:
2331 case LFUN_NEWPAGE_INSERT:
2333 doInsertInset(cur, this, cmd, false, false);
2337 case LFUN_SEPARATOR_INSERT: {
2338 doInsertInset(cur, this, cmd, false, false);
2340 // remove a following space
2341 Paragraph & par = cur.paragraph();
2342 if (cur.pos() != cur.lastpos() && par.isLineSeparator(cur.pos()))
2343 par.eraseChar(cur.pos(), cur.buffer()->params().track_changes);
2347 case LFUN_DEPTH_DECREMENT:
2348 changeDepth(cur, DEC_DEPTH);
2351 case LFUN_DEPTH_INCREMENT:
2352 changeDepth(cur, INC_DEPTH);
2355 case LFUN_REGEXP_MODE:
2356 regexpDispatch(cur, cmd);
2359 case LFUN_MATH_MODE: {
2360 if (cmd.argument() == "on" || cmd.argument() == "") {
2361 // don't pass "on" as argument
2362 // (it would appear literally in the first cell)
2363 docstring sel = cur.selectionAsString(false);
2364 InsetMathMacroTemplate * macro = new InsetMathMacroTemplate(cur.buffer());
2365 // create a macro template if we see "\\newcommand" somewhere, and
2366 // an ordinary formula otherwise
2368 && (sel.find(from_ascii("\\newcommand")) != string::npos
2369 || sel.find(from_ascii("\\newlyxcommand")) != string::npos
2370 || sel.find(from_ascii("\\def")) != string::npos)
2371 && macro->fromString(sel)) {
2373 replaceSelection(cur);
2376 // no meaningful macro template was found
2378 mathDispatch(cur,FuncRequest(LFUN_MATH_MODE));
2381 // The argument is meaningful
2382 // We replace cmd with LFUN_MATH_INSERT because LFUN_MATH_MODE
2383 // has a different meaning in math mode
2384 mathDispatch(cur, FuncRequest(LFUN_MATH_INSERT,cmd.argument()));
2388 case LFUN_MATH_MACRO:
2389 if (cmd.argument().empty())
2390 cur.errorMessage(from_utf8(N_("Missing argument")));
2393 string s = to_utf8(cmd.argument());
2394 string const s1 = token(s, ' ', 1);
2395 int const nargs = s1.empty() ? 0 : convert<int>(s1);
2396 string const s2 = token(s, ' ', 2);
2397 MacroType type = MacroTypeNewcommand;
2399 type = MacroTypeDef;
2400 InsetMathMacroTemplate * inset = new InsetMathMacroTemplate(cur.buffer(),
2401 from_utf8(token(s, ' ', 0)), nargs, false, type);
2402 inset->setBuffer(bv->buffer());
2403 insertInset(cur, inset);
2405 // enter macro inset and select the name
2407 cur.top().pos() = cur.top().lastpos();
2409 cur.selection(true);
2410 cur.top().pos() = 0;
2414 case LFUN_MATH_DISPLAY:
2415 case LFUN_MATH_SUBSCRIPT:
2416 case LFUN_MATH_SUPERSCRIPT:
2417 case LFUN_MATH_INSERT:
2418 case LFUN_MATH_AMS_MATRIX:
2419 case LFUN_MATH_MATRIX:
2420 case LFUN_MATH_DELIM:
2421 case LFUN_MATH_BIGDELIM:
2422 mathDispatch(cur, cmd);
2425 case LFUN_FONT_EMPH: {
2426 Font font(ignore_font, ignore_language);
2427 font.fontInfo().setEmph(FONT_TOGGLE);
2428 toggleAndShow(cur, this, font);
2432 case LFUN_FONT_ITAL: {
2433 Font font(ignore_font, ignore_language);
2434 font.fontInfo().setShape(ITALIC_SHAPE);
2435 toggleAndShow(cur, this, font);
2439 case LFUN_FONT_BOLD:
2440 case LFUN_FONT_BOLDSYMBOL: {
2441 Font font(ignore_font, ignore_language);
2442 font.fontInfo().setSeries(BOLD_SERIES);
2443 toggleAndShow(cur, this, font);
2447 case LFUN_FONT_NOUN: {
2448 Font font(ignore_font, ignore_language);
2449 font.fontInfo().setNoun(FONT_TOGGLE);
2450 toggleAndShow(cur, this, font);
2454 case LFUN_FONT_TYPEWRITER: {
2455 Font font(ignore_font, ignore_language);
2456 font.fontInfo().setFamily(TYPEWRITER_FAMILY); // no good
2457 toggleAndShow(cur, this, font);
2461 case LFUN_FONT_SANS: {
2462 Font font(ignore_font, ignore_language);
2463 font.fontInfo().setFamily(SANS_FAMILY);
2464 toggleAndShow(cur, this, font);
2468 case LFUN_FONT_ROMAN: {
2469 Font font(ignore_font, ignore_language);
2470 font.fontInfo().setFamily(ROMAN_FAMILY);
2471 toggleAndShow(cur, this, font);
2475 case LFUN_FONT_DEFAULT: {
2476 Font font(inherit_font, ignore_language);
2477 toggleAndShow(cur, this, font);
2481 case LFUN_FONT_STRIKEOUT: {
2482 Font font(ignore_font, ignore_language);
2483 font.fontInfo().setStrikeout(FONT_TOGGLE);
2484 toggleAndShow(cur, this, font);
2488 case LFUN_FONT_CROSSOUT: {
2489 Font font(ignore_font, ignore_language);
2490 font.fontInfo().setXout(FONT_TOGGLE);
2491 toggleAndShow(cur, this, font);
2495 case LFUN_FONT_UNDERUNDERLINE: {
2496 Font font(ignore_font, ignore_language);
2497 font.fontInfo().setUuline(FONT_TOGGLE);
2498 toggleAndShow(cur, this, font);
2502 case LFUN_FONT_UNDERWAVE: {
2503 Font font(ignore_font, ignore_language);
2504 font.fontInfo().setUwave(FONT_TOGGLE);
2505 toggleAndShow(cur, this, font);
2509 case LFUN_FONT_UNDERLINE: {
2510 Font font(ignore_font, ignore_language);
2511 font.fontInfo().setUnderbar(FONT_TOGGLE);
2512 toggleAndShow(cur, this, font);
2516 case LFUN_FONT_NO_SPELLCHECK: {
2517 Font font(ignore_font, ignore_language);
2518 font.fontInfo().setNoSpellcheck(FONT_TOGGLE);
2519 toggleAndShow(cur, this, font);
2523 case LFUN_FONT_SIZE: {
2524 Font font(ignore_font, ignore_language);
2525 setLyXSize(to_utf8(cmd.argument()), font.fontInfo());
2526 toggleAndShow(cur, this, font);
2530 case LFUN_LANGUAGE: {
2531 string const lang_arg = cmd.getArg(0);
2532 bool const reset = (lang_arg.empty() || lang_arg == "reset");
2533 Language const * lang =
2534 reset ? reset_language
2535 : languages.getLanguage(lang_arg);
2536 // we allow reset_language, which is 0, but only if it
2537 // was requested via empty or "reset" arg.
2538 if (!lang && !reset)
2540 bool const toggle = (cmd.getArg(1) != "set");
2541 selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
2542 Font font(ignore_font, lang);
2543 toggleAndShow(cur, this, font, toggle);
2547 case LFUN_TEXTSTYLE_APPLY: {
2548 unsigned int num = 0;
2549 string const arg = to_utf8(cmd.argument());
2552 if (isStrUnsignedInt(arg)) {
2553 num = convert<uint>(arg);
2554 if (num >= freeFonts.size()) {
2555 cur.message(_("Invalid argument (number exceeds stack size)!"));
2559 cur.message(_("Invalid argument (must be a non-negative number)!"));
2563 toggleAndShow(cur, this, freeFonts[num].second, toggleall);
2564 cur.message(bformat(_("Text properties applied: %1$s"), freeFonts[num].first));
2568 // Set the freefont using the contents of \param data dispatched from
2569 // the frontends and apply it at the current cursor location.
2570 case LFUN_TEXTSTYLE_UPDATE: {
2571 Font font(ignore_font, ignore_language);
2573 if (font.fromString(to_utf8(cmd.argument()), toggle)) {
2574 docstring const props = font.stateText(&bv->buffer().params(), true);
2575 freeFonts.push(make_pair(props, font));
2577 toggleAndShow(cur, this, font, toggleall);
2578 cur.message(bformat(_("Text properties applied: %1$s"), props));
2580 LYXERR0("Invalid argument of textstyle-update");
2584 case LFUN_FINISHED_LEFT:
2585 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_LEFT:\n" << cur);
2586 // We're leaving an inset, going left. If the inset is LTR, we're
2587 // leaving from the front, so we should not move (remain at --- but
2588 // not in --- the inset). If the inset is RTL, move left, without
2589 // entering the inset itself; i.e., move to after the inset.
2590 if (cur.paragraph().getFontSettings(
2591 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2592 cursorVisLeft(cur, true);
2595 case LFUN_FINISHED_RIGHT:
2596 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_RIGHT:\n" << cur);
2597 // We're leaving an inset, going right. If the inset is RTL, we're
2598 // leaving from the front, so we should not move (remain at --- but
2599 // not in --- the inset). If the inset is LTR, move right, without
2600 // entering the inset itself; i.e., move to after the inset.
2601 if (!cur.paragraph().getFontSettings(
2602 cur.bv().buffer().params(), cur.pos()).isRightToLeft())
2603 cursorVisRight(cur, true);
2606 case LFUN_FINISHED_BACKWARD:
2607 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_BACKWARD:\n" << cur);
2608 cur.setCurrentFont();
2611 case LFUN_FINISHED_FORWARD:
2612 LYXERR(Debug::DEBUG, "handle LFUN_FINISHED_FORWARD:\n" << cur);
2614 cur.setCurrentFont();
2617 case LFUN_LAYOUT_PARAGRAPH: {
2619 params2string(cur.paragraph(), data);
2620 data = "show\n" + data;
2621 bv->showDialog("paragraph", data);
2625 case LFUN_PARAGRAPH_UPDATE: {
2627 params2string(cur.paragraph(), data);
2629 // Will the paragraph accept changes from the dialog?
2631 cur.inset().allowParagraphCustomization(cur.idx());
2633 data = "update " + convert<string>(accept) + '\n' + data;
2634 bv->updateDialog("paragraph", data);
2638 case LFUN_ACCENT_UMLAUT:
2639 case LFUN_ACCENT_CIRCUMFLEX:
2640 case LFUN_ACCENT_GRAVE:
2641 case LFUN_ACCENT_ACUTE:
2642 case LFUN_ACCENT_TILDE:
2643 case LFUN_ACCENT_PERISPOMENI:
2644 case LFUN_ACCENT_CEDILLA:
2645 case LFUN_ACCENT_MACRON:
2646 case LFUN_ACCENT_DOT:
2647 case LFUN_ACCENT_UNDERDOT:
2648 case LFUN_ACCENT_UNDERBAR:
2649 case LFUN_ACCENT_CARON:
2650 case LFUN_ACCENT_BREVE:
2651 case LFUN_ACCENT_TIE:
2652 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
2653 case LFUN_ACCENT_CIRCLE:
2654 case LFUN_ACCENT_OGONEK:
2655 theApp()->handleKeyFunc(cmd.action());
2656 if (!cmd.argument().empty())
2657 // FIXME: Are all these characters encoded in one byte in utf8?
2658 bv->translateAndInsert(cmd.argument()[0], this, cur);
2659 cur.screenUpdateFlags(Update::FitCursor);
2662 case LFUN_FLOAT_LIST_INSERT: {
2663 DocumentClass const & tclass = bv->buffer().params().documentClass();
2664 if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
2666 if (cur.selection())
2667 cutSelection(cur, false);
2668 breakParagraph(cur);
2670 if (cur.lastpos() != 0) {
2671 cursorBackward(cur);
2672 breakParagraph(cur);
2675 docstring const laystr = cur.inset().usePlainLayout() ?
2676 tclass.plainLayoutName() :
2677 tclass.defaultLayoutName();
2678 setLayout(cur, laystr);
2679 ParagraphParameters p;
2680 // FIXME If this call were replaced with one to clearParagraphParams(),
2681 // then we could get rid of this method altogether.
2682 setParagraphs(cur, p);
2683 // FIXME This should be simplified when InsetFloatList takes a
2684 // Buffer in its constructor.
2685 InsetFloatList * ifl = new InsetFloatList(cur.buffer(), to_utf8(cmd.argument()));
2686 ifl->setBuffer(bv->buffer());
2687 insertInset(cur, ifl);
2690 lyxerr << "Non-existent float type: "
2691 << to_utf8(cmd.argument()) << endl;
2696 case LFUN_CHANGE_ACCEPT: {
2697 acceptOrRejectChanges(cur, ACCEPT);
2701 case LFUN_CHANGE_REJECT: {
2702 acceptOrRejectChanges(cur, REJECT);
2706 case LFUN_THESAURUS_ENTRY: {
2707 Language const * language = cur.getFont().language();
2708 docstring arg = cmd.argument();
2710 arg = cur.selectionAsString(false);
2711 // Too large. We unselect if needed and try to get
2712 // the first word in selection or under cursor
2713 if (arg.size() > 100 || arg.empty()) {
2714 if (cur.selection()) {
2715 DocIterator selbeg = cur.selectionBegin();
2716 cur.clearSelection();
2717 setCursorIntern(cur, selbeg.pit(), selbeg.pos());
2718 cur.screenUpdateFlags(Update::Force);
2720 // Get word or selection
2721 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2722 arg = cur.selectionAsString(false);
2723 arg += " lang=" + from_ascii(language->lang());
2726 string lang = cmd.getArg(1);
2727 // This duplicates the code in GuiThesaurus::initialiseParams
2728 if (prefixIs(lang, "lang=")) {
2729 language = languages.getLanguage(lang.substr(5));
2731 language = cur.getFont().language();
2734 string lang = language->code();
2735 if (lyxrc.thesaurusdir_path.empty() && !thesaurus.thesaurusInstalled(from_ascii(lang))) {
2736 LYXERR(Debug::ACTION, "Command " << cmd << ". Thesaurus not found for language " << lang);
2737 frontend::Alert::warning(_("Path to thesaurus directory not set!"),
2738 _("The path to the thesaurus directory has not been specified.\n"
2739 "The thesaurus is not functional.\n"
2740 "Please refer to sec. 6.15.1 of the User's Guide for setup\n"
2743 bv->showDialog("thesaurus", to_utf8(arg));
2747 case LFUN_SPELLING_ADD: {
2748 Language const * language = getLanguage(cur, cmd.getArg(1));
2749 docstring word = from_utf8(cmd.getArg(0));
2751 word = cur.selectionAsString(false);
2753 if (word.size() > 100 || word.empty()) {
2754 // Get word or selection
2755 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2756 word = cur.selectionAsString(false);
2759 WordLangTuple wl(word, language);
2760 theSpellChecker()->insert(wl);
2764 case LFUN_SPELLING_ADD_LOCAL: {
2765 Language const * language = getLanguage(cur, cmd.getArg(1));
2766 docstring word = from_utf8(cmd.getArg(0));
2768 word = cur.selectionAsString(false);
2769 if (word.size() > 100)
2772 // Get word or selection
2773 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2774 word = cur.selectionAsString(false);
2777 WordLangTuple wl(word, language);
2778 if (!bv->buffer().params().spellignored(wl)) {
2779 cur.recordUndoBufferParams();
2780 bv->buffer().params().spellignore().push_back(wl);
2782 // trigger re-check of whole buffer
2783 bv->buffer().requestSpellcheck();
2788 case LFUN_SPELLING_REMOVE_LOCAL: {
2789 Language const * language = getLanguage(cur, cmd.getArg(1));
2790 docstring word = from_utf8(cmd.getArg(0));
2792 word = cur.selectionAsString(false);
2793 if (word.size() > 100)
2796 // Get word or selection
2797 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2798 word = cur.selectionAsString(false);
2801 WordLangTuple wl(word, language);
2802 bool has_item = false;
2803 vector<WordLangTuple>::const_iterator it = bv->buffer().params().spellignore().begin();
2804 for (; it != bv->buffer().params().spellignore().end(); ++it) {
2805 if (it->lang()->code() != wl.lang()->code())
2807 if (it->word() == wl.word()) {
2813 cur.recordUndoBufferParams();
2814 bv->buffer().params().spellignore().erase(it);
2816 // trigger re-check of whole buffer
2817 bv->buffer().requestSpellcheck();
2823 case LFUN_SPELLING_IGNORE: {
2824 Language const * language = getLanguage(cur, cmd.getArg(1));
2825 docstring word = from_utf8(cmd.getArg(0));
2827 word = cur.selectionAsString(false);
2829 if (word.size() > 100 || word.empty()) {
2830 // Get word or selection
2831 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2832 word = cur.selectionAsString(false);
2835 WordLangTuple wl(word, language);
2836 theSpellChecker()->accept(wl);
2840 case LFUN_SPELLING_REMOVE: {
2841 Language const * language = getLanguage(cur, cmd.getArg(1));
2842 docstring word = from_utf8(cmd.getArg(0));
2844 word = cur.selectionAsString(false);
2846 if (word.size() > 100 || word.empty()) {
2847 // Get word or selection
2848 selectWordWhenUnderCursor(cur, WHOLE_WORD);
2849 word = cur.selectionAsString(false);
2852 WordLangTuple wl(word, language);
2853 theSpellChecker()->remove(wl);
2857 case LFUN_PARAGRAPH_PARAMS_APPLY: {
2858 // Given data, an encoding of the ParagraphParameters
2859 // generated in the Paragraph dialog, this function sets
2860 // the current paragraph, or currently selected paragraphs,
2862 // NOTE: This function overrides all existing settings.
2863 setParagraphs(cur, cmd.argument());
2864 cur.message(_("Paragraph layout set"));
2868 case LFUN_PARAGRAPH_PARAMS: {
2869 // Given data, an encoding of the ParagraphParameters as we'd
2870 // find them in a LyX file, this function modifies the current paragraph,
2871 // or currently selected paragraphs.
2872 // NOTE: This function only modifies, and does not override, existing
2874 setParagraphs(cur, cmd.argument(), true);
2875 cur.message(_("Paragraph layout set"));
2880 if (cur.selection()) {
2881 cur.selection(false);
2884 // This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more
2885 // correct, but I'm not 100% sure -- dov, 071019
2886 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
2890 case LFUN_OUTLINE_UP: {
2891 pos_type const opos = cur.pos();
2892 outline(OutlineUp, cur, this);
2893 setCursor(cur, cur.pit(), opos);
2894 cur.forceBufferUpdate();
2899 case LFUN_OUTLINE_DOWN: {
2900 pos_type const opos = cur.pos();
2901 outline(OutlineDown, cur, this);
2902 setCursor(cur, cur.pit(), opos);
2903 cur.forceBufferUpdate();
2908 case LFUN_OUTLINE_IN:
2909 outline(OutlineIn, cur, this);
2910 cur.forceBufferUpdate();
2914 case LFUN_OUTLINE_OUT:
2915 outline(OutlineOut, cur, this);
2916 cur.forceBufferUpdate();
2920 case LFUN_SERVER_GET_STATISTICS: {
2921 DocIterator from, to;
2922 if (cur.selection()) {
2923 from = cur.selectionBegin();
2924 to = cur.selectionEnd();
2926 from = doc_iterator_begin(cur.buffer());
2927 to = doc_iterator_end(cur.buffer());
2930 cur.buffer()->updateStatistics(from, to);
2931 string const arg0 = cmd.getArg(0);
2932 if (arg0 == "words") {
2933 cur.message(convert<docstring>(cur.buffer()->wordCount()));
2934 } else if (arg0 == "chars") {
2935 cur.message(convert<docstring>(cur.buffer()->charCount(false)));
2936 } else if (arg0 == "chars-space") {
2937 cur.message(convert<docstring>(cur.buffer()->charCount(true)));
2939 cur.message(convert<docstring>(cur.buffer()->wordCount()) + " "
2940 + convert<docstring>(cur.buffer()->charCount(false)) + " "
2941 + convert<docstring>(cur.buffer()->charCount(true)));
2947 LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
2952 needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
2954 if (lyxrc.spellcheck_continuously && !needsUpdate) {
2955 // Check for misspelled text
2956 // The redraw is useful because of the painting of
2957 // misspelled markers depends on the cursor position.
2958 // Trigger a redraw for cursor moves inside misspelled text.
2959 if (!cur.inTexted()) {
2960 // move from regular text to math
2961 needsUpdate = last_misspelled;
2962 } else if (oldTopSlice != cur.top() || oldBoundary != cur.boundary()) {
2963 // move inside regular text
2964 needsUpdate = last_misspelled
2965 || cur.paragraph().isMisspelled(cur.pos(), true);
2969 // FIXME: The cursor flag is reset two lines below
2970 // so we need to check here if some of the LFUN did touch that.
2971 // for now only Text::erase() and Text::backspace() do that.
2972 // The plan is to verify all the LFUNs and then to remove this
2973 // singleParUpdate boolean altogether.
2974 if (cur.result().screenUpdate() & Update::Force) {
2975 singleParUpdate = false;
2979 // FIXME: the following code should go in favor of fine grained
2980 // update flag treatment.
2981 if (singleParUpdate) {
2982 // Inserting characters does not change par height in general. So, try
2983 // to update _only_ this paragraph. BufferView will detect if a full
2984 // metrics update is needed anyway.
2985 cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
2989 && &oldTopSlice.inset() == &cur.inset()
2990 && oldTopSlice.idx() == cur.idx()
2991 && !oldSelection // oldSelection is a backup of cur.selection() at the beginning of the function.
2992 && !cur.selection())
2993 // FIXME: it would be better if we could just do this
2995 //if (cur.result().update() != Update::FitCursor)
2996 // cur.noScreenUpdate();
2998 // But some LFUNs do not set Update::FitCursor when needed, so we
2999 // do it for all. This is not very harmfull as FitCursor will provoke
3000 // a full redraw only if needed but still, a proper review of all LFUN
3001 // should be done and this needsUpdate boolean can then be removed.
3002 cur.screenUpdateFlags(Update::FitCursor);
3004 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
3008 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
3009 FuncStatus & status) const
3011 LBUFERR(this == cur.text());
3013 FontInfo const & fontinfo = cur.real_current_font.fontInfo();
3015 bool allow_in_passthru = false;
3016 InsetCode code = NO_CODE;
3018 switch (cmd.action()) {
3020 case LFUN_DEPTH_DECREMENT:
3021 enable = changeDepthAllowed(cur, DEC_DEPTH);
3024 case LFUN_DEPTH_INCREMENT:
3025 enable = changeDepthAllowed(cur, INC_DEPTH);
3029 // FIXME We really should not allow this to be put, e.g.,
3030 // in a footnote, or in ERT. But it would make sense in a
3031 // branch, so I'm not sure what to do.
3032 status.setOnOff(cur.paragraph().params().startOfAppendix());
3035 case LFUN_DIALOG_SHOW_NEW_INSET:
3036 if (cmd.argument() == "bibitem")
3037 code = BIBITEM_CODE;
3038 else if (cmd.argument() == "bibtex") {
3040 // not allowed in description items
3041 enable = !inDescriptionItem(cur);
3043 else if (cmd.argument() == "box")
3045 else if (cmd.argument() == "branch")
3047 else if (cmd.argument() == "citation")
3049 else if (cmd.argument() == "counter")
3050 code = COUNTER_CODE;
3051 else if (cmd.argument() == "ert")
3053 else if (cmd.argument() == "external")
3054 code = EXTERNAL_CODE;
3055 else if (cmd.argument() == "float")
3057 else if (cmd.argument() == "graphics")
3058 code = GRAPHICS_CODE;
3059 else if (cmd.argument() == "href")
3060 code = HYPERLINK_CODE;
3061 else if (cmd.argument() == "include")
3062 code = INCLUDE_CODE;
3063 else if (cmd.argument() == "index")
3065 else if (cmd.argument() == "index_print")
3066 code = INDEX_PRINT_CODE;
3067 else if (cmd.argument() == "listings")
3068 code = LISTINGS_CODE;
3069 else if (cmd.argument() == "mathspace")
3070 code = MATH_HULL_CODE;
3071 else if (cmd.argument() == "nomenclature")
3072 code = NOMENCL_CODE;
3073 else if (cmd.argument() == "nomencl_print")
3074 code = NOMENCL_PRINT_CODE;
3075 else if (cmd.argument() == "label")
3077 else if (cmd.argument() == "line")
3079 else if (cmd.argument() == "note")
3081 else if (cmd.argument() == "phantom")
3082 code = PHANTOM_CODE;
3083 else if (cmd.argument() == "ref")
3085 else if (cmd.argument() == "space")
3087 else if (cmd.argument() == "toc")
3089 else if (cmd.argument() == "vspace")
3091 else if (cmd.argument() == "wrap")
3095 case LFUN_ERT_INSERT:
3098 case LFUN_LISTING_INSERT:
3099 code = LISTINGS_CODE;
3100 // not allowed in description items
3101 enable = !inDescriptionItem(cur);
3103 case LFUN_FOOTNOTE_INSERT:
3106 case LFUN_TABULAR_INSERT:
3107 code = TABULAR_CODE;
3109 case LFUN_TABULAR_STYLE_INSERT:
3110 code = TABULAR_CODE;
3112 case LFUN_MARGINALNOTE_INSERT:
3115 case LFUN_FLOAT_INSERT:
3116 case LFUN_FLOAT_WIDE_INSERT:
3117 // FIXME: If there is a selection, we should check whether there
3118 // are floats in the selection, but this has performance issues, see
3119 // LFUN_CHANGE_ACCEPT/REJECT.
3121 if (inDescriptionItem(cur))
3122 // not allowed in description items
3125 InsetCode const inset_code = cur.inset().lyxCode();
3127 // algorithm floats cannot be put in another float
3128 if (to_utf8(cmd.argument()) == "algorithm") {
3129 enable = inset_code != WRAP_CODE && inset_code != FLOAT_CODE;
3133 // for figures and tables: only allow in another
3134 // float or wrap if it is of the same type and
3135 // not a subfloat already
3136 if(cur.inset().lyxCode() == code) {
3137 InsetFloat const & ins =
3138 static_cast<InsetFloat const &>(cur.inset());
3139 enable = ins.params().type == to_utf8(cmd.argument())
3140 && !ins.params().subfloat;
3141 } else if(cur.inset().lyxCode() == WRAP_CODE) {
3142 InsetWrap const & ins =
3143 static_cast<InsetWrap const &>(cur.inset());
3144 enable = ins.params().type == to_utf8(cmd.argument());
3148 case LFUN_WRAP_INSERT:
3150 // not allowed in description items
3151 enable = !inDescriptionItem(cur);
3153 case LFUN_FLOAT_LIST_INSERT: {
3154 code = FLOAT_LIST_CODE;
3155 // not allowed in description items
3156 enable = !inDescriptionItem(cur);
3158 FloatList const & floats = cur.buffer()->params().documentClass().floats();
3159 FloatList::const_iterator cit = floats[to_ascii(cmd.argument())];
3160 // make sure we know about such floats
3161 if (cit == floats.end() ||
3162 // and that we know how to generate a list of them
3163 (!cit->second.usesFloatPkg() && cit->second.listCommand().empty())) {
3164 status.setUnknown(true);
3165 // probably not necessary, but...
3171 case LFUN_CAPTION_INSERT: {
3172 code = CAPTION_CODE;
3173 string arg = cmd.getArg(0);
3174 bool varia = arg != "Unnumbered"
3175 && cur.inset().allowsCaptionVariation(arg);
3176 // not allowed in description items,
3177 // and in specific insets
3178 enable = !inDescriptionItem(cur)
3179 && (varia || arg.empty() || arg == "Standard");
3182 case LFUN_NOTE_INSERT:
3185 case LFUN_FLEX_INSERT: {
3187 docstring s = from_utf8(cmd.getArg(0));
3188 // Prepend "Flex:" prefix if not there
3189 if (!prefixIs(s, from_ascii("Flex:")))
3190 s = from_ascii("Flex:") + s;
3191 if (!cur.buffer()->params().documentClass().hasInsetLayout(s))
3195 cur.buffer()->params().documentClass().insetLayout(s).lyxtype();
3196 if (ilt != InsetLyXType::CHARSTYLE
3197 && ilt != InsetLyXType::CUSTOM
3198 && ilt != InsetLyXType::STANDARD)
3203 case LFUN_BOX_INSERT:
3206 case LFUN_BRANCH_INSERT:
3208 if (cur.buffer()->masterBuffer()->params().branchlist().empty()
3209 && cur.buffer()->params().branchlist().empty())
3212 case LFUN_IPA_INSERT:
3215 case LFUN_PHANTOM_INSERT:
3216 code = PHANTOM_CODE;
3218 case LFUN_LABEL_INSERT:
3221 case LFUN_INFO_INSERT:
3223 enable = cmd.argument().empty()
3224 || infoparams.validateArgument(cur.buffer(), cmd.argument(), true);
3226 case LFUN_ARGUMENT_INSERT: {
3228 allow_in_passthru = true;
3229 string const arg = cmd.getArg(0);
3234 Layout const & lay = cur.paragraph().layout();
3235 Layout::LaTeXArgMap args = lay.args();
3236 Layout::LaTeXArgMap::const_iterator const lait =
3238 if (lait != args.end()) {
3240 pit_type pit = cur.pit();
3241 pit_type lastpit = cur.pit();
3242 if (lay.isEnvironment() && !prefixIs(arg, "item:")) {
3243 // In a sequence of "merged" environment layouts, we only allow
3244 // non-item arguments once.
3245 lastpit = cur.lastpit();
3246 // get the first paragraph in sequence with this layout
3247 depth_type const current_depth = cur.paragraph().params().depth();
3251 Paragraph cpar = pars_[pit - 1];
3252 if (cpar.layout() == lay && cpar.params().depth() == current_depth)
3258 for (; pit <= lastpit; ++pit) {
3259 if (pars_[pit].layout() != lay)
3261 for (auto const & table : pars_[pit].insetList())
3262 if (InsetArgument const * ins = table.inset->asInsetArgument())
3263 if (ins->name() == arg) {
3264 // we have this already
3273 case LFUN_INDEX_INSERT:
3276 case LFUN_INDEX_PRINT:
3277 code = INDEX_PRINT_CODE;
3278 // not allowed in description items
3279 enable = !inDescriptionItem(cur);
3281 case LFUN_NOMENCL_INSERT:
3282 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
3286 code = NOMENCL_CODE;
3288 case LFUN_NOMENCL_PRINT:
3289 code = NOMENCL_PRINT_CODE;
3290 // not allowed in description items
3291 enable = !inDescriptionItem(cur);
3293 case LFUN_HREF_INSERT:
3294 if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
3298 code = HYPERLINK_CODE;
3300 case LFUN_INDEXMACRO_INSERT: {
3301 string const arg = cmd.getArg(0);
3302 if (arg == "sortkey")
3303 code = INDEXMACRO_SORTKEY_CODE;
3305 code = INDEXMACRO_CODE;
3308 case LFUN_IPAMACRO_INSERT: {
3309 string const arg = cmd.getArg(0);
3311 code = IPADECO_CODE;
3313 code = IPACHAR_CODE;
3316 case LFUN_QUOTE_INSERT:
3317 // always allow this, since we will inset a raw quote
3318 // if an inset is not allowed.
3319 allow_in_passthru = true;
3321 case LFUN_SPECIALCHAR_INSERT:
3322 code = SPECIALCHAR_CODE;
3324 case LFUN_SPACE_INSERT:
3325 // slight hack: we know this is allowed in math mode
3329 case LFUN_PREVIEW_INSERT:
3330 code = PREVIEW_CODE;
3332 case LFUN_SCRIPT_INSERT:
3336 case LFUN_MATH_INSERT:
3337 case LFUN_MATH_AMS_MATRIX:
3338 case LFUN_MATH_MATRIX:
3339 case LFUN_MATH_DELIM:
3340 case LFUN_MATH_BIGDELIM:
3341 case LFUN_MATH_DISPLAY:
3342 case LFUN_MATH_MODE:
3343 case LFUN_MATH_MACRO:
3344 case LFUN_MATH_SUBSCRIPT:
3345 case LFUN_MATH_SUPERSCRIPT:
3346 code = MATH_HULL_CODE;
3349 case LFUN_REGEXP_MODE:
3350 code = MATH_HULL_CODE;
3351 enable = cur.buffer()->isInternal() && !cur.inRegexped();
3354 case LFUN_INSET_MODIFY:
3355 // We need to disable this, because we may get called for a
3357 // InsetTabular::getStatus() -> InsetText::getStatus()
3358 // and we don't handle LFUN_INSET_MODIFY.
3362 case LFUN_FONT_EMPH:
3363 status.setOnOff(fontinfo.emph() == FONT_ON);
3364 enable = !cur.paragraph().isPassThru();
3367 case LFUN_FONT_ITAL:
3368 status.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
3369 enable = !cur.paragraph().isPassThru();
3372 case LFUN_FONT_NOUN:
3373 status.setOnOff(fontinfo.noun() == FONT_ON);
3374 enable = !cur.paragraph().isPassThru();
3377 case LFUN_FONT_BOLD:
3378 case LFUN_FONT_BOLDSYMBOL:
3379 status.setOnOff(fontinfo.series() == BOLD_SERIES);
3380 enable = !cur.paragraph().isPassThru();
3383 case LFUN_FONT_SANS:
3384 status.setOnOff(fontinfo.family() == SANS_FAMILY);
3385 enable = !cur.paragraph().isPassThru();
3388 case LFUN_FONT_ROMAN:
3389 status.setOnOff(fontinfo.family() == ROMAN_FAMILY);
3390 enable = !cur.paragraph().isPassThru();
3393 case LFUN_FONT_TYPEWRITER:
3394 status.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
3395 enable = !cur.paragraph().isPassThru();
3399 enable = cur.selection();
3403 if (cmd.argument().empty()) {
3404 if (theClipboard().isInternal())
3405 enable = cap::numberOfSelections() > 0;
3407 enable = !theClipboard().empty();
3411 // we have an argument
3412 string const arg = to_utf8(cmd.argument());
3413 if (isStrUnsignedInt(arg)) {
3414 // it's a number and therefore means the internal stack
3415 unsigned int n = convert<unsigned int>(arg);
3416 enable = cap::numberOfSelections() > n;
3420 // explicit text type?
3421 if (arg == "html") {
3422 // Do not enable for PlainTextType, since some tidying in the
3423 // frontend is needed for HTML, which is too unsafe for plain text.
3424 enable = theClipboard().hasTextContents(Clipboard::HtmlTextType);
3426 } else if (arg == "latex") {
3427 // LaTeX is usually not available on the clipboard with
3428 // the correct MIME type, but in plain text.
3429 enable = theClipboard().hasTextContents(Clipboard::PlainTextType) ||
3430 theClipboard().hasTextContents(Clipboard::LaTeXTextType);
3434 Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
3436 type = Clipboard::PdfGraphicsType;
3437 else if (arg == "png")
3438 type = Clipboard::PngGraphicsType;
3439 else if (arg == "jpeg")
3440 type = Clipboard::JpegGraphicsType;
3441 else if (arg == "linkback")
3442 type = Clipboard::LinkBackGraphicsType;
3443 else if (arg == "emf")
3444 type = Clipboard::EmfGraphicsType;
3445 else if (arg == "wmf")
3446 type = Clipboard::WmfGraphicsType;
3449 LYXERR0("Unrecognized graphics type: " << arg);
3450 // we don't want to assert if the user just mistyped the LFUN
3451 LATTEST(cmd.origin() != FuncRequest::INTERNAL);
3455 enable = theClipboard().hasGraphicsContents(type);
3459 case LFUN_CLIPBOARD_PASTE:
3460 case LFUN_CLIPBOARD_PASTE_SIMPLE:
3461 enable = !theClipboard().empty();
3464 case LFUN_PRIMARY_SELECTION_PASTE:
3465 status.setUnknown(!theSelection().supported());
3466 enable = cur.selection() || !theSelection().empty();
3469 case LFUN_SELECTION_PASTE:
3470 enable = cap::selection();
3473 case LFUN_PARAGRAPH_MOVE_UP:
3474 enable = cur.pit() > 0 && !cur.selection();
3477 case LFUN_PARAGRAPH_MOVE_DOWN:
3478 enable = cur.pit() < cur.lastpit() && !cur.selection();
3481 case LFUN_CHANGE_ACCEPT:
3482 case LFUN_CHANGE_REJECT:
3483 if (!cur.selection())
3484 enable = cur.paragraph().isChanged(cur.pos());
3486 // will enable if there is a change in the selection
3489 // cheap improvement for efficiency: using cached
3490 // buffer variable, if there is no change in the
3491 // document, no need to check further.
3492 if (!cur.buffer()->areChangesPresent())
3495 for (DocIterator it = cur.selectionBegin(); ; it.forwardPar()) {
3496 pos_type const beg = it.pos();
3498 bool const in_last_par = (it.pit() == cur.selectionEnd().pit() &&
3499 it.idx() == cur.selectionEnd().idx());
3501 end = cur.selectionEnd().pos();
3503 // the +1 is needed for cases, e.g., where there is a
3504 // paragraph break. See #11629.
3505 end = it.lastpos() + 1;
3506 if (beg != end && it.paragraph().isChanged(beg, end)) {
3510 if (beg != end && it.paragraph().hasChangedInsets(beg, end)) {
3520 case LFUN_OUTLINE_UP:
3521 case LFUN_OUTLINE_DOWN:
3522 case LFUN_OUTLINE_IN:
3523 case LFUN_OUTLINE_OUT:
3524 // FIXME: LyX is not ready for outlining within inset.
3525 enable = isMainText()
3526 && cur.buffer()->text().getTocLevel(cur.pit()) != Layout::NOT_IN_TOC;
3529 case LFUN_NEWLINE_INSERT:
3530 // LaTeX restrictions (labels or empty par)
3531 enable = !cur.paragraph().isPassThru()
3532 && cur.pos() > cur.paragraph().beginOfBody();
3535 case LFUN_SEPARATOR_INSERT:
3536 // Always enabled for now
3540 case LFUN_TAB_INSERT:
3541 case LFUN_TAB_DELETE:
3542 enable = cur.paragraph().isPassThru();
3545 case LFUN_GRAPHICS_SET_GROUP: {
3546 InsetGraphics * ins = graphics::getCurrentGraphicsInset(cur);
3550 status.setOnOff(to_utf8(cmd.argument()) == ins->getParams().groupId);
3554 case LFUN_NEWPAGE_INSERT:
3555 // not allowed in description items
3556 code = NEWPAGE_CODE;
3557 enable = !inDescriptionItem(cur);
3561 enable = !cur.paragraph().isPassThru();
3562 status.setOnOff(cmd.getArg(0) == cur.real_current_font.language()->lang());
3565 case LFUN_PARAGRAPH_BREAK:
3566 enable = inset().allowMultiPar();
3569 case LFUN_SPELLING_ADD:
3570 case LFUN_SPELLING_ADD_LOCAL:
3571 case LFUN_SPELLING_REMOVE_LOCAL:
3572 case LFUN_SPELLING_IGNORE:
3573 case LFUN_SPELLING_REMOVE:
3574 enable = theSpellChecker() != nullptr;
3575 if (enable && !cmd.getArg(1).empty()) {
3576 // validate explicitly given language
3577 Language const * const lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
3578 enable &= lang != nullptr;
3583 case LFUN_LAYOUT_TOGGLE: {
3584 bool const ignoreautonests = cmd.getArg(1) == "ignoreautonests";
3585 docstring const req_layout = ignoreautonests ? from_utf8(cmd.getArg(0)) : cmd.argument();
3586 docstring const layout = resolveLayout(req_layout, cur);
3588 // FIXME: make this work in multicell selection case
3589 enable = !owner_->forcePlainLayout() && !layout.empty() && !cur.selIsMultiCell();
3590 status.setOnOff(!owner_->forcePlainLayout() && !cur.selIsMultiCell()
3591 && isAlreadyLayout(layout, cur));
3595 case LFUN_ENVIRONMENT_SPLIT: {
3596 if (cmd.argument() == "outer") {
3597 // check if we have an environment in our nesting hierarchy
3599 depth_type const current_depth = cur.paragraph().params().depth();
3600 pit_type pit = cur.pit();
3601 Paragraph cpar = pars_[pit];
3603 if (pit == 0 || cpar.params().depth() == 0)
3607 if (cpar.params().depth() < current_depth)
3608 res = cpar.layout().isEnvironment();
3613 else if (cmd.argument() == "previous") {
3614 // look if we have an environment in the previous par
3615 pit_type pit = cur.pit();
3616 Paragraph cpar = pars_[pit];
3620 enable = cpar.layout().isEnvironment();
3626 else if (cur.paragraph().layout().isEnvironment()) {
3627 enable = cmd.argument() == "before"
3628 || cur.pos() > 0 || !isFirstInSequence(cur.pit());
3635 case LFUN_LAYOUT_PARAGRAPH:
3636 case LFUN_PARAGRAPH_PARAMS:
3637 case LFUN_PARAGRAPH_PARAMS_APPLY:
3638 case LFUN_PARAGRAPH_UPDATE:
3639 enable = owner_->allowParagraphCustomization();
3642 // FIXME: why are accent lfuns forbidden with pass_thru layouts?
3643 // Because they insert COMBINING DIACRITICAL Unicode characters,
3644 // that cannot be handled by LaTeX but must be converted according
3645 // to the definition in lib/unicodesymbols?
3646 case LFUN_ACCENT_ACUTE:
3647 case LFUN_ACCENT_BREVE:
3648 case LFUN_ACCENT_CARON:
3649 case LFUN_ACCENT_CEDILLA:
3650 case LFUN_ACCENT_CIRCLE:
3651 case LFUN_ACCENT_CIRCUMFLEX:
3652 case LFUN_ACCENT_DOT:
3653 case LFUN_ACCENT_GRAVE:
3654 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
3655 case LFUN_ACCENT_MACRON:
3656 case LFUN_ACCENT_OGONEK:
3657 case LFUN_ACCENT_TIE:
3658 case LFUN_ACCENT_TILDE:
3659 case LFUN_ACCENT_PERISPOMENI:
3660 case LFUN_ACCENT_UMLAUT:
3661 case LFUN_ACCENT_UNDERBAR:
3662 case LFUN_ACCENT_UNDERDOT:
3663 case LFUN_FONT_FRAK:
3664 case LFUN_FONT_SIZE:
3665 case LFUN_FONT_STATE:
3666 case LFUN_FONT_UNDERLINE:
3667 case LFUN_FONT_STRIKEOUT:
3668 case LFUN_FONT_CROSSOUT:
3669 case LFUN_FONT_UNDERUNDERLINE:
3670 case LFUN_FONT_UNDERWAVE:
3671 case LFUN_FONT_NO_SPELLCHECK:
3672 case LFUN_TEXTSTYLE_UPDATE:
3673 enable = !cur.paragraph().isPassThru();
3676 case LFUN_FONT_DEFAULT: {
3677 Font font(inherit_font, ignore_language);
3678 BufferParams const & bp = cur.buffer()->masterParams();
3679 if (cur.selection()) {
3681 // Check if we have a non-default font attribute
3682 // in the selection range.
3683 DocIterator const from = cur.selectionBegin();
3684 DocIterator const to = cur.selectionEnd();
3685 for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) {
3686 if (!dit.inTexted()) {
3690 Paragraph const & par = dit.paragraph();
3691 pos_type const pos = dit.pos();
3692 Font tmp = par.getFontSettings(bp, pos);
3693 if (tmp.fontInfo() != font.fontInfo()
3694 || tmp.language() != bp.language) {
3702 // Disable if all is default already.
3703 enable = (cur.current_font.fontInfo() != font.fontInfo()
3704 || cur.current_font.language() != bp.language);
3708 case LFUN_TEXTSTYLE_APPLY:
3709 enable = !freeFonts.empty();
3712 case LFUN_WORD_DELETE_FORWARD:
3713 case LFUN_WORD_DELETE_BACKWARD:
3714 case LFUN_LINE_DELETE_FORWARD:
3715 case LFUN_WORD_FORWARD:
3716 case LFUN_WORD_BACKWARD:
3717 case LFUN_WORD_RIGHT:
3718 case LFUN_WORD_LEFT:
3719 case LFUN_CHAR_FORWARD:
3720 case LFUN_CHAR_FORWARD_SELECT:
3721 case LFUN_CHAR_BACKWARD:
3722 case LFUN_CHAR_BACKWARD_SELECT:
3723 case LFUN_CHAR_LEFT:
3724 case LFUN_CHAR_LEFT_SELECT:
3725 case LFUN_CHAR_RIGHT:
3726 case LFUN_CHAR_RIGHT_SELECT:
3728 case LFUN_UP_SELECT:
3730 case LFUN_DOWN_SELECT:
3731 case LFUN_PARAGRAPH_SELECT:
3732 case LFUN_PARAGRAPH_UP_SELECT:
3733 case LFUN_PARAGRAPH_DOWN_SELECT:
3734 case LFUN_LINE_BEGIN_SELECT:
3735 case LFUN_LINE_END_SELECT:
3736 case LFUN_WORD_FORWARD_SELECT:
3737 case LFUN_WORD_BACKWARD_SELECT:
3738 case LFUN_WORD_RIGHT_SELECT:
3739 case LFUN_WORD_LEFT_SELECT:
3740 case LFUN_WORD_SELECT:
3741 case LFUN_SECTION_SELECT:
3742 case LFUN_BUFFER_BEGIN:
3743 case LFUN_BUFFER_END:
3744 case LFUN_BUFFER_BEGIN_SELECT:
3745 case LFUN_BUFFER_END_SELECT:
3746 case LFUN_INSET_BEGIN:
3747 case LFUN_INSET_END:
3748 case LFUN_INSET_BEGIN_SELECT:
3749 case LFUN_INSET_END_SELECT:
3750 case LFUN_PARAGRAPH_UP:
3751 case LFUN_PARAGRAPH_DOWN:
3752 case LFUN_LINE_BEGIN:
3754 case LFUN_CHAR_DELETE_FORWARD:
3755 case LFUN_CHAR_DELETE_BACKWARD:
3756 case LFUN_WORD_UPCASE:
3757 case LFUN_WORD_LOWCASE:
3758 case LFUN_WORD_CAPITALIZE:
3759 case LFUN_CHARS_TRANSPOSE:
3760 case LFUN_SERVER_GET_XY:
3761 case LFUN_SERVER_SET_XY:
3762 case LFUN_SERVER_GET_LAYOUT:
3763 case LFUN_SELF_INSERT:
3764 case LFUN_UNICODE_INSERT:
3765 case LFUN_THESAURUS_ENTRY:
3767 case LFUN_SERVER_GET_STATISTICS:
3768 // these are handled in our dispatch()
3772 case LFUN_INSET_INSERT: {
3773 string const type = cmd.getArg(0);
3774 if (type == "toc") {
3776 // not allowed in description items
3777 //FIXME: couldn't this be merged in Inset::insetAllowed()?
3778 enable = !inDescriptionItem(cur);
3785 case LFUN_SEARCH_IGNORE: {
3786 bool const value = cmd.getArg(1) == "true";
3787 setIgnoreFormat(cmd.getArg(0), value);
3797 || !cur.inset().insetAllowed(code)
3798 || (cur.paragraph().layout().pass_thru && !allow_in_passthru)))
3801 status.setEnabled(enable);
3806 void Text::pasteString(Cursor & cur, docstring const & clip,
3809 if (!clip.empty()) {
3812 insertStringAsParagraphs(cur, clip, cur.current_font);
3814 insertStringAsLines(cur, clip, cur.current_font);
3819 // FIXME: an item inset would make things much easier.
3820 bool Text::inDescriptionItem(Cursor const & cur) const
3822 Paragraph const & par = cur.paragraph();
3823 pos_type const pos = cur.pos();
3824 pos_type const body_pos = par.beginOfBody();
3826 if (par.layout().latextype != LATEX_LIST_ENVIRONMENT
3827 && (par.layout().latextype != LATEX_ITEM_ENVIRONMENT
3828 || par.layout().margintype != MARGIN_FIRST_DYNAMIC))
3831 return (pos < body_pos
3833 && (pos == 0 || par.getChar(pos - 1) != ' ')));
3837 std::vector<docstring> Text::getFreeFonts() const
3839 vector<docstring> ffList;
3841 for (auto const & f : freeFonts)
3842 ffList.push_back(f.first);