mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-03 14:13:58 +00:00
some de-mathed-ification
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8459 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d891a896f4
commit
2c535ef9e9
94
src/cursor.C
94
src/cursor.C
@ -921,45 +921,6 @@ bool LCursor::inNucleus()
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::left()
|
||||
{
|
||||
autocorrect() = false;
|
||||
clearTargetX();
|
||||
if (inMacroMode()) {
|
||||
macroModeClose();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pos() != 0 && openable(prevAtom())) {
|
||||
posLeft();
|
||||
push(nextAtom().nucleus());
|
||||
inset()->idxLast(*this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return posLeft() || idxLeft() || popLeft() || selection();
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::right()
|
||||
{
|
||||
autocorrect() = false;
|
||||
clearTargetX();
|
||||
if (inMacroMode()) {
|
||||
macroModeClose();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pos() != lastpos() && openable(nextAtom())) {
|
||||
pushLeft(nextAtom().nucleus());
|
||||
inset()->idxFirst(*this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return posRight() || idxRight() || popRight() || selection();
|
||||
}
|
||||
|
||||
|
||||
bool positionable(CursorBase const & cursor, CursorBase const & anchor)
|
||||
{
|
||||
// avoid deeper nested insets when selecting
|
||||
@ -990,28 +951,6 @@ void LCursor::setScreenPos(int x, int y)
|
||||
|
||||
|
||||
|
||||
bool LCursor::home()
|
||||
{
|
||||
autocorrect() = false;
|
||||
macroModeClose();
|
||||
if (!inset()->idxHome(*this))
|
||||
return popLeft();
|
||||
clearTargetX();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::end()
|
||||
{
|
||||
autocorrect() = false;
|
||||
macroModeClose();
|
||||
if (!inset()->idxEnd(*this))
|
||||
return popRight();
|
||||
clearTargetX();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void LCursor::plainErase()
|
||||
{
|
||||
cell().erase(pos());
|
||||
@ -1143,7 +1082,7 @@ bool LCursor::backspace()
|
||||
// let's require two backspaces for 'big stuff' and
|
||||
// highlight on the first
|
||||
selection() = true;
|
||||
left();
|
||||
--pos();
|
||||
} else {
|
||||
--pos();
|
||||
plainErase();
|
||||
@ -1182,7 +1121,7 @@ bool LCursor::erase()
|
||||
|
||||
if (pos() != lastpos() && inset()->nargs() > 0) {
|
||||
selection() = true;
|
||||
right();
|
||||
++pos();
|
||||
} else {
|
||||
plainErase();
|
||||
}
|
||||
@ -1232,8 +1171,8 @@ void LCursor::macroModeClose()
|
||||
string const name = s.substr(1);
|
||||
|
||||
// prevent entering of recursive macros
|
||||
if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
|
||||
&& formula()->getInsetName() == name)
|
||||
InsetBase const * macro = innerInsetOfType(InsetBase::MATHMACRO_CODE);
|
||||
if (macro && macro->getInsetName() == name)
|
||||
lyxerr << "can't enter recursive macro" << endl;
|
||||
|
||||
niceInsert(createMathInset(name));
|
||||
@ -1544,27 +1483,6 @@ void LCursor::bruteFind2(int x, int y)
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::idxLineLast()
|
||||
{
|
||||
idx() -= idx() % ncols();
|
||||
idx() += ncols() - 1;
|
||||
pos() = lastpos();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::idxLeft()
|
||||
{
|
||||
return inset()->idxLeft(*this);
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::idxRight()
|
||||
{
|
||||
return inset()->idxRight(*this);
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::script(bool up)
|
||||
{
|
||||
// Hack to get \\^ and \\_ working
|
||||
@ -1849,13 +1767,13 @@ void LCursor::handleFont(string const & font)
|
||||
|
||||
bool LCursor::inMathed() const
|
||||
{
|
||||
return formula();
|
||||
return current_ && inset()->inMathed();
|
||||
}
|
||||
|
||||
|
||||
bool LCursor::inTexted() const
|
||||
{
|
||||
return !formula();
|
||||
return !inMathed();
|
||||
}
|
||||
|
||||
|
||||
|
21
src/cursor.h
21
src/cursor.h
@ -190,8 +190,12 @@ public:
|
||||
size_t nrows() const;
|
||||
/// return the grid row of the current cell
|
||||
row_type row() const;
|
||||
/// return the grid row of the current cell
|
||||
/// return the last row of the current grid
|
||||
row_type lastrow() const { return nrows() - 1; }
|
||||
/// return the grid column of the current cell
|
||||
col_type col() const;
|
||||
/// return the last column of the current grid
|
||||
col_type lastcol() const { return ncols() - 1; }
|
||||
/// the inset just behind the cursor
|
||||
InsetBase * nextInset();
|
||||
/// the inset just in front of the cursor
|
||||
@ -362,14 +366,6 @@ public:
|
||||
bool erase();
|
||||
/// return false for empty math insets
|
||||
bool backspace();
|
||||
/// called for LFUN_HOME etc
|
||||
bool home();
|
||||
/// called for LFUN_END etc
|
||||
bool end();
|
||||
/// called for LFUN_RIGHT and LFUN_RIGHTSEL
|
||||
bool right();
|
||||
/// called for LFUN_LEFT etc
|
||||
bool left();
|
||||
/// called for LFUN_UP etc
|
||||
bool up();
|
||||
/// called for LFUN_DOWN etc
|
||||
@ -451,12 +447,6 @@ public:
|
||||
std::string getPossibleLabel();
|
||||
|
||||
private:
|
||||
/// moves cursor index one cell to the left
|
||||
bool idxLeft();
|
||||
/// moves cursor index one cell to the right
|
||||
bool idxRight();
|
||||
/// moves cursor to end of last cell of current line
|
||||
bool idxLineLast();
|
||||
/// moves position somehow up or down
|
||||
bool goUpDown(bool up);
|
||||
/// moves position closest to (x, y) in given box
|
||||
@ -470,6 +460,7 @@ private:
|
||||
std::string macroName();
|
||||
/// where in the curent cell does the macro name start?
|
||||
int macroNamePos();
|
||||
public:
|
||||
/// can we enter the inset?
|
||||
bool openable(MathAtom const &) const;
|
||||
};
|
||||
|
@ -67,6 +67,8 @@ public:
|
||||
virtual MathInset * asMathInset() { return 0; }
|
||||
/// identification as non-math inset
|
||||
virtual UpdatableInset * asUpdatableInset() { return 0; }
|
||||
/// true for 'math' math inset, but not for e.g. mbox
|
||||
virtual bool inMathed() const { return false; }
|
||||
|
||||
// the real dispatcher
|
||||
void dispatch(LCursor & cur, FuncRequest const & cmd);
|
||||
@ -127,11 +129,6 @@ public:
|
||||
/// Target pos when we enter the inset from the right by pressing "Left"
|
||||
virtual bool idxLast(LCursor &) const { return false; }
|
||||
|
||||
/// Where should we go if we press home?
|
||||
virtual bool idxHome(LCursor &) const { return false; }
|
||||
/// Where should we go if we press end?
|
||||
virtual bool idxEnd(LCursor &) const { return false; }
|
||||
|
||||
/// Delete a cell and move cursor
|
||||
virtual bool idxDelete(idx_type &) { return false; }
|
||||
/// pulls cell after pressing erase
|
||||
|
@ -826,46 +826,6 @@ bool MathGridInset::idxLast(LCursor & cur) const
|
||||
}
|
||||
|
||||
|
||||
bool MathGridInset::idxHome(LCursor & cur) const
|
||||
{
|
||||
if (cur.pos() > 0) {
|
||||
cur.pos() = 0;
|
||||
return true;
|
||||
}
|
||||
if (cur.col() > 0) {
|
||||
cur.idx() -= cur.idx() % ncols();
|
||||
cur.pos() = 0;
|
||||
return true;
|
||||
}
|
||||
if (cur.idx() > 0) {
|
||||
cur.idx() = 0;
|
||||
cur.pos() = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool MathGridInset::idxEnd(LCursor & cur) const
|
||||
{
|
||||
if (cur.pos() < cur.lastpos()) {
|
||||
cur.pos() = cur.lastpos();
|
||||
return true;
|
||||
}
|
||||
if (cur.col() < ncols() - 1) {
|
||||
cur.idx() = cur.idx() - cur.idx() % ncols() + ncols() - 1;
|
||||
cur.pos() = cur.lastpos();
|
||||
return true;
|
||||
}
|
||||
if (cur.idx() < nargs() - 1) {
|
||||
cur.idx() = nargs() - 1;
|
||||
cur.pos() = cur.lastpos();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool MathGridInset::idxDelete(idx_type & idx)
|
||||
{
|
||||
// nothing to do if we have just one row
|
||||
@ -1047,154 +1007,183 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
//lyxerr << "*** MathGridInset: request: " << cmd << endl;
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_MOUSE_RELEASE:
|
||||
//if (cmd.button() == mouse_button::button3) {
|
||||
// GridInsetMailer(*this).showDialog();
|
||||
// return DispatchResult(true, true);
|
||||
//}
|
||||
MathNestInset::priv_dispatch(cur, cmd);
|
||||
return;
|
||||
case LFUN_MOUSE_RELEASE:
|
||||
//if (cmd.button() == mouse_button::button3) {
|
||||
// GridInsetMailer(*this).showDialog();
|
||||
// return DispatchResult(true, true);
|
||||
//}
|
||||
MathNestInset::priv_dispatch(cur, cmd);
|
||||
return;
|
||||
|
||||
case LFUN_INSET_DIALOG_UPDATE:
|
||||
GridInsetMailer(*this).updateDialog(&cur.bv());
|
||||
return;
|
||||
case LFUN_INSET_DIALOG_UPDATE:
|
||||
GridInsetMailer(*this).updateDialog(&cur.bv());
|
||||
return;
|
||||
|
||||
// insert file functions
|
||||
case LFUN_DELETE_LINE_FORWARD:
|
||||
//autocorrect_ = false;
|
||||
//macroModeClose();
|
||||
//if (selection_) {
|
||||
// selDel();
|
||||
// return;
|
||||
//}
|
||||
if (nrows() > 1)
|
||||
// insert file functions
|
||||
case LFUN_DELETE_LINE_FORWARD:
|
||||
//autocorrect_ = false;
|
||||
//macroModeClose();
|
||||
//if (selection_) {
|
||||
// selDel();
|
||||
// return;
|
||||
//}
|
||||
if (nrows() > 1)
|
||||
delRow(cur.row());
|
||||
if (cur.idx() > cur.lastidx())
|
||||
cur.idx() = cur.lastidx();
|
||||
if (cur.pos() > cur.lastpos())
|
||||
cur.pos() = cur.lastpos();
|
||||
return;
|
||||
|
||||
case LFUN_CELL_SPLIT:
|
||||
////recordUndo(cur, Undo::ATOMIC);
|
||||
splitCell(cur);
|
||||
return;
|
||||
|
||||
case LFUN_BREAKLINE: {
|
||||
////recordUndo(cur, Undo::INSERT);
|
||||
row_type const r = cur.row();
|
||||
addRow(r);
|
||||
|
||||
// split line
|
||||
for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
|
||||
swap(cell(index(r, c)), cell(index(r + 1, c)));
|
||||
|
||||
// split cell
|
||||
splitCell(cur);
|
||||
swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
|
||||
if (cur.idx() > 0)
|
||||
--cur.idx();
|
||||
cur.idx() = cur.lastpos();
|
||||
|
||||
//mathcursor->normalize();
|
||||
cur.dispatched(FINISHED_LEFT);
|
||||
return;
|
||||
}
|
||||
|
||||
case LFUN_TABULAR_FEATURE: {
|
||||
//lyxerr << "handling tabular-feature " << cmd.argument << endl;
|
||||
istringstream is(cmd.argument);
|
||||
string s;
|
||||
is >> s;
|
||||
if (s == "valign-top")
|
||||
valign('t');
|
||||
else if (s == "valign-middle")
|
||||
valign('c');
|
||||
else if (s == "valign-bottom")
|
||||
valign('b');
|
||||
else if (s == "align-left")
|
||||
halign('l', col(cur.idx()));
|
||||
else if (s == "align-right")
|
||||
halign('r', col(cur.idx()));
|
||||
else if (s == "align-center")
|
||||
halign('c', col(cur.idx()));
|
||||
else if (s == "append-row")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i)
|
||||
addRow(cur.row());
|
||||
else if (s == "delete-row")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
||||
delRow(cur.row());
|
||||
if (cur.idx() > cur.lastidx())
|
||||
cur.idx() = cur.lastidx();
|
||||
if (cur.pos() > cur.lastpos())
|
||||
cur.pos() = cur.lastpos();
|
||||
if (cur.idx() > nargs())
|
||||
cur.idx() -= ncols();
|
||||
}
|
||||
else if (s == "copy-row")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i)
|
||||
copyRow(cur.row());
|
||||
else if (s == "swap-row")
|
||||
swapRow(cur.row());
|
||||
else if (s == "append-column")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
||||
row_type r = cur.row();
|
||||
col_type c = col(cur.idx());
|
||||
addCol(c);
|
||||
cur.idx() = index(r, c);
|
||||
}
|
||||
else if (s == "delete-column")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
||||
row_type r = cur.row();
|
||||
col_type c = col(cur.idx());
|
||||
delCol(col(cur.idx()));
|
||||
cur.idx() = index(r, c);
|
||||
if (cur.idx() > nargs())
|
||||
cur.idx() -= ncols();
|
||||
}
|
||||
else if (s == "copy-column")
|
||||
copyCol(col(cur.idx()));
|
||||
else if (s == "swap-column")
|
||||
swapCol(col(cur.idx()));
|
||||
else {
|
||||
cur.notdispatched();
|
||||
return;
|
||||
}
|
||||
lyxerr << "returning FINISHED_LEFT" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
case LFUN_CELL_SPLIT:
|
||||
////recordUndo(cur, Undo::ATOMIC);
|
||||
splitCell(cur);
|
||||
return;
|
||||
case LFUN_PASTE: {
|
||||
//lyxerr << "pasting '" << cmd.argument << "'" << endl;
|
||||
MathGridInset grid(1, 1);
|
||||
mathed_parse_normal(grid, cmd.argument);
|
||||
if (grid.nargs() == 1) {
|
||||
// single cell/part of cell
|
||||
cur.cell().insert(cur.pos(), grid.cell(0));
|
||||
cur.pos() += grid.cell(0).size();
|
||||
} else {
|
||||
// multiple cells
|
||||
col_type const numcols =
|
||||
min(grid.ncols(), ncols() - col(cur.idx()));
|
||||
row_type const numrows =
|
||||
min(grid.nrows(), nrows() - cur.row());
|
||||
for (row_type r = 0; r < numrows; ++r) {
|
||||
for (col_type c = 0; c < numcols; ++c) {
|
||||
idx_type i = index(r + cur.row(), c + col(cur.idx()));
|
||||
cell(i).insert(0, grid.cell(grid.index(r, c)));
|
||||
}
|
||||
// append the left over horizontal cells to the last column
|
||||
idx_type i = index(r + cur.row(), ncols() - 1);
|
||||
for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
|
||||
cell(i).append(grid.cell(grid.index(r, c)));
|
||||
}
|
||||
// append the left over vertical cells to the last _cell_
|
||||
idx_type i = nargs() - 1;
|
||||
for (row_type r = numrows; r < grid.nrows(); ++r)
|
||||
for (col_type c = 0; c < grid.ncols(); ++c)
|
||||
cell(i).append(grid.cell(grid.index(r, c)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case LFUN_BREAKLINE: {
|
||||
////recordUndo(cur, Undo::INSERT);
|
||||
row_type const r = cur.row();
|
||||
addRow(r);
|
||||
|
||||
// split line
|
||||
for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
|
||||
swap(cell(index(r, c)), cell(index(r + 1, c)));
|
||||
|
||||
// split cell
|
||||
splitCell(cur);
|
||||
swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
|
||||
if (cur.idx() > 0)
|
||||
--cur.idx();
|
||||
cur.idx() = cur.lastpos();
|
||||
|
||||
//mathcursor->normalize();
|
||||
case LFUN_HOMESEL:
|
||||
case LFUN_HOME:
|
||||
case LFUN_WORDLEFTSEL:
|
||||
case LFUN_WORDLEFT:
|
||||
cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
|
||||
cur.macroModeClose();
|
||||
if (cur.pos() != 0)
|
||||
cur.pos() = 0;
|
||||
else if (cur.idx() != 0)
|
||||
cur.idx() = 0;
|
||||
else
|
||||
cur.dispatched(FINISHED_LEFT);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case LFUN_TABULAR_FEATURE: {
|
||||
//lyxerr << "handling tabular-feature " << cmd.argument << endl;
|
||||
istringstream is(cmd.argument);
|
||||
string s;
|
||||
is >> s;
|
||||
if (s == "valign-top")
|
||||
valign('t');
|
||||
else if (s == "valign-middle")
|
||||
valign('c');
|
||||
else if (s == "valign-bottom")
|
||||
valign('b');
|
||||
else if (s == "align-left")
|
||||
halign('l', col(cur.idx()));
|
||||
else if (s == "align-right")
|
||||
halign('r', col(cur.idx()));
|
||||
else if (s == "align-center")
|
||||
halign('c', col(cur.idx()));
|
||||
else if (s == "append-row")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i)
|
||||
addRow(cur.row());
|
||||
else if (s == "delete-row")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
||||
delRow(cur.row());
|
||||
if (cur.idx() > nargs())
|
||||
cur.idx() -= ncols();
|
||||
}
|
||||
else if (s == "copy-row")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i)
|
||||
copyRow(cur.row());
|
||||
else if (s == "swap-row")
|
||||
swapRow(cur.row());
|
||||
else if (s == "append-column")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
||||
row_type r = cur.row();
|
||||
col_type c = col(cur.idx());
|
||||
addCol(c);
|
||||
cur.idx() = index(r, c);
|
||||
}
|
||||
else if (s == "delete-column")
|
||||
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
||||
row_type r = cur.row();
|
||||
col_type c = col(cur.idx());
|
||||
delCol(col(cur.idx()));
|
||||
cur.idx() = index(r, c);
|
||||
if (cur.idx() > nargs())
|
||||
cur.idx() -= ncols();
|
||||
}
|
||||
else if (s == "copy-column")
|
||||
copyCol(col(cur.idx()));
|
||||
else if (s == "swap-column")
|
||||
swapCol(col(cur.idx()));
|
||||
else {
|
||||
cur.notdispatched();
|
||||
return;
|
||||
}
|
||||
lyxerr << "returning FINISHED_LEFT" << endl;
|
||||
return;
|
||||
}
|
||||
case LFUN_WORDRIGHTSEL:
|
||||
case LFUN_WORDRIGHT:
|
||||
case LFUN_ENDSEL:
|
||||
case LFUN_END:
|
||||
cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
|
||||
cur.macroModeClose();
|
||||
cur.clearTargetX();
|
||||
if (cur.pos() != cur.lastpos())
|
||||
cur.pos() = cur.lastpos();
|
||||
else if (cur.idx() != cur.lastidx())
|
||||
cur.idx() = cur.lastidx();
|
||||
else
|
||||
cur.dispatched(FINISHED_RIGHT);
|
||||
break;
|
||||
|
||||
case LFUN_PASTE: {
|
||||
//lyxerr << "pasting '" << cmd.argument << "'" << endl;
|
||||
MathGridInset grid(1, 1);
|
||||
mathed_parse_normal(grid, cmd.argument);
|
||||
if (grid.nargs() == 1) {
|
||||
// single cell/part of cell
|
||||
cur.cell().insert(cur.pos(), grid.cell(0));
|
||||
cur.pos() += grid.cell(0).size();
|
||||
} else {
|
||||
// multiple cells
|
||||
col_type const numcols =
|
||||
min(grid.ncols(), ncols() - col(cur.idx()));
|
||||
row_type const numrows =
|
||||
min(grid.nrows(), nrows() - cur.row());
|
||||
for (row_type r = 0; r < numrows; ++r) {
|
||||
for (col_type c = 0; c < numcols; ++c) {
|
||||
idx_type i = index(r + cur.row(), c + col(cur.idx()));
|
||||
cell(i).insert(0, grid.cell(grid.index(r, c)));
|
||||
}
|
||||
// append the left over horizontal cells to the last column
|
||||
idx_type i = index(r + cur.row(), ncols() - 1);
|
||||
for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
|
||||
cell(i).append(grid.cell(grid.index(r, c)));
|
||||
}
|
||||
// append the left over vertical cells to the last _cell_
|
||||
idx_type i = nargs() - 1;
|
||||
for (row_type r = numrows; r < grid.nrows(); ++r)
|
||||
for (col_type c = 0; c < grid.ncols(); ++c)
|
||||
cell(i).append(grid.cell(grid.index(r, c)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
MathNestInset::priv_dispatch(cur, cmd);
|
||||
return;
|
||||
default:
|
||||
MathNestInset::priv_dispatch(cur, cmd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -155,10 +155,6 @@ public:
|
||||
///
|
||||
bool idxLast(LCursor &) const;
|
||||
///
|
||||
bool idxHome(LCursor &) const;
|
||||
///
|
||||
bool idxEnd(LCursor &) const;
|
||||
///
|
||||
bool idxDelete(idx_type & idx);
|
||||
/// pulls cell after pressing erase
|
||||
void idxGlue(idx_type idx);
|
||||
|
@ -851,12 +851,14 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
|
||||
case LFUN_MATH_MUTATE: {
|
||||
lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
|
||||
row_type r = cur.row();
|
||||
col_type c = cur.col();
|
||||
row_type row = cur.row();
|
||||
col_type col = cur.col();
|
||||
mutate(cmd.argument);
|
||||
cur.idx() = r * ncols() + c;
|
||||
if (cur.idx() >= nargs())
|
||||
cur.idx() = nargs() - 1;
|
||||
cur.idx() = row * ncols() + col;
|
||||
if (cur.idx() > cur.lastidx()) {
|
||||
cur.idx() = cur.lastidx();
|
||||
cur.pos() = cur.lastpos();
|
||||
}
|
||||
if (cur.pos() > cur.lastpos())
|
||||
cur.pos() = cur.lastpos();
|
||||
//cur.dispatched(FINISHED);
|
||||
|
@ -77,6 +77,8 @@ class MathInset : public InsetBase {
|
||||
public:
|
||||
/// identification as math inset
|
||||
MathInset * asMathInset() { return this; }
|
||||
/// this is overridden in math text insets (i.e. mbox)
|
||||
bool inMathed() const { return true; }
|
||||
|
||||
/// substitutes macro arguments if necessary
|
||||
virtual void substitute(MathMacro const & macro);
|
||||
|
@ -35,6 +35,8 @@ public:
|
||||
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
bool inMathed() const { return false; }
|
||||
|
||||
///
|
||||
LyXText * getText(int) const;
|
||||
|
@ -164,26 +164,6 @@ bool MathNestInset::idxLast(LCursor & cur) const
|
||||
}
|
||||
|
||||
|
||||
bool MathNestInset::idxHome(LCursor & cur) const
|
||||
{
|
||||
BOOST_ASSERT(ptr_cmp(cur.inset(), this));
|
||||
if (cur.pos() == 0)
|
||||
return false;
|
||||
cur.pos() = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MathNestInset::idxEnd(LCursor & cur) const
|
||||
{
|
||||
BOOST_ASSERT(ptr_cmp(cur.inset(), this));
|
||||
if (cur.lastpos() == cur.lastpos())
|
||||
return false;
|
||||
cur.pos() = cur.lastpos();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void MathNestInset::dump() const
|
||||
{
|
||||
WriteStream os(lyxerr);
|
||||
@ -351,6 +331,7 @@ void MathNestInset::handleFont2(LCursor & cur, string const & arg)
|
||||
void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
{
|
||||
lyxerr << "MathNestInset: request: " << cmd << std::endl;
|
||||
CursorSlice sl = cur.current();
|
||||
|
||||
switch (cmd.action) {
|
||||
|
||||
@ -423,15 +404,38 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
|
||||
case LFUN_RIGHTSEL:
|
||||
case LFUN_RIGHT:
|
||||
lyxerr << "mathnest RIGHT: from:\n" << cur << endl;
|
||||
cur.selHandle(cmd.action == LFUN_RIGHTSEL);
|
||||
if (!cur.right())
|
||||
cur.autocorrect() = false;
|
||||
cur.clearTargetX();
|
||||
if (cur.inMacroMode())
|
||||
cur.macroModeClose();
|
||||
else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
|
||||
cur.pushLeft(cur.nextAtom().nucleus());
|
||||
cur.inset()->idxFirst(cur);
|
||||
} else if (cur.posRight() || idxRight(cur)
|
||||
|| cur.popRight() || cur.selection())
|
||||
;
|
||||
else
|
||||
cur.dispatched(FINISHED_RIGHT);
|
||||
lyxerr << "mathnest RIGHT: to:\n" << cur << endl;
|
||||
break;
|
||||
|
||||
case LFUN_LEFTSEL:
|
||||
case LFUN_LEFT:
|
||||
cur.selHandle(cmd.action == LFUN_LEFTSEL);
|
||||
if (!cur.left())
|
||||
cur.autocorrect() = false;
|
||||
cur.clearTargetX();
|
||||
if (cur.inMacroMode())
|
||||
cur.macroModeClose();
|
||||
else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
|
||||
cur.posLeft();
|
||||
cur.push(cur.nextAtom().nucleus());
|
||||
cur.inset()->idxLast(cur);
|
||||
} else if (cur.posLeft() || idxLeft(cur)
|
||||
|| cur.popLeft() || cur.selection())
|
||||
;
|
||||
else
|
||||
cur.dispatched(FINISHED_LEFT);
|
||||
break;
|
||||
|
||||
@ -450,10 +454,12 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_WORDSEL:
|
||||
cur.home();
|
||||
cur.pos() = 0;
|
||||
cur.idx() = 0;
|
||||
cur.resetAnchor();
|
||||
cur.selection() = true;
|
||||
cur.end();
|
||||
cur.pos() = cur.lastpos();
|
||||
cur.idx() = cur.lastidx();
|
||||
break;
|
||||
|
||||
case LFUN_UP_PARAGRAPHSEL:
|
||||
@ -462,32 +468,43 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
||||
case LFUN_DOWN_PARAGRAPH:
|
||||
break;
|
||||
|
||||
case LFUN_HOMESEL:
|
||||
case LFUN_HOME:
|
||||
case LFUN_WORDLEFTSEL:
|
||||
case LFUN_WORDLEFT:
|
||||
cur.selHandle(cmd.action == LFUN_WORDLEFTSEL);
|
||||
if (!cur.home())
|
||||
cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
|
||||
cur.macroModeClose();
|
||||
if (cur.pos() != 0) {
|
||||
cur.pos() = 0;
|
||||
} else if (cur.col() != 0) {
|
||||
cur.idx() -= cur.col();
|
||||
cur.pos() = 0;
|
||||
} else if (cur.idx() != 0) {
|
||||
cur.idx() = 0;
|
||||
cur.pos() = 0;
|
||||
} else {
|
||||
cur.dispatched(FINISHED_LEFT);
|
||||
}
|
||||
break;
|
||||
|
||||
case LFUN_WORDRIGHTSEL:
|
||||
case LFUN_WORDRIGHT:
|
||||
cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL);
|
||||
if (!cur.end())
|
||||
cur.dispatched(FINISHED_RIGHT);
|
||||
break;
|
||||
|
||||
case LFUN_HOMESEL:
|
||||
case LFUN_HOME:
|
||||
cur.selHandle(cmd.action == LFUN_HOMESEL);
|
||||
if (!cur.home())
|
||||
cur.dispatched(FINISHED_LEFT);
|
||||
break;
|
||||
|
||||
case LFUN_ENDSEL:
|
||||
case LFUN_END:
|
||||
cur.selHandle(cmd.action == LFUN_ENDSEL);
|
||||
if (!cur.end())
|
||||
cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
|
||||
cur.macroModeClose();
|
||||
cur.clearTargetX();
|
||||
if (cur.pos() != cur.lastpos()) {
|
||||
cur.pos() = cur.lastpos();
|
||||
} else if (cur.col() != cur.lastcol()) {
|
||||
cur.idx() = cur.idx() - cur.col() + cur.lastcol();
|
||||
cur.pos() = cur.lastpos();
|
||||
} else if (cur.idx() != cur.lastidx()) {
|
||||
cur.idx() = cur.lastidx();
|
||||
cur.pos() = cur.lastpos();
|
||||
} else {
|
||||
cur.dispatched(FINISHED_RIGHT);
|
||||
}
|
||||
break;
|
||||
|
||||
case LFUN_PRIORSEL:
|
||||
|
@ -60,11 +60,6 @@ public:
|
||||
/// target pos when we enter the inset from the right by pressing "Left"
|
||||
bool idxLast(LCursor &) const;
|
||||
|
||||
/// where should we go if we press home?
|
||||
bool idxHome(LCursor &) const;
|
||||
/// where should we go if we press end?
|
||||
bool idxEnd(LCursor &) const;
|
||||
|
||||
/// number of cells currently governed by us
|
||||
idx_type nargs() const;
|
||||
/// access to the lock
|
||||
|
@ -135,8 +135,7 @@ namespace {
|
||||
lyxerr << "selection is: '" << sel << "'" << endl;
|
||||
|
||||
if (sel.empty()) {
|
||||
cur.insert(new MathHullInset);
|
||||
cur.dispatch(FuncRequest(LFUN_RIGHT));
|
||||
cur.insert(new MathHullInset); // activates inset
|
||||
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
|
||||
// don't do that also for LFUN_MATH_MODE unless you want end up with
|
||||
// always changing to mathrm when opening an inlined inset
|
||||
@ -152,12 +151,10 @@ namespace {
|
||||
sel.find("\\def") == string::npos)
|
||||
{
|
||||
cur.insert(new MathHullInset);
|
||||
cur.dispatch(FuncRequest(LFUN_RIGHT));
|
||||
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
|
||||
cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
|
||||
} else {
|
||||
cur.insert(new InsetFormulaMacro(sel));
|
||||
cur.dispatch(FuncRequest(LFUN_RIGHT));
|
||||
}
|
||||
}
|
||||
cur.message(N_("Math editor mode"));
|
||||
|
Loading…
Reference in New Issue
Block a user