Martin Vermeer wrote:
> On Wed, Feb 22, 2006 at 09:41:48PM +0200, Martin Vermeer wrote:
>> The test for (*it)->getChar(). The idea with this is to make sure that
>> if there is not a "character" in this location (but rather, something
>> that is itself an inset), the cursor slice on the current level will be
>> positioned to the left of it (and presumably the visible cursor, one
>> level deeper, inside it).
>>
>> This breaks down if the "thing" is a symbol: it is not a character
>> according to the above test, but neither can the cursor descend into
>> it.
>
> Fixing it for math_symbolinset was simply a matter of adding a getChar()
> method returning, e.g., '@'. For frac it is trickier...
This is a hack that will bite later. getChar is supposed to return the
contents of an inset if it can be represented as a single character, not
some arbitrary character.
What you really want to know is "Can the cursor descend into this inset?" We
have InsetBase::editable() that exactly answers this question, the only
disadvantage is that this is not implemented in mathed yet.
The attached patch implements that and works for me as well. What needs to
be done if this should go in is to check for side effects everywhere where
editable() is used (fortunately only ~ 3 places), and better testing, but I
think that this approach is prefereable to the getChar hack.
Georg
Index: src/mathed/math_colorinset.h
===================================================================
--- src/mathed/math_colorinset.h (Revision 13267)
+++ src/mathed/math_colorinset.h (Arbeitskopie)
@@ -32,6 +32,8 @@ public:
bool extraBraces() const { return true; }
///
void draw(PainterInfo & pi, int x, int y) const;
+ ///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
/// we need package color
void validate(LaTeXFeatures & features) const;
///
Index: src/mathed/math_boxinset.h
===================================================================
--- src/mathed/math_boxinset.h (Revision 13267)
+++ src/mathed/math_boxinset.h (Arbeitskopie)
@@ -32,6 +32,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void write(WriteStream & os) const;
///
void normalize(NormalStream & ns) const;
Index: src/mathed/math_lefteqninset.h
===================================================================
--- src/mathed/math_lefteqninset.h (Revision 13267)
+++ src/mathed/math_lefteqninset.h (Arbeitskopie)
@@ -28,6 +28,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
void infoize(std::ostream & os) const;
private:
virtual std::auto_ptr<InsetBase> doClone() const;
Index: src/mathed/math_fboxinset.h
===================================================================
--- src/mathed/math_fboxinset.h (Revision 13267)
+++ src/mathed/math_fboxinset.h (Arbeitskopie)
@@ -27,6 +27,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
Index: src/mathed/math_biginset.h
===================================================================
--- src/mathed/math_biginset.h (Revision 13267)
+++ src/mathed/math_biginset.h (Arbeitskopie)
@@ -26,6 +26,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
void write(WriteStream & os) const;
///
void normalize(NormalStream & os) const;
Index: src/mathed/math_frameboxinset.h
===================================================================
--- src/mathed/math_frameboxinset.h (Revision 13267)
+++ src/mathed/math_frameboxinset.h (Arbeitskopie)
@@ -25,6 +25,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
Index: src/mathed/math_boldsymbolinset.h
===================================================================
--- src/mathed/math_boldsymbolinset.h (Revision 13267)
+++ src/mathed/math_boldsymbolinset.h (Arbeitskopie)
@@ -25,6 +25,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
Index: src/mathed/math_makeboxinset.h
===================================================================
--- src/mathed/math_makeboxinset.h (Revision 13267)
+++ src/mathed/math_makeboxinset.h (Arbeitskopie)
@@ -26,6 +26,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
Index: src/mathed/math_data.C
===================================================================
--- src/mathed/math_data.C (Revision 13267)
+++ src/mathed/math_data.C (Arbeitskopie)
@@ -393,7 +388,7 @@ MathArray::size_type MathArray::x2pos(in
#endif
if (it != begin()) {
--it;
- if (it < end() && (*it)->getChar())
+ if (it < end() && (*it)->editable() != InsetBase::HIGHLY_EDITABLE)
++it;
}
Index: src/mathed/math_scriptinset.h
===================================================================
--- src/mathed/math_scriptinset.h (Revision 13267)
+++ src/mathed/math_scriptinset.h (Arbeitskopie)
@@ -34,6 +34,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
Index: src/mathed/math_fontinset.h
===================================================================
--- src/mathed/math_fontinset.h (Revision 13267)
+++ src/mathed/math_fontinset.h (Arbeitskopie)
@@ -35,6 +35,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
Index: src/mathed/math_stringinset.h
===================================================================
--- src/mathed/math_stringinset.h (Revision 13267)
+++ src/mathed/math_stringinset.h (Arbeitskopie)
@@ -28,6 +28,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
std::string str() const { return str_; }
///
MathStringInset * asStringInset() { return this; }
Index: src/mathed/math_rootinset.h
===================================================================
--- src/mathed/math_rootinset.h (Revision 13267)
+++ src/mathed/math_rootinset.h (Arbeitskopie)
@@ -27,7 +27,8 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
-
+ ///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
///
void write(WriteStream & os) const;
///
Index: src/mathed/math_decorationinset.h
===================================================================
--- src/mathed/math_decorationinset.h (Revision 13267)
+++ src/mathed/math_decorationinset.h (Arbeitskopie)
@@ -26,6 +26,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
void write(WriteStream & os) const;
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
Index: src/mathed/math_symbolinset.h
===================================================================
--- src/mathed/math_symbolinset.h (Revision 13267)
+++ src/mathed/math_symbolinset.h (Arbeitskopie)
@@ -33,6 +33,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
int width() const { return width_; }
///
Index: src/mathed/math_exintinset.h
===================================================================
--- src/mathed/math_exintinset.h (Revision 13267)
+++ src/mathed/math_exintinset.h (Arbeitskopie)
@@ -32,7 +32,8 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo &, int x, int y) const;
-
+ ///
+ EDITABLE editable() const { return NOT_EDITABLE; }
///
void normalize(NormalStream &) const;
///
Index: src/mathed/math_deliminset.h
===================================================================
--- src/mathed/math_deliminset.h (Revision 13267)
+++ src/mathed/math_deliminset.h (Arbeitskopie)
@@ -41,7 +41,8 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo &, int x, int y) const;
-
+ ///
+ EDITABLE editable() const { return NOT_EDITABLE; }
///
void write(WriteStream & os) const;
/// write normalized content
Index: src/mathed/math_spaceinset.h
===================================================================
--- src/mathed/math_spaceinset.h (Revision 13267)
+++ src/mathed/math_spaceinset.h (Arbeitskopie)
@@ -38,7 +38,8 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
-
+ ///
+ EDITABLE editable() const { return NOT_EDITABLE; }
///
void normalize(NormalStream &) const;
///
Index: src/mathed/math_hullinset.h
===================================================================
--- src/mathed/math_hullinset.h (Revision 13267)
+++ src/mathed/math_hullinset.h (Arbeitskopie)
@@ -195,8 +203,6 @@ public:
///
virtual void revealCodes(LCursor & cur) const;
///
- EDITABLE editable() const { return HIGHLY_EDITABLE; }
- ///
void edit(LCursor & cur, bool left);
///
InsetBase * editXY(LCursor & cur, int x, int y);
Index: src/mathed/math_braceinset.h
===================================================================
--- src/mathed/math_braceinset.h (Revision 13267)
+++ src/mathed/math_braceinset.h (Arbeitskopie)
@@ -31,6 +31,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
Index: src/mathed/math_parinset.h
===================================================================
--- src/mathed/math_parinset.h (Revision 13267)
+++ src/mathed/math_parinset.h (Arbeitskopie)
@@ -28,6 +28,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void infoize(std::ostream & os) const;
///
void write(WriteStream & os) const;
Index: src/mathed/math_numberinset.h
===================================================================
--- src/mathed/math_numberinset.h (Revision 13267)
+++ src/mathed/math_numberinset.h (Arbeitskopie)
@@ -27,6 +27,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
std::string str() const { return str_; }
///
MathNumberInset * asNumberInset() { return this; }
Index: src/mathed/math_macro.h
===================================================================
--- src/mathed/math_macro.h (Revision 13267)
+++ src/mathed/math_macro.h (Arbeitskopie)
@@ -31,6 +31,8 @@ public:
/// draw selection background
void drawSelection(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void metrics(MetricsInfo & mi, Dimension & dim) const;
/// get cursor position
void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
Index: src/mathed/math_commentinset.h
===================================================================
--- src/mathed/math_commentinset.h (Revision 13267)
+++ src/mathed/math_commentinset.h (Arbeitskopie)
@@ -29,6 +29,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
Index: src/mathed/math_diffinset.h
===================================================================
--- src/mathed/math_diffinset.h (Revision 13267)
+++ src/mathed/math_diffinset.h (Arbeitskopie)
@@ -28,7 +28,8 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
-
+ ///
+ EDITABLE editable() const { return NOT_EDITABLE; }
///
void normalize(NormalStream &) const;
///
Index: src/mathed/math_sizeinset.h
===================================================================
--- src/mathed/math_sizeinset.h (Revision 13267)
+++ src/mathed/math_sizeinset.h (Arbeitskopie)
@@ -29,7 +29,8 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo &, int x, int y) const;
-
+ ///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
///
void write(WriteStream & os) const;
///
Index: src/mathed/math_liminset.h
===================================================================
--- src/mathed/math_liminset.h (Revision 13267)
+++ src/mathed/math_liminset.h (Arbeitskopie)
@@ -26,7 +26,8 @@ public:
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
-
+ ///
+ EDITABLE editable() const { return NOT_EDITABLE; }
///
void normalize(NormalStream &) const;
///
Index: src/mathed/math_envinset.h
===================================================================
--- src/mathed/math_envinset.h (Revision 13267)
+++ src/mathed/math_envinset.h (Arbeitskopie)
@@ -25,6 +25,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
Index: src/mathed/math_exfuncinset.h
===================================================================
--- src/mathed/math_exfuncinset.h (Revision 13267)
+++ src/mathed/math_exfuncinset.h (Arbeitskopie)
@@ -32,6 +32,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
std::string name() const;
///
Index: src/mathed/math_fracbase.h
===================================================================
--- src/mathed/math_fracbase.h (Revision 13267)
+++ src/mathed/math_fracbase.h (Arbeitskopie)
@@ -25,6 +25,8 @@ public:
bool idxLeft(LCursor &) const;
///
bool idxRight(LCursor &) const;
+ ///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
};
#endif
Index: src/mathed/command_inset.h
===================================================================
--- src/mathed/command_inset.h (Revision 13267)
+++ src/mathed/command_inset.h (Arbeitskopie)
@@ -30,6 +30,8 @@ public:
///
InsetBase * editXY(LCursor &, int, int);
///
+ EDITABLE editable() const { return IS_EDITABLE; }
+ ///
void write(WriteStream & os) const;
//
// void infoize(std::ostream & os) const;
Index: src/mathed/math_charinset.h
===================================================================
--- src/mathed/math_charinset.h (Revision 13267)
+++ src/mathed/math_charinset.h (Arbeitskopie)
@@ -25,6 +25,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter &, int x, int y) const;
Index: src/mathed/math_gridinset.h
===================================================================
--- src/mathed/math_gridinset.h (Revision 13267)
+++ src/mathed/math_gridinset.h (Arbeitskopie)
@@ -101,6 +101,8 @@ public:
void drawWithMargin(PainterInfo & pi, int x, int y,
int lmargin = 0, int rmargin = 0) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
Index: src/mathed/math_sqrtinset.h
===================================================================
--- src/mathed/math_sqrtinset.h (Revision 13267)
+++ src/mathed/math_sqrtinset.h (Arbeitskopie)
@@ -24,6 +24,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void drawT(TextPainter &, int x, int y) const;
Index: src/mathed/math_boxedinset.h
===================================================================
--- src/mathed/math_boxedinset.h (Revision 13267)
+++ src/mathed/math_boxedinset.h (Arbeitskopie)
@@ -27,6 +27,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
Index: src/mathed/math_mboxinset.h
===================================================================
--- src/mathed/math_mboxinset.h (Revision 13267)
+++ src/mathed/math_mboxinset.h (Arbeitskopie)
@@ -29,6 +29,8 @@ public:
///
void drawSelection(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
bool inMathed() const { return false; }
///
bool isActive() const { return true; }
Index: src/mathed/math_fontoldinset.h
===================================================================
--- src/mathed/math_fontoldinset.h (Revision 13267)
+++ src/mathed/math_fontoldinset.h (Arbeitskopie)
@@ -31,6 +31,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
+ ///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
Index: src/mathed/math_dotsinset.h
===================================================================
--- src/mathed/math_dotsinset.h (Revision 13267)
+++ src/mathed/math_dotsinset.h (Arbeitskopie)
@@ -27,6 +27,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
std::string name() const;
protected:
/// cache for the thing's height
Index: src/mathed/math_xyarrowinset.h
===================================================================
--- src/mathed/math_xyarrowinset.h (Revision 13267)
+++ src/mathed/math_xyarrowinset.h (Arbeitskopie)
@@ -31,6 +31,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
MathXYArrowInset * asXYArrowInset() { return this; }
///
Index: src/mathed/math_macroarg.h
===================================================================
--- src/mathed/math_macroarg.h (Revision 13267)
+++ src/mathed/math_macroarg.h (Arbeitskopie)
@@ -26,6 +26,8 @@ public:
///
void draw(PainterInfo &, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
std::size_t number() const { return number_; }
///
InsetBase::Code lyxCode() const { return MATHMACROARG_CODE; }
Index: src/mathed/math_kerninset.h
===================================================================
--- src/mathed/math_kerninset.h (Revision 13267)
+++ src/mathed/math_kerninset.h (Arbeitskopie)
@@ -32,6 +32,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
void write(WriteStream & os) const;
///
void normalize(NormalStream & ns) const;
Index: src/mathed/math_unknowninset.h
===================================================================
--- src/mathed/math_unknowninset.h (Revision 13267)
+++ src/mathed/math_unknowninset.h (Arbeitskopie)
@@ -26,6 +26,8 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
+ EDITABLE editable() const { return NOT_EDITABLE; }
+ ///
void setName(std::string const & name);
///
std::string name() const;