mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
enable insertion of spaces in all \textxxx modes.
some cleanup. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4702 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
cec9c25bd7
commit
10fd14e55b
@ -613,7 +613,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
||||
break;
|
||||
|
||||
case LFUN_MATH_MODE:
|
||||
if (mathcursor->inMathMode()) {
|
||||
if (mathcursor->currentMode()) {
|
||||
handleFont(bv, arg, "textrm");
|
||||
} else {
|
||||
mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
|
||||
|
@ -36,12 +36,6 @@ void MathBoxInset::normalize(NormalStream & os) const
|
||||
}
|
||||
|
||||
|
||||
void MathBoxInset::rebreak()
|
||||
{
|
||||
//lyxerr << "trying to rebreak...\n";
|
||||
}
|
||||
|
||||
|
||||
void MathBoxInset::metrics(MathMetricsInfo & mi) const
|
||||
{
|
||||
MathFontSetChanger dummy(mi.base, "textnormal");
|
||||
|
@ -20,15 +20,11 @@ public:
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
mode_type currentMode() const { return TEXT_MODE; }
|
||||
///
|
||||
void metrics(MathMetricsInfo & mi) const;
|
||||
///
|
||||
void draw(MathPainterInfo & pi, int x, int y) const;
|
||||
/// identifies BoxInsets
|
||||
MathBoxInset * asBoxInset() { return this; }
|
||||
/// identifies BoxInsets
|
||||
MathBoxInset const * asBoxInset() const { return this; }
|
||||
///
|
||||
void rebreak();
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
|
@ -32,12 +32,10 @@
|
||||
#include "math_autocorrect.h"
|
||||
#include "math_arrayinset.h"
|
||||
#include "math_braceinset.h"
|
||||
#include "math_boxinset.h"
|
||||
#include "math_casesinset.h"
|
||||
#include "math_charinset.h"
|
||||
#include "math_extern.h"
|
||||
#include "math_factory.h"
|
||||
#include "math_fboxinset.h"
|
||||
#include "math_hullinset.h"
|
||||
#include "math_iterator.h"
|
||||
#include "math_macroarg.h"
|
||||
@ -855,17 +853,6 @@ void MathCursor::touch()
|
||||
|
||||
void MathCursor::normalize()
|
||||
{
|
||||
#if 0
|
||||
// rebreak
|
||||
{
|
||||
MathIterator it = ibegin(formula()->par().nucleus());
|
||||
MathIterator et = iend(formula()->par().nucleus());
|
||||
for (; it != et; ++it)
|
||||
if (it.par()->asBoxInset())
|
||||
it.par()->asBoxInset()->rebreak();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (idx() >= par()->nargs()) {
|
||||
lyxerr << "this should not really happen - 1: "
|
||||
<< idx() << " " << par()->nargs() << "\n";
|
||||
@ -1366,20 +1353,6 @@ bool MathCursor::script(bool up)
|
||||
}
|
||||
|
||||
|
||||
bool MathCursor::inMathMode() const
|
||||
{
|
||||
if (par()->asBoxInset())
|
||||
return false;
|
||||
if (par()->asFboxInset())
|
||||
return false;
|
||||
if (par()->asParboxInset())
|
||||
return false;
|
||||
if (par()->asParInset())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MathCursor::interpret(char c)
|
||||
{
|
||||
//lyxerr << "interpret 2: '" << c << "'\n";
|
||||
@ -1451,16 +1424,6 @@ bool MathCursor::interpret(char c)
|
||||
|
||||
selClearOrDel();
|
||||
|
||||
if (!inMathMode()) {
|
||||
// suppress direct insertion of two spaces in a row
|
||||
// the still allows typing '<space>a<space>' and deleting the 'a', but
|
||||
// it is better than nothing...
|
||||
if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
|
||||
return true;
|
||||
insert(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (c == '\\') {
|
||||
//lyxerr << "starting with macro\n";
|
||||
insert(MathAtom(new MathUnknownInset("\\", false)));
|
||||
@ -1468,6 +1431,15 @@ bool MathCursor::interpret(char c)
|
||||
}
|
||||
|
||||
if (c == ' ') {
|
||||
if (currentMode() == MathInset::TEXT_MODE) {
|
||||
// insert spaces in text mode,
|
||||
// but suppress direct insertion of two spaces in a row
|
||||
// the still allows typing '<space>a<space>' and deleting the 'a', but
|
||||
// it is better than nothing...
|
||||
if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
|
||||
insert(c);
|
||||
return true;
|
||||
}
|
||||
if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
|
||||
prevAtom()->asSpaceInset()->incSpace();
|
||||
return true;
|
||||
@ -1771,3 +1743,14 @@ int MathCursor::dispatch(string const & cmd)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
MathInset::mode_type MathCursor::currentMode() const
|
||||
{
|
||||
for (int i = Cursor_.size() - 1; i >= 0; --i) {
|
||||
MathInset::mode_type res = Cursor_[i].par_->currentMode();
|
||||
if (res != MathInset::UNDECIDED_MODE)
|
||||
return res;
|
||||
}
|
||||
return MathInset::UNDECIDED_MODE;
|
||||
}
|
||||
|
@ -138,8 +138,8 @@ public:
|
||||
MathUnknownInset * inMacroMode() const;
|
||||
/// are we currently typing '#1' or '#2' or...?
|
||||
bool inMacroArgMode() const;
|
||||
/// are we in an mbox?
|
||||
bool inMathMode() const;
|
||||
/// are we in math mode (1), text mode (-1) or unsure?
|
||||
MathInset::mode_type currentMode() const;
|
||||
|
||||
// Local selection methods
|
||||
///
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
MathFboxInset * asFboxInset() { return this; }
|
||||
mode_type currentMode() const { return TEXT_MODE; }
|
||||
///
|
||||
void metrics(MathMetricsInfo & mi) const;
|
||||
///
|
||||
|
@ -29,6 +29,12 @@ MathInset * MathFontInset::clone() const
|
||||
}
|
||||
|
||||
|
||||
MathInset::mode_type MathFontInset::currentMode() const
|
||||
{
|
||||
return key_->extra == "mathmode" ? MATH_MODE : TEXT_MODE;
|
||||
}
|
||||
|
||||
|
||||
void MathFontInset::metrics(MathMetricsInfo & mi) const
|
||||
{
|
||||
MathFontSetChanger dummy(mi.base, key_->name.c_str());
|
||||
|
@ -20,6 +20,8 @@ public:
|
||||
explicit MathFontInset(latexkeys const * key);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
/// are we in math mode, text mode, or unsure?
|
||||
mode_type currentMode() const;
|
||||
///
|
||||
void metrics(MathMetricsInfo & mi) const;
|
||||
///
|
||||
|
@ -20,6 +20,8 @@ public:
|
||||
explicit MathFontOldInset(latexkeys const * key);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
/// we are in text mode.
|
||||
mode_type currentMode() const { return TEXT_MODE; }
|
||||
/// we write extra braces in any case...
|
||||
bool extraBraces() const { return true; }
|
||||
///
|
||||
|
@ -94,14 +94,6 @@ MathHullInset::MathHullInset(string const & type)
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
/*
|
||||
MathHullInset::MathHullInset(string const & type, MathGridInset const & grid)
|
||||
: MathGridInset(grid), type_(type), nonum_(1), label_(1)
|
||||
{
|
||||
setDefaults();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
MathInset * MathHullInset::clone() const
|
||||
{
|
||||
@ -109,6 +101,15 @@ MathInset * MathHullInset::clone() const
|
||||
}
|
||||
|
||||
|
||||
MathInset::mode_type MathHullInset::currentMode() const
|
||||
{
|
||||
if (type_ == "none")
|
||||
return UNDECIDED_MODE;
|
||||
// definitely math mode ...
|
||||
return MATH_MODE;
|
||||
}
|
||||
|
||||
|
||||
bool MathHullInset::idxFirst(idx_type & idx, pos_type & pos) const
|
||||
{
|
||||
idx = 0;
|
||||
|
@ -21,10 +21,10 @@ public:
|
||||
///
|
||||
explicit MathHullInset(string const & type);
|
||||
///
|
||||
MathHullInset(string const & type, MathGridInset const & grid);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
mode_type currentMode() const;
|
||||
///
|
||||
void metrics(MathMetricsInfo & mi) const;
|
||||
///
|
||||
void draw(MathPainterInfo &, int x, int y) const;
|
||||
|
@ -49,16 +49,13 @@ inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
|
||||
|
||||
class MathArrayInset;
|
||||
class MathAMSArrayInset;
|
||||
class MathBoxInset;
|
||||
class MathCharInset;
|
||||
class MathDelimInset;
|
||||
class MathFboxInset;
|
||||
class MathGridInset;
|
||||
class MathFracInset;
|
||||
class MathHullInset;
|
||||
class MathMatrixInset;
|
||||
class MathNestInset;
|
||||
class MathParInset;
|
||||
class MathParboxInset;
|
||||
class MathScriptInset;
|
||||
class MathStringInset;
|
||||
@ -196,12 +193,9 @@ public:
|
||||
/// identifies certain types of insets
|
||||
virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
|
||||
virtual MathArrayInset * asArrayInset() { return 0; }
|
||||
virtual MathBoxInset * asBoxInset() { return 0; }
|
||||
virtual MathBoxInset const * asBoxInset() const { return 0; }
|
||||
virtual MathCharInset const * asCharInset() const { return 0; }
|
||||
virtual MathDelimInset * asDelimInset() { return 0; }
|
||||
virtual MathDelimInset const * asDelimInset() const { return 0; }
|
||||
virtual MathFboxInset * asFboxInset() { return 0; }
|
||||
virtual MathFracInset * asFracInset() { return 0; }
|
||||
virtual MathGridInset * asGridInset() { return 0; }
|
||||
virtual MathHullInset * asHullInset() { return 0; }
|
||||
@ -209,7 +203,6 @@ public:
|
||||
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
|
||||
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
|
||||
virtual MathNestInset * asNestInset() { return 0; }
|
||||
virtual MathParInset * asParInset() { return 0; }
|
||||
virtual MathParboxInset * asParboxInset() { return 0; }
|
||||
virtual MathScriptInset * asScriptInset() { return 0; }
|
||||
virtual MathScriptInset const * asScriptInset() const { return 0; }
|
||||
@ -227,6 +220,9 @@ public:
|
||||
virtual bool isActive() const { return nargs() > 0; }
|
||||
/// is the a relational operator (used for splitting equations)
|
||||
virtual bool isRelOp() const { return false; }
|
||||
/// -1: text mode, 1: math mode, 0 undecided
|
||||
enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
|
||||
virtual mode_type currentMode() const { return UNDECIDED_MODE; }
|
||||
/// will this get written as a single block in {..}
|
||||
virtual bool extraBraces() const { return false; }
|
||||
|
||||
|
@ -11,6 +11,8 @@ public:
|
||||
MathParboxInset * asParboxInset() { return this; }
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
mode_type currentMode() const { return TEXT_MODE; }
|
||||
/// get cursor position
|
||||
void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
|
||||
///
|
||||
|
@ -8,7 +8,7 @@ public:
|
||||
///
|
||||
MathParInset();
|
||||
///
|
||||
MathParInset * asParInset() { return this; }
|
||||
mode_type currentMode() const { return TEXT_MODE; }
|
||||
///
|
||||
void metrics(MathMetricsInfo & mi) const;
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user