mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 11:16:55 +00:00
Fix bug #6936.
If \hline is entered, do not create an unknown inset, but increase the number of hlines of the current row if that is allowed. The same idea is applied to copy-paste (not part of the bug report). This is also a test for committing via git.
This commit is contained in:
parent
b907a0dc7c
commit
6d75800f5d
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "InsetMathGrid.h"
|
#include "InsetMathGrid.h"
|
||||||
|
|
||||||
|
#include "InsetMathUnknown.h"
|
||||||
#include "MathData.h"
|
#include "MathData.h"
|
||||||
#include "MathParser.h"
|
#include "MathParser.h"
|
||||||
#include "MathStream.h"
|
#include "MathStream.h"
|
||||||
@ -176,6 +177,22 @@ void InsetMathGrid::setDefaults()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
|
||||||
|
{
|
||||||
|
if (str == "\\hline") {
|
||||||
|
FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
|
||||||
|
FuncStatus status;
|
||||||
|
if (getStatus(cur, fr, status)) {
|
||||||
|
if (status.enabled()) {
|
||||||
|
rowinfo_[cur.row()].lines_++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return InsetMathNest::interpretString(cur, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
|
void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
|
||||||
{
|
{
|
||||||
col_type col = 0;
|
col_type col = 0;
|
||||||
@ -1332,11 +1349,25 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
|
mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hline_enabled = false;
|
||||||
|
FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
|
||||||
|
FuncStatus status;
|
||||||
|
if (getStatus(cur, fr, status))
|
||||||
|
hline_enabled = status.enabled();
|
||||||
if (grid.nargs() == 1) {
|
if (grid.nargs() == 1) {
|
||||||
// single cell/part of cell
|
// single cell/part of cell
|
||||||
cur.recordUndo();
|
cur.recordUndo();
|
||||||
cur.cell().insert(cur.pos(), grid.cell(0));
|
cur.cell().insert(cur.pos(), grid.cell(0));
|
||||||
cur.pos() += grid.cell(0).size();
|
cur.pos() += grid.cell(0).size();
|
||||||
|
if (hline_enabled)
|
||||||
|
rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
|
||||||
|
else {
|
||||||
|
for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
|
||||||
|
cur.cell().insert(0,
|
||||||
|
MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
|
||||||
|
cur.pos()++;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// multiple cells
|
// multiple cells
|
||||||
cur.recordUndoInset();
|
cur.recordUndoInset();
|
||||||
@ -1349,6 +1380,15 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
idx_type i = index(r + cur.row(), c + col(cur.idx()));
|
idx_type i = index(r + cur.row(), c + col(cur.idx()));
|
||||||
cell(i).insert(0, grid.cell(grid.index(r, c)));
|
cell(i).insert(0, grid.cell(grid.index(r, c)));
|
||||||
}
|
}
|
||||||
|
if (hline_enabled)
|
||||||
|
rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
|
||||||
|
else {
|
||||||
|
for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
|
||||||
|
idx_type i = index(r + cur.row(), 0);
|
||||||
|
cell(i).insert(0,
|
||||||
|
MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
|
||||||
|
}
|
||||||
|
}
|
||||||
// append the left over horizontal cells to the last column
|
// append the left over horizontal cells to the last column
|
||||||
idx_type i = index(r + cur.row(), ncols() - 1);
|
idx_type i = index(r + cur.row(), ncols() - 1);
|
||||||
for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
|
for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
|
||||||
@ -1356,9 +1396,18 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
}
|
}
|
||||||
// append the left over vertical cells to the last _cell_
|
// append the left over vertical cells to the last _cell_
|
||||||
idx_type i = nargs() - 1;
|
idx_type i = nargs() - 1;
|
||||||
for (row_type r = numrows; r < grid.nrows(); ++r)
|
for (row_type r = numrows; r < grid.nrows(); ++r) {
|
||||||
for (col_type c = 0; c < grid.ncols(); ++c)
|
for (col_type c = 0; c < grid.ncols(); ++c)
|
||||||
cell(i).append(grid.cell(grid.index(r, c)));
|
cell(i).append(grid.cell(grid.index(r, c)));
|
||||||
|
if (hline_enabled)
|
||||||
|
rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
|
||||||
|
else {
|
||||||
|
for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
|
||||||
|
cell(i).insert(0,
|
||||||
|
MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cur.clearSelection(); // bug 393
|
cur.clearSelection(); // bug 393
|
||||||
// FIXME audit setBuffer calls
|
// FIXME audit setBuffer calls
|
||||||
|
@ -194,6 +194,8 @@ public:
|
|||||||
virtual char defaultColAlign(col_type) { return 'c'; }
|
virtual char defaultColAlign(col_type) { return 'c'; }
|
||||||
///
|
///
|
||||||
void setDefaults();
|
void setDefaults();
|
||||||
|
///
|
||||||
|
virtual bool interpretString(Cursor & cur, docstring const & str);
|
||||||
|
|
||||||
///
|
///
|
||||||
virtual int colsep() const;
|
virtual int colsep() const;
|
||||||
|
@ -872,7 +872,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
// if relevant. Think typing "\frac<space>".
|
// if relevant. Think typing "\frac<space>".
|
||||||
if (cmd.argument()[0] == ' '
|
if (cmd.argument()[0] == ' '
|
||||||
&& cur.inMacroMode() && cur.macroName() != "\\"
|
&& cur.inMacroMode() && cur.macroName() != "\\"
|
||||||
&& cur.macroModeClose()) {
|
&& cur.macroModeClose() && cur.pos() > 0) {
|
||||||
MathAtom const atom = cur.prevAtom();
|
MathAtom const atom = cur.prevAtom();
|
||||||
if (atom->asNestInset() && atom->isActive()) {
|
if (atom->asNestInset() && atom->isActive()) {
|
||||||
cur.posBackward();
|
cur.posBackward();
|
||||||
|
@ -172,7 +172,7 @@ public:
|
|||||||
/// interpret \p str and insert the result at the current position of
|
/// interpret \p str and insert the result at the current position of
|
||||||
/// \p cur if it is something known. Return whether \p cur was
|
/// \p cur if it is something known. Return whether \p cur was
|
||||||
/// inserted.
|
/// inserted.
|
||||||
bool interpretString(Cursor & cur, docstring const & str);
|
virtual bool interpretString(Cursor & cur, docstring const & str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// lfun handler
|
/// lfun handler
|
||||||
|
@ -1272,7 +1272,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
|||||||
os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
|
os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
|
||||||
<< "\" columns=\"" << colinfo.size() << "\">\n";
|
<< "\" columns=\"" << colinfo.size() << "\">\n";
|
||||||
os << "<features"
|
os << "<features"
|
||||||
<< write_attribute("rotate", "0")
|
<< write_attribute("rotate", false)
|
||||||
<< write_attribute("booktabs", booktabs)
|
<< write_attribute("booktabs", booktabs)
|
||||||
<< write_attribute("islongtable", is_long_tabular);
|
<< write_attribute("islongtable", is_long_tabular);
|
||||||
if (is_long_tabular) {
|
if (is_long_tabular) {
|
||||||
|
Loading…
Reference in New Issue
Block a user