using cap::pasteFromStack;
using cap::pasteClipboard;
using cap::replaceSelection;
-using cap::saveSelection;
using support::isStrUnsignedInt;
using support::token;
Font freefont(Font::ALL_IGNORE);
bool toggleall = false;
-
void toggleAndShow(Cursor & cur, Text * text,
Font const & font, bool toggleall = true)
{
if (font.language() != ignore_language ||
font.number() != Font::IGNORE) {
Paragraph & par = cur.paragraph();
- text->bidi.computeTables(par, cur.buffer(), cur.textRow());
- if (cur.boundary() !=
- text->bidi.isBoundary(cur.buffer(), par,
- cur.pos(),
- text->real_current_font))
+ if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
+ cur.pos(), text->real_current_font))
text->setCursor(cur, cur.pit(), cur.pos(),
- false, !cur.boundary());
+ false, !cur.boundary());
}
}
{
if (selecting || cur.mark())
cur.setSelection();
- saveSelection(cur);
- cur.bv().switchKeyMap();
}
}
+bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
+{
+ if (!lyxrc.rtl_support && !sl.text())
+ return false;
+
+ int correction = 0;
+ if (boundary && sl.pos() > 0)
+ correction = -1;
+
+ Paragraph const & par = getPar(sl.pit());
+ return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
+}
+
+
+bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
+ pos_type pos) const
+{
+ if (!lyxrc.rtl_support)
+ return false;
+
+ // no RTL boundary at line start
+ if (pos == 0)
+ return false;
+
+ bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
+ bool right;
+ if (pos == par.size())
+ right = par.isRightToLeftPar(buffer.params());
+ else
+ right = getFont(buffer, par, pos).isVisibleRightToLeft();
+ return left != right;
+}
+
+
+bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
+ pos_type pos, Font const & font) const
+{
+ if (!lyxrc.rtl_support)
+ return false;
+
+ bool left = font.isVisibleRightToLeft();
+ bool right;
+ if (pos == par.size())
+ right = par.isRightToLeftPar(buffer.params());
+ else
+ right = getFont(buffer, par, pos).isVisibleRightToLeft();
+ return left != right;
+}
+
+
void Text::dispatch(Cursor & cur, FuncRequest & cmd)
{
LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
}
case LFUN_WORD_DELETE_FORWARD:
- cur.clearSelection();
- deleteWordForward(cur);
+ if (cur.selection()) {
+ cutSelection(cur, true, false);
+ } else
+ deleteWordForward(cur);
finishChange(cur, false);
break;
case LFUN_WORD_DELETE_BACKWARD:
- cur.clearSelection();
- deleteWordBackward(cur);
+ if (cur.selection()) {
+ cutSelection(cur, true, false);
+ } else
+ deleteWordBackward(cur);
finishChange(cur, false);
break;
case LFUN_LINE_DELETE:
- cur.clearSelection();
- deleteLineForward(cur);
+ if (cur.selection()) {
+ cutSelection(cur, true, false);
+ } else
+ deleteLineForward(cur);
finishChange(cur, false);
break;
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_CHAR_BACKWARD:
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
- if (cur.selection())
- saveSelection(cur);
break;
- case LFUN_UP:
case LFUN_UP_SELECT:
- //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
- needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
- needsUpdate |= cur.upDownInText(true);
-
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary)
- cur.undispatched();
- if (cur.selection())
- saveSelection(cur);
- break;
-
- case LFUN_DOWN:
case LFUN_DOWN_SELECT:
- //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
- needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
- needsUpdate |= cur.upDownInText(false);
-
- if (!needsUpdate && oldTopSlice == cur.top() &&
- cur.boundary() == oldBoundary)
+ case LFUN_UP:
+ case LFUN_DOWN: {
+ // stop/start the selection
+ bool select = cmd.action == LFUN_DOWN_SELECT ||
+ cmd.action == LFUN_UP_SELECT;
+ cur.selHandle(select);
+
+ // move cursor up/down
+ bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
+ bool const successful = cur.upDownInText(up, needsUpdate);
+ if (successful) {
+ // notify insets which were left and get their update flags
+ notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
+ cur.fixIfBroken();
+
+ // redraw if you leave mathed (for the decorations)
+ needsUpdate |= cur.beforeDispatchCursor().inMathed();
+ } else
cur.undispatched();
- if (cur.selection())
- saveSelection(cur);
+
break;
+ }
case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_UP_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
needsUpdate |= cursorUpParagraph(cur);
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_PARAGRAPH_DOWN:
case LFUN_PARAGRAPH_DOWN_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
needsUpdate |= cursorDownParagraph(cur);
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_SCREEN_UP:
else {
cursorPrevious(cur);
}
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_SCREEN_DOWN:
else {
cursorNext(cur);
}
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_LINE_BEGIN:
case LFUN_LINE_END_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
needsUpdate |= cursorEnd(cur);
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_WORD_FORWARD:
needsUpdate |= cursorLeftOneWord(cur);
else
needsUpdate |= cursorRightOneWord(cur);
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_WORD_BACKWARD:
needsUpdate |= cursorRightOneWord(cur);
else
needsUpdate |= cursorLeftOneWord(cur);
- if (cur.selection())
- saveSelection(cur);
break;
case LFUN_WORD_SELECT: {
cutSelection(cur, true, false);
singleParUpdate = false;
}
- bv->switchKeyMap();
break;
case LFUN_DELETE_BACKWARD_SKIP:
cap::replaceSelection(cur);
breakParagraph(cur, 0);
cur.resetAnchor();
- bv->switchKeyMap();
break;
case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
cap::replaceSelection(cur);
breakParagraph(cur, 1);
cur.resetAnchor();
- bv->switchKeyMap();
break;
case LFUN_BREAK_PARAGRAPH_SKIP: {
else
breakParagraph(cur, 0);
cur.resetAnchor();
- bv->switchKeyMap();
break;
}
}
bv->buffer()->errors("Paste");
cur.clearSelection(); // bug 393
- bv->switchKeyMap();
finishUndo();
break;
}
if (change_layout) {
- current_layout = layout;
setLayout(cur, layout);
// inform the GUI that the layout has changed.
bv->layoutChanged(layout);
- bv->switchKeyMap();
}
break;
}
docstring hexstring = cmd.argument();
if (lyx::support::isHex(hexstring)) {
char_type c = lyx::support::hexToInt(hexstring);
- if (c > 32 && c < 0x10ffff) {
+ if (c >= 32 && c < 0x10ffff) {
lyxerr << "Inserting c: " << c << endl;
docstring s = docstring(1, c);
lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
cursorEnd(cur);
cur.setSelection();
bv->cursor() = cur;
- saveSelection(cur);
}
break;
paste_internally = true;
}
- // we have to update after dePM triggered
- bool update = bv->mouseSetCursor(cur);
-
// Insert primary selection with middle mouse
// if there is a local selection in the current buffer,
// insert this
cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
bv->buffer()->errors("Paste");
cur.clearSelection(); // bug 393
- bv->switchKeyMap();
+ bv->buffer()->markDirty();
finishUndo();
- } else
+ } else {
+ bv->mouseSetCursor(cur);
lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
+ }
}
+ // we have to update after dePM triggered
+ bool update = bv->mouseSetCursor(cur);
+
if (!update && cmd.button() == mouse_button::button1) {
needsUpdate = false;
cur.noUpdate();
// but bvcur is current mouse position
Cursor & bvcur = cur.bv().cursor();
bvcur.selection() = true;
- saveSelection(bvcur);
}
needsUpdate = false;
cur.noUpdate();
}
- bv->switchKeyMap();
break;
}
// "auto_region_delete", which defaults to
// true (on).
- if (lyxrc.auto_region_delete)
- if (cur.selection())
- cutSelection(cur, false, false);
+ if (lyxrc.auto_region_delete && cur.selection()) {
+ cutSelection(cur, false, false);
+ // When change tracking is set to off, the metrics update
+ // mechanism correctly detects if a full update is needed or not.
+ // This detection fails when a selection spans multiple rows and
+ // change tracking is enabled because the paragraph metrics stays
+ // the same. In this case, we force the full update:
+ // (see http://bugzilla.lyx.org/show_bug.cgi?id=3992)
+ if (cur.buffer().params().trackChanges)
+ cur.updateFlags(Update::Force);
+ }
cur.clearSelection();
Font const old_font = real_current_font;
docstring::const_iterator cit = cmd.argument().begin();
docstring::const_iterator end = cmd.argument().end();
for (; cit != end; ++cit)
- bv->getIntl().getTransManager().
- translateAndInsert(*cit, this, cur);
+ bv->translateAndInsert(*cit, this, cur);
cur.resetAnchor();
moveCursor(cur, false);
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM: {
cur.insert(new InsetMathHull(hullSimple));
- cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
+ checkAndActivateInset(cur, true);
BOOST_ASSERT(cur.inMathed());
cur.dispatch(cmd);
break;
Font font(Font::ALL_IGNORE);
font.setLanguage(lang);
toggleAndShow(cur, this, font);
- bv->switchKeyMap();
break;
}
theLyXFunc().handleKeyFunc(cmd.action);
if (!cmd.argument().empty())
// FIXME: Are all these characters encoded in one byte in utf8?
- bv->getIntl().getTransManager()
- .translateAndInsert(cmd.argument()[0], this, cur);
+ bv->translateAndInsert(cmd.argument()[0], this, cur);
break;
case LFUN_FLOAT_LIST: {
case LFUN_ESCAPE:
if (cur.selection()) {
cur.selection() = false;
- saveSelection(cur);
} else {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
case LFUN_MATH_MATRIX:
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM:
+ case LFUN_MATH_INSERT:
case LFUN_MATH_SUBSCRIPT:
case LFUN_MATH_SUPERSCRIPT:
case LFUN_FONT_DEFAULT: