#include "gettext.h"
#include "intl.h"
#include "language.h"
+#include "LyXAction.h"
#include "lyxfunc.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
-#include "support/tostr.h"
+#include "support/convert.h"
#include "mathed/math_hullinset.h"
#include "mathed/math_macrotemplate.h"
using lyx::cap::replaceSelection;
using lyx::support::isStrUnsignedInt;
-using lyx::support::strToUnsignedInt;
-using lyx::support::atoi;
using lyx::support::token;
using std::endl;
}
-void LyXText::cursorPrevious(LCursor & cur)
+bool LyXText::cursorPrevious(LCursor & cur)
{
pos_type cpos = cur.pos();
lyx::pit_type cpar = cur.pit();
int x = cur.x_target();
setCursorFromCoordinates(cur, x, 0);
- cursorUp(cur);
+ bool updated = cursorUp(cur);
if (cpar == cur.pit() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the previous row instead.
- cursorUp(cur);
+ updated |= cursorUp(cur);
}
cur.bv().updateScrollbar();
finishUndo();
+ return updated;
}
-void LyXText::cursorNext(LCursor & cur)
+bool LyXText::cursorNext(LCursor & cur)
{
pos_type cpos = cur.pos();
lyx::pit_type cpar = cur.pit();
int x = cur.x_target();
setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
- cursorDown(cur);
+ bool updated = cursorDown(cur);
if (cpar == cur.pit() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the next row instead.
- cursorDown(cur);
+ updated |= cursorDown(cur);
}
cur.bv().updateScrollbar();
finishUndo();
+ return updated;
}
void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
{
lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
- //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
+ lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
BOOST_ASSERT(cur.text() == this);
BufferView * bv = &cur.bv();
- CursorSlice sl = cur.top();
+ CursorSlice oldTopSlice = cur.top();
bool sel = cur.selection();
- bool moving = false;
+ bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
switch (cmd.action) {
break;
case LFUN_WORDRIGHT:
- moving = true;
if (!cur.mark())
cur.clearSelection();
if (isRTL(cur.paragraph()))
- cursorLeftOneWord(cur);
+ needsUpdate = cursorLeftOneWord(cur);
else
- cursorRightOneWord(cur);
+ needsUpdate = cursorRightOneWord(cur);
finishChange(cur, false);
break;
case LFUN_WORDLEFT:
- moving = true;
if (!cur.mark())
cur.clearSelection();
if (isRTL(cur.paragraph()))
- cursorRightOneWord(cur);
+ needsUpdate = cursorRightOneWord(cur);
else
- cursorLeftOneWord(cur);
+ needsUpdate = cursorLeftOneWord(cur);
finishChange(cur, false);
break;
case LFUN_BEGINNINGBUF:
- if (cur.size() == 1) {
+ if (cur.depth() == 1) {
if (!cur.mark())
cur.clearSelection();
cursorTop(cur);
break;
case LFUN_BEGINNINGBUFSEL:
- if (cur.size() == 1) {
+ if (cur.depth() == 1) {
if (!cur.selection())
cur.resetAnchor();
cursorTop(cur);
break;
case LFUN_ENDBUF:
- if (cur.size() == 1) {
+ if (cur.depth() == 1) {
if (!cur.mark())
cur.clearSelection();
cursorBottom(cur);
cur.undispatched();
}
break;
-
+
case LFUN_ENDBUFSEL:
- if (cur.size() == 1) {
+ if (cur.depth() == 1) {
if (!cur.selection())
cur.resetAnchor();
cursorBottom(cur);
break;
case LFUN_RIGHT:
- moving = true;
case LFUN_RIGHTSEL:
- //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
+ lyxerr << BOOST_CURRENT_FUNCTION
+ << " LFUN_RIGHT[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_RIGHTSEL);
if (isRTL(cur.paragraph()))
- cursorLeft(cur);
+ needsUpdate = cursorLeft(cur);
else
- cursorRight(cur);
- if (sl == cur.top()) {
+ needsUpdate = cursorRight(cur);
+ if (!needsUpdate && oldTopSlice == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
break;
case LFUN_LEFT:
- moving = true;
case LFUN_LEFTSEL:
//lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_LEFTSEL);
if (isRTL(cur.paragraph()))
- cursorRight(cur);
+ needsUpdate = cursorRight(cur);
else
- cursorLeft(cur);
- if (sl == cur.top()) {
+ needsUpdate = cursorLeft(cur);
+ if (oldTopSlice == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
break;
case LFUN_UP:
- moving = true;
case LFUN_UPSEL:
update(cur);
//lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_UPSEL);
- cursorUp(cur);
- if (sl == cur.top()) {
+ needsUpdate = cursorUp(cur);
+ if (oldTopSlice == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_UP);
}
break;
case LFUN_DOWN:
- moving = true;
case LFUN_DOWNSEL:
update(cur);
//lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_DOWNSEL);
- cursorDown(cur);
- if (sl == cur.top()) {
+ needsUpdate = cursorDown(cur);
+ if (oldTopSlice == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_DOWN);
}
break;
+ case LFUN_UP_PARAGRAPH:
+ if (!cur.mark())
+ cur.clearSelection();
+ needsUpdate = cursorUpParagraph(cur);
+ finishChange(cur, false);
+ break;
+
case LFUN_UP_PARAGRAPHSEL:
if (!cur.selection())
cur.resetAnchor();
finishChange(cur, true);
break;
+ case LFUN_DOWN_PARAGRAPH:
+ if (!cur.mark())
+ cur.clearSelection();
+ needsUpdate = cursorDownParagraph(cur);
+ finishChange(cur, false);
+ break;
+
case LFUN_DOWN_PARAGRAPHSEL:
if (!cur.selection())
cur.resetAnchor();
break;
}
- case LFUN_UP_PARAGRAPH:
- moving = true;
- if (!cur.mark())
- cur.clearSelection();
- cursorUpParagraph(cur);
- finishChange(cur, false);
- break;
-
- case LFUN_DOWN_PARAGRAPH:
- moving = true;
- if (!cur.mark())
- cur.clearSelection();
- cursorDownParagraph(cur);
- finishChange(cur, false);
- break;
-
case LFUN_PRIOR:
update(cur);
- moving = true;
if (!cur.mark())
cur.clearSelection();
finishChange(cur, false);
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_UP);
} else {
- cursorPrevious(cur);
+ needsUpdate = cursorPrevious(cur);
}
break;
case LFUN_NEXT:
update(cur);
- moving = true;
if (!cur.mark())
cur.clearSelection();
finishChange(cur, false);
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_DOWN);
} else {
- cursorNext(cur);
+ needsUpdate = cursorNext(cur);
}
break;
lyxerr << _("Unknown spacing argument: ")
<< cmd.argument << endl;
}
- if (cur_spacing != new_spacing || cur_value != new_value)
+ if (cur_spacing != new_spacing || cur_value != new_value)
par.params().spacing(Spacing(new_spacing, new_value));
break;
}
#warning FIXME Check if the arg is in the domain of available selections.
#endif
if (isStrUnsignedInt(cmd.argument))
- pasteSelection(cur, strToUnsignedInt(cmd.argument));
+ pasteSelection(cur, convert<unsigned int>(cmd.argument));
else
pasteSelection(cur, 0);
cur.clearSelection(); // bug 393
break;
case LFUN_GETXY:
- cur.message(tostr(cursorX(cur.top())) + ' '
- + tostr(cursorY(cur.top())));
+ cur.message(convert<string>(cursorX(cur.top())) + ' '
+ + convert<string>(cursorY(cur.top())));
break;
case LFUN_SETXY: {
int const wh = bv->workHeight();
int const y = std::max(0, std::min(wh - 1, cmd.y));
-
+
setCursorFromCoordinates(cur, cmd.x, y);
cur.x_target() = cmd.x;
if (cmd.y >= wh)
bvcur.selection() = true;
lyxerr << "MOTION: " << bv->cursor() << endl;
}
-
+
} else
cur.undispatched();
break;
else {
string s = cmd.argument;
string const s1 = token(s, ' ', 1);
- int const nargs = s1.empty() ? 0 : atoi(s1);
+ int const nargs = s1.empty() ? 0 : convert<int>(s1);
string const s2 = token(s, ' ', 2);
string const type = s2.empty() ? "newcommand" : s2;
cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
//cur.nextInset()->edit(cur, true);
}
break;
-
+
// passthrough hat and underscore outside mathed:
case LFUN_SUBSCRIPT:
mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
InsetBase & inset = cur.inset();
bool const accept = !inset.forceDefaultParagraphs(&inset);
- data = "update " + tostr(accept) + '\n' + data;
+ data = "update " + convert<string>(accept) + '\n' + data;
bv->owner()->getDialogs().update("paragraph", data);
break;
}
break;
default:
+ lyxerr << BOOST_CURRENT_FUNCTION
+ << " Not DISPATCHED by LyXText" << endl;
cur.undispatched();
break;
}
- // avoid to update when navigating
- if (moving
- && &sl.inset() == &cur.inset()
- && sl.idx() == cur.idx()
- && sel == false
- && cur.selection() == false)
+ if (!needsUpdate
+ && &oldTopSlice.inset() == &cur.inset()
+ && oldTopSlice.idx() == cur.idx()
+ && !sel
+ && !cur.selection())
cur.noUpdate();
+ else
+ cur.needsUpdate();
}