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());
}
}
void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
{
+ recordUndo(cur);
cap::replaceSelection(cur);
cur.insert(new InsetSpecialChar(kind));
cur.posRight();
}
+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;
std::swap(pars_[pit], pars_[pit + 1]);
ParIterator begin(cur);
- // begin.pos() (== cur.pos()) may point beyond the end of the
+ // begin.pos() (== cur.pos()) may point beyond the end of the
// paragraph referenced by begin. This would cause a crash
// in updateLabels()
begin.pos() = 0;
std::swap(pars_[pit], pars_[pit - 1]);
ParIterator end = ParIterator(cur);
- // end.pos() (== cur.pos()) may point beyond the end of the
+ // end.pos() (== cur.pos()) may point beyond the end of the
// paragraph referenced by end. This would cause a crash
// in boost::next()
end.pos() = 0;
//lyxerr << BOOST_CURRENT_FUNCTION
// << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
- if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+ if (reverseDirectionNeeded(cur))
needsUpdate |= cursorLeft(cur);
else
needsUpdate |= cursorRight(cur);
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
- }
- if (cur.selection())
+ } else if (cur.selection())
saveSelection(cur);
break;
case LFUN_CHAR_BACKWARD_SELECT:
//lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
- if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+ if (reverseDirectionNeeded(cur))
needsUpdate |= cursorRight(cur);
else
needsUpdate |= cursorLeft(cur);
break;
case LFUN_UP:
- case LFUN_UP_SELECT:
+ case LFUN_UP_SELECT: {
//lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
-
- needsUpdate |= cursorUp(cur);
-
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ bool const successful = cur.upDownInText(true, needsUpdate);
+ if (!successful)
cur.undispatched();
- cmd = FuncRequest(LFUN_FINISHED_UP);
- }
if (cur.selection())
saveSelection(cur);
break;
+ }
case LFUN_DOWN:
- case LFUN_DOWN_SELECT:
+ case LFUN_DOWN_SELECT: {
//lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
- needsUpdate |= cursorDown(cur);
-
- if (!needsUpdate && oldTopSlice == cur.top() &&
- cur.boundary() == oldBoundary)
- {
+ bool const successful = cur.upDownInText(false, needsUpdate);
+ if (!successful)
cur.undispatched();
- cmd = FuncRequest(LFUN_FINISHED_DOWN);
- }
if (cur.selection())
saveSelection(cur);
break;
+ }
case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_UP_SELECT:
case LFUN_SCREEN_UP:
case LFUN_SCREEN_UP_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
- if (cur.pit() == 0 && cur.textRow().pos() == 0) {
+ if (cur.pit() == 0 && cur.textRow().pos() == 0)
cur.undispatched();
- cmd = FuncRequest(LFUN_FINISHED_UP);
- } else {
+ else {
cursorPrevious(cur);
}
if (cur.selection())
case LFUN_SCREEN_DOWN_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
if (cur.pit() == cur.lastpit()
- && cur.textRow().endpos() == cur.lastpos()) {
+ && cur.textRow().endpos() == cur.lastpos())
cur.undispatched();
- cmd = FuncRequest(LFUN_FINISHED_DOWN);
- } else {
+ else {
cursorNext(cur);
}
if (cur.selection())
case LFUN_WORD_FORWARD:
case LFUN_WORD_FORWARD_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
- if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+ if (reverseDirectionNeeded(cur))
needsUpdate |= cursorLeftOneWord(cur);
else
needsUpdate |= cursorRightOneWord(cur);
case LFUN_WORD_BACKWARD:
case LFUN_WORD_BACKWARD_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
- if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+ if (reverseDirectionNeeded(cur))
needsUpdate |= cursorRightOneWord(cur);
else
needsUpdate |= cursorLeftOneWord(cur);
// FIXME (Abdel 01/02/2006):
// What follows would be a partial fix for bug 2154:
// http://bugzilla.lyx.org/show_bug.cgi?id=2154
- // This automatically put the label inset _after_ a
+ // This automatically put the label inset _after_ a
// numbered section. It should be possible to extend the mechanism
// to any kind of LateX environement.
// The correct way to fix that bug would be at LateX generation.
break;
case LFUN_CHARS_TRANSPOSE:
- charsTranspose(cur);
+ charsTranspose(cur);
break;
case LFUN_PASTE:
case LFUN_CLIPBOARD_PASTE:
cur.clearSelection();
pasteClipboard(cur, bv->buffer()->errorList("Paste"),
- cmd.argument() == "paragraph");
+ cmd.argument() == "paragraph");
bv->buffer()->errors("Paste");
break;
case LFUN_PRIMARY_SELECTION_PASTE:
pasteString(cur, theSelection().get(),
- cmd.argument() == "paragraph");
+ cmd.argument() == "paragraph");
break;
case LFUN_UNICODE_INSERT: {
}
break;
}
-
+
case LFUN_QUOTE_INSERT: {
Paragraph & par = cur.paragraph();
pos_type pos = cur.pos();
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
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();
int const y = std::max(0, std::min(wh - 1, cmd.y));
setCursorFromCoordinates(cur, cmd.x, y);
- cur.x_target() = cmd.x;
+ cur.setTargetX(cmd.x);
if (cmd.y >= wh)
lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
else if (cmd.y < 0)
pars.push_back(Paragraph());
pars.back().setInsetOwner(pars[0].inInset());
pars.back().layout(tclass.defaultLayout());
-
+
}
// reposition the cursor to the caption
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;
}
case LFUN_FINISHED_LEFT:
LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
+ if (reverseDirectionNeeded(cur))
+ ++cur.pos();
break;
case LFUN_FINISHED_RIGHT:
LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
- ++cur.pos();
- break;
-
- case LFUN_FINISHED_UP:
- LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_UP:\n" << cur << endl;
- cursorUp(cur);
- break;
-
- case LFUN_FINISHED_DOWN:
- LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
- cursorDown(cur);
+ if (!reverseDirectionNeeded(cur))
+ ++cur.pos();
break;
case LFUN_LAYOUT_PARAGRAPH: {
// update flag treatment.
if (singleParUpdate) {
// Inserting characters does not change par height
- ParagraphMetrics const & pms
+ ParagraphMetrics const & pms
= cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
if (pms.dim().height()
== olddim.height()) {
//
//if (cur.result().update() != Update::FitCursor)
// cur.noUpdate();
- //
+ //
// But some LFUNs do not set Update::FitCursor when needed, so we
// do it for all. This is not very harmfull as FitCursor will provoke
// a full redraw only if needed but still, a proper review of all LFUN
return true;
case LFUN_BIBITEM_INSERT:
- enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
+ enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
+ && cur.pos() == 0);
break;
case LFUN_DIALOG_SHOW_NEW_INSET: