mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 13:04:58 +00:00
Define mathClass of MathMacro
Enables intelligent splitting for math macros. Crucially improves the detection of math words for the new Ctrl-Arrow movement.
This commit is contained in:
parent
eb2d373e4b
commit
a467671283
@ -889,6 +889,20 @@ int MathData::yo(BufferView const & bv) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MathClass MathData::mathClass() const
|
||||||
|
{
|
||||||
|
MathClass res = MC_UNKNOWN;
|
||||||
|
for (MathAtom const & at : *this) {
|
||||||
|
MathClass mc = at->mathClass();
|
||||||
|
if (res == MC_UNKNOWN)
|
||||||
|
res = mc;
|
||||||
|
else if (mc != MC_UNKNOWN && res != mc)
|
||||||
|
return MC_ORD;
|
||||||
|
}
|
||||||
|
return res == MC_UNKNOWN ? MC_ORD : res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ostream & operator<<(ostream & os, MathData const & ar)
|
ostream & operator<<(ostream & os, MathData const & ar)
|
||||||
{
|
{
|
||||||
odocstringstream oss;
|
odocstringstream oss;
|
||||||
|
@ -137,6 +137,8 @@ public:
|
|||||||
void drawT(TextPainter & pi, int x, int y) const;
|
void drawT(TextPainter & pi, int x, int y) const;
|
||||||
/// mark cell for re-drawing
|
/// mark cell for re-drawing
|
||||||
void touch() const;
|
void touch() const;
|
||||||
|
/// approximate the math class of the data
|
||||||
|
MathClass mathClass() const;
|
||||||
|
|
||||||
/// access to cached x coordinate of last drawing
|
/// access to cached x coordinate of last drawing
|
||||||
int xo(BufferView const & bv) const;
|
int xo(BufferView const & bv) const;
|
||||||
|
@ -140,6 +140,15 @@ public:
|
|||||||
void htmlize(HtmlStream & ms) const { ms << mathMacro_->cell(idx_); }
|
void htmlize(HtmlStream & ms) const { ms << mathMacro_->cell(idx_); }
|
||||||
///
|
///
|
||||||
void octave(OctaveStream & os) const { os << mathMacro_->cell(idx_); }
|
void octave(OctaveStream & os) const { os << mathMacro_->cell(idx_); }
|
||||||
|
///
|
||||||
|
MathClass mathClass() const
|
||||||
|
{
|
||||||
|
return MC_UNKNOWN;
|
||||||
|
// This can be refined once the pointer issues are fixed. I did not
|
||||||
|
// notice any immediate crash with the following code, but it is risky
|
||||||
|
// nevertheless:
|
||||||
|
//return mathMacro_->cell(idx_).mathClass();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
@ -823,16 +832,21 @@ size_t MathMacro::appetite() const
|
|||||||
|
|
||||||
MathClass MathMacro::mathClass() const
|
MathClass MathMacro::mathClass() const
|
||||||
{
|
{
|
||||||
// this only affects intelligent splitting since global macros are always
|
// This can be just a heuristic, since it is only considered for display
|
||||||
// linearised.
|
// when the macro is not linearised. Therefore it affects:
|
||||||
|
// * The spacing of the inset while being edited,
|
||||||
|
// * Intelligent splitting
|
||||||
|
// * Cursor word movement (Ctrl-Arrow).
|
||||||
if (MacroData const * m = macroBackup()) {
|
if (MacroData const * m = macroBackup()) {
|
||||||
|
// If it is a global macro and is defined explicitly
|
||||||
if (m->symbol()) {
|
if (m->symbol()) {
|
||||||
MathClass mc = string_to_class(d->macroBackup_.symbol()->extra);
|
MathClass mc = string_to_class(d->macroBackup_.symbol()->extra);
|
||||||
if (mc != MC_UNKNOWN)
|
if (mc != MC_UNKNOWN)
|
||||||
return mc;
|
return mc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MC_ORD;
|
// Otherwise guess from the expanded macro
|
||||||
|
return d->expanded_.mathClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user