#include "insets/InsetGraphics.h"
#include "insets/InsetGraphicsParams.h"
#include "insets/InsetInfo.h"
+#include "insets/InsetIndexMacro.h"
#include "insets/InsetIPAMacro.h"
#include "insets/InsetNewline.h"
#include "insets/InsetQuotes.h"
cur.real_current_font))
text->setCursor(cur, cur.pit(), cur.pos(),
false, !cur.boundary());
+ if (font.language() != ignore_language)
+ // We need a buffer update if we change the language
+ // (e.g., with info insets or if the selection contains
+ // a par label)
+ cur.forceBufferUpdate();
}
}
static bool doInsertInset(Cursor & cur, Text * text,
- FuncRequest const & cmd, bool edit, bool pastesel)
+ FuncRequest const & cmd, bool edit,
+ bool pastesel, bool resetfont = false)
{
Buffer & buffer = cur.bv().buffer();
BufferParams const & bparams = buffer.params();
cur.recordUndo();
if (cmd.action() == LFUN_ARGUMENT_INSERT) {
bool cotextinsert = false;
- InsetArgument const * const ia = static_cast<InsetArgument const *>(inset);
+ InsetArgument * const ia = static_cast<InsetArgument *>(inset);
Layout const & lay = cur.paragraph().layout();
Layout::LaTeXArgMap args = lay.args();
Layout::LaTeXArgMap::const_iterator const lait = args.find(ia->name());
else
ds = cur.paragraph().asString();
text->insertInset(cur, inset);
+ ia->init(cur.paragraph());
if (edit)
inset->edit(cur, true);
// Now put co-text into inset
* paragraph and the inset allows setting layout
* FIXME: this does not work as expected when change tracking is on
* However, we do not really know what to do in this case.
+ * FIXME: figure out a good test in the environment case (see #12251).
*/
- if (cur.paragraph().empty() && !inset->forcePlainLayout()) {
+ if (cur.paragraph().layout().isCommand()
+ && cur.paragraph().empty()
+ && !inset->forcePlainLayout()) {
cur.paragraph().setPlainOrDefaultLayout(bparams.documentClass());
move_layout = true;
}
if (inset_text) {
Font const & font = inset->inheritFont()
? cur.bv().textMetrics(text).displayFont(cur.pit(), cur.pos())
- : buffer.params().getFont();
+ : bparams.getFont();
inset_text->setOuterFont(cur.bv(), font.fontInfo());
}
+ if (cmd.action() == LFUN_ARGUMENT_INSERT) {
+ InsetArgument * const ia = static_cast<InsetArgument *>(inset);
+ ia->init(cur.paragraph());
+ }
+
if (edit)
inset->edit(cur, true);
cur.clearSelection(); // bug 393
cur.finishUndo();
if (inset_text) {
+ if (resetfont) {
+ // Reset of font (not language) is requested.
+ // Used by InsetIndex (#11961).
+ Language const * lang = cur.getFont().language();
+ Font font(bparams.getFont().fontInfo(), lang);
+ cur.paragraph().resetFonts(font);
+ }
inset_text->fixParagraphsFont();
cur.pos() = 0;
cur.pit() = 0;
if (cur.selection())
cutSelection(cur, false);
else
- deleteWordForward(cur, cmd.getArg(0) == "force");
+ deleteWordForward(cur, cmd.getArg(0) != "confirm");
finishChange(cur, false);
break;
if (cur.selection())
cutSelection(cur, false);
else
- deleteWordBackward(cur, cmd.getArg(0) == "force");
+ deleteWordBackward(cur, cmd.getArg(0) != "confirm");
finishChange(cur, false);
break;
bool const cur_moved = cursorForward(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
- // we will probably be moving out the inset, so we should execute
- // the depm-mechanism, but only when the cursor has a place to
- // go outside this inset, i.e. in a slice above.
- if (cur.depth() > 1 && cur.pos() == cur.lastpos()
- && cur.pit() == cur.lastpit()) {
- // The cursor hasn't changed yet. To give the
- // DEPM the possibility of doing something we must
- // provide it with two different cursors.
- Cursor dummy = cur;
- dummy.pos() = dummy.pit() = 0;
- if (cur.bv().checkDepm(dummy, cur))
- cur.forceBufferUpdate();
- }
+ // we will be moving out the inset, so we should execute
+ // the depm-mechanism.
+ // The cursor hasn't changed yet. To give the DEPM the
+ // possibility of doing something we must provide it with
+ // two different cursors.
+ Cursor dummy = cur;
+ dummy.pos() = dummy.pit() = 0;
+ if (cur.bv().checkDepm(dummy, cur))
+ cur.forceBufferUpdate();
}
break;
}
bool const cur_moved = cursorBackward(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
- // we will probably be moving out the inset, so we should execute
- // the depm-mechanism, but only when the cursor has a place to
- // go outside this inset, i.e. in a slice above.
- if (cur.depth() > 1 && cur.pos() == 0 && cur.pit() == 0) {
- // The cursor hasn't changed yet. To give the
- // DEPM the possibility of doing something we must
- // provide it with two different cursors.
- Cursor dummy = cur;
- dummy.pos() = cur.lastpos();
- dummy.pit() = cur.lastpit();
- if (cur.bv().checkDepm(dummy, cur))
- cur.forceBufferUpdate();
- }
+ // we will be moving out the inset, so we should execute
+ // the depm-mechanism.
+ // The cursor hasn't changed yet. To give the DEPM the
+ // possibility of doing something we must provide it with
+ // two different cursors.
+ Cursor dummy = cur;
+ dummy.pos() = cur.lastpos();
+ dummy.pit() = cur.lastpit();
+ if (cur.bv().checkDepm(dummy, cur))
+ cur.forceBufferUpdate();
}
break;
}
needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
bool const cur_moved = cursorVisLeft(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
bool const cur_moved = cursorVisRight(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
bool const cur_moved = cursorVisRightOneWord(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
bool const cur_moved = cursorForwardOneWord(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
- // we will probably be moving out the inset, so we should execute
- // the depm-mechanism, but only when the cursor has a place to
- // go outside this inset, i.e. in a slice above.
- if (cur.depth() > 1 && cur.pos() == cur.lastpos()
- && cur.pit() == cur.lastpit()) {
- // The cursor hasn't changed yet. To give the
- // DEPM the possibility of doing something we must
- // provide it with two different cursors.
- Cursor dummy = cur;
- dummy.pos() = dummy.pit() = 0;
- if (cur.bv().checkDepm(dummy, cur))
- cur.forceBufferUpdate();
- }
+ // we will be moving out the inset, so we should execute
+ // the depm-mechanism.
+ // The cursor hasn't changed yet. To give the DEPM the
+ // possibility of doing something we must provide it with
+ // two different cursors.
+ Cursor dummy = cur;
+ dummy.pos() = dummy.pit() = 0;
+ if (cur.bv().checkDepm(dummy, cur))
+ cur.forceBufferUpdate();
}
break;
}
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
bool const cur_moved = cursorVisLeftOneWord(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
bool const cur_moved = cursorBackwardOneWord(cur);
needsUpdate |= cur_moved;
- if (!cur_moved && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && cur.depth() > 1
+ && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
- // we will probably be moving out the inset, so we should execute
- // the depm-mechanism, but only when the cursor has a place to
- // go outside this inset, i.e. in a slice above.
- if (cur.depth() > 1 && cur.pos() == 0
- && cur.pit() == 0) {
- // The cursor hasn't changed yet. To give the
- // DEPM the possibility of doing something we must
- // provide it with two different cursors.
- Cursor dummy = cur;
- dummy.pos() = cur.lastpos();
- dummy.pit() = cur.lastpit();
- if (cur.bv().checkDepm(dummy, cur))
- cur.forceBufferUpdate();
- }
+ // we will be moving out the inset, so we should execute
+ // the depm-mechanism.
+ // The cursor hasn't changed yet. To give the DEPM the
+ // possibility of doing something we must provide it with
+ // two different cursors.
+ Cursor dummy = cur;
+ dummy.pos() = cur.lastpos();
+ dummy.pit() = cur.lastpit();
+ if (cur.bv().checkDepm(dummy, cur))
+ cur.forceBufferUpdate();
}
break;
}
if (cur.pos() == cur.paragraph().size())
// Par boundary, force full-screen update
singleParUpdate = false;
- else if (cmd.getArg(0) != "force" && cur.confirmDeletion()) {
+ else if (cmd.getArg(0) == "confirm" && cur.confirmDeletion()) {
cur.resetAnchor();
cur.selection(true);
cur.posForward();
// Par boundary, full-screen update
if (par_boundary)
singleParUpdate = false;
- else if (cmd.getArg(0) != "force" && cur.confirmDeletion(true)) {
+ else if (cmd.getArg(0) == "confirm" && cur.confirmDeletion(true)) {
cur.resetAnchor();
cur.selection(true);
cur.posBackward();
pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
else if (theClipboard().hasTextContents()) {
if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
- true, Clipboard::AnyTextType))
+ !cur.paragraph().parbreakIsNewline(),
+ Clipboard::AnyTextType))
tryGraphics = false;
}
if (tryGraphics && theClipboard().hasGraphicsContents())
bvcur.resetAnchor();
if (!bv->mouseSetCursor(cur, cmd.modifier() == ShiftModifier))
cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
- if (bvcur.wordSelection())
- selectWord(bvcur, WHOLE_WORD);
+ // FIXME: move this to mouseSetCursor?
+ if (bvcur.wordSelection() && bvcur.inTexted())
+ expandWordSel(bvcur);
break;
case mouse_button::button2:
// We continue with our existing selection or start a new one, so don't
// reset the anchor.
bvcur.setCursor(cur);
+ if (bvcur.wordSelection() && bvcur.inTexted())
+ expandWordSel(bvcur);
bvcur.selection(true);
bvcur.setCurrentFont();
if (cur.top() == old) {
case LFUN_BRANCH_INSERT:
case LFUN_PHANTOM_INSERT:
case LFUN_ERT_INSERT:
+ case LFUN_INDEXMACRO_INSERT:
case LFUN_LISTING_INSERT:
case LFUN_MARGINALNOTE_INSERT:
case LFUN_ARGUMENT_INSERT:
case LFUN_INDEX_INSERT:
case LFUN_PREVIEW_INSERT:
case LFUN_SCRIPT_INSERT:
- case LFUN_IPA_INSERT:
+ case LFUN_IPA_INSERT: {
+ // Indexes reset font formatting (#11961)
+ bool const resetfont = cmd.action() == LFUN_INDEX_INSERT;
// Open the inset, and move the current selection
// inside it.
- doInsertInset(cur, this, cmd, true, true);
+ doInsertInset(cur, this, cmd, true, true, resetfont);
cur.posForward();
cur.setCurrentFont();
// Some insets are numbered, others are shown in the outline pane so
// let's update the labels and the toc backend.
cur.forceBufferUpdate();
break;
+ }
case LFUN_FLEX_INSERT: {
// Open the inset, and move the current selection
// leave this now in order to insert the next one.
if (inautoarg) {
cur.leaveInset(cur.inset());
+ cur.setCurrentFont();
cur.posForward();
if (arg.insertonnewline && cur.pos() > 0) {
FuncRequest cmd2(LFUN_PARAGRAPH_BREAK);
string const lang_arg = cmd.getArg(0);
bool const reset = (lang_arg.empty() || lang_arg == "reset");
Language const * lang =
- reset ? reset_language
+ reset ? cur.bv().buffer().params().language
: languages.getLanguage(lang_arg);
// we allow reset_language, which is 0, but only if it
// was requested via empty or "reset" arg.
selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
Font font(ignore_font, lang);
toggleAndShow(cur, this, font, toggle);
- // We need a buffer update if we change the language
- // of an info inset
- if (cur.insetInSelection(INFO_CODE))
- cur.forceBufferUpdate();
break;
}
freeFonts.push(make_pair(props, font));
toggleall = toggle;
toggleAndShow(cur, this, font, toggleall);
- // We need a buffer update if we change the language
- // of an info inset
- if (cur.insetInSelection(INFO_CODE))
- cur.forceBufferUpdate();
cur.message(bformat(_("Text properties applied: %1$s"), props));
} else
LYXERR0("Invalid argument of textstyle-update");
cur.recordUndoBufferParams();
bv->buffer().params().spellignore().push_back(wl);
cur.recordUndo();
- // trigger re-check
- WordLangTuple wl;
- docstring_list suggestions;
- Paragraph const & par = cur.paragraph();
- pos_type from = cur.pos();
- pos_type to = from;
- par.spellCheck(from, to, wl, suggestions, true, true);
+ // trigger re-check of whole buffer
+ bv->buffer().requestSpellcheck();
}
break;
}
cur.recordUndoBufferParams();
bv->buffer().params().spellignore().erase(it);
cur.recordUndo();
- // trigger re-check
- WordLangTuple wl;
- docstring_list suggestions;
- Paragraph const & par = cur.paragraph();
- pos_type from = cur.pos();
- pos_type to = from;
- par.spellCheck(from, to, wl, suggestions, true, true);
+ // trigger re-check of whole buffer
+ bv->buffer().requestSpellcheck();
}
break;
}
code = BRANCH_CODE;
else if (cmd.argument() == "citation")
code = CITE_CODE;
+ else if (cmd.argument() == "counter")
+ code = COUNTER_CODE;
else if (cmd.argument() == "ert")
code = ERT_CODE;
else if (cmd.argument() == "external")
break;
case LFUN_FLEX_INSERT: {
code = FLEX_CODE;
- string s = cmd.getArg(0);
- InsetLayout il =
- cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
- if (il.lyxtype() != InsetLyXType::CHARSTYLE &&
- il.lyxtype() != InsetLyXType::CUSTOM &&
- il.lyxtype ()!= InsetLyXType::STANDARD)
+ docstring s = from_utf8(cmd.getArg(0));
+ // Prepend "Flex:" prefix if not there
+ if (!prefixIs(s, from_ascii("Flex:")))
+ s = from_ascii("Flex:") + s;
+ if (!cur.buffer()->params().documentClass().hasInsetLayout(s))
enable = false;
- break;
+ else {
+ InsetLyXType ilt =
+ cur.buffer()->params().documentClass().insetLayout(s).lyxtype();
+ if (ilt != InsetLyXType::CHARSTYLE
+ && ilt != InsetLyXType::CUSTOM
+ && ilt != InsetLyXType::STANDARD)
+ enable = false;
}
+ break;
+ }
case LFUN_BOX_INSERT:
code = BOX_CODE;
break;
}
code = HYPERLINK_CODE;
break;
+ case LFUN_INDEXMACRO_INSERT: {
+ string const arg = cmd.getArg(0);
+ if (arg == "sortkey")
+ code = INDEXMACRO_SORTKEY_CODE;
+ else
+ code = INDEXMACRO_CODE;
+ break;
+ }
case LFUN_IPAMACRO_INSERT: {
string const arg = cmd.getArg(0);
if (arg == "deco")
break;
case LFUN_PRIMARY_SELECTION_PASTE:
+ status.setUnknown(!theSelection().supported());
enable = cur.selection() || !theSelection().empty();
break;
docstring const req_layout = ignoreautonests ? from_utf8(cmd.getArg(0)) : cmd.argument();
docstring const layout = resolveLayout(req_layout, cur);
- enable = !owner_->forcePlainLayout() && !layout.empty();
- status.setOnOff(!owner_->forcePlainLayout() && isAlreadyLayout(layout, cur));
+ // FIXME: make this work in multicell selection case
+ enable = !owner_->forcePlainLayout() && !layout.empty() && !cur.selIsMultiCell();
+ status.setOnOff(!owner_->forcePlainLayout() && !cur.selIsMultiCell()
+ && isAlreadyLayout(layout, cur));
break;
}