Angus Leeming wrote:

> Alfredo Braunstein wrote:
>> The document scrolled down a bit for some reason (and the scrollbar
>> is broken). But the line is there.
> 
> Thank you.
> 
>>> and the dialog is telling us that "Guideby" is unknown.
>> 
>> THis went in when the PosIterator -> DocIterator switch, 'newlines'
>> are not identified as separating words now... I can have a look.
> 
> Thank you.
> 
>>> Thereafter, press "ignore"
>> I'll have at this look tomorrow.
> 
> Ok. I added two print statements. Patch attached.
> 
>                 The LyX User's Guide
>                 by the LyX Team [foot][Principal maintainer of
> this file is Mike Ressler. If you have ...]
> 
> It's something of an eye-opener to see how inefficient this bloody
> thing is, but anyway, here's the crash:

it is still O(n) per user interaction.... (note that getPar is O(1) now). It
could be easily optimized I think, if we need.
 
> getPar: 0 from 1
> getPar: 0 from 1
> getPar: 0 from 1
> getPar: 0 from 1
> getPar: 0 from 1
> getPar: 0 from 1
> getPar: 0 from 1
> checking Ressler
> getPar: 1 from 1
> Assertion triggered in Paragraph& LyXText::getPar(int) const by
> failing check "par < int(paragraphs().size())" in file
> ../../src/text.C:1690
> 
> Program received signal SIGABRT, Aborted.
> 0x00adfc32 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
> 
> Looks like the iteration doesn't get out of the footnote correctly.
> 
> Time for bed.


This is what I had to do for making it work (!).

- restore BufferView::setCursor (I had emptied it out in the ParIterator
patch for some reason, thinking it was not needed any more)
- fix BufferView::putSelectionAt (this should be culled out at the end I
think)
- commented out LyXText::updateLocal. I presume that most of it is uneeded
(mostly all that is view related). It should change name if it is so.
- added InsetText::allowSpellCheck() const { return true; }
- fix small bits of ControlSpellChecker. In particular, use cur.forwardPos
instead of forwardChar (we need paragraph ends to identify word
boundaries). Also added a check for inTexted. (btw, I suspect that
lyx::find also suffers from some of these problems, but for some reason it
seems inactive now)

Patch attached (to be tested).

Alfredo
? ChangeLog-old
? PosIterator.C-save
? PosIterator.h-save
? bfri.C
? safe
? textcursor.C-save
? textcursor.h-save
? insets/insetcollapsable-save.C
? insets/insettext-save.C
? insets/safe
? mathed/safe
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.243
diff -u -p -u -r1.243 BufferView.C
--- BufferView.C	30 Mar 2004 08:18:07 -0000	1.243
+++ BufferView.C	31 Mar 2004 08:19:59 -0000
@@ -367,8 +367,11 @@ LyXText * BufferView::text() const
 
 void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
 {
-	LCursor & cur = cursor();
-	cur.setCursor(makeDocumentIterator(par, pos), false);
+	int const last = par.size();
+	for (int i = 0; i < last; ++i)
+		par[i].inset().edit(cursor(), true);
+
+	cursor().setCursor(makeDocumentIterator(par, pos), false);
 }
 
 
@@ -393,24 +396,24 @@ void BufferView::putSelectionAt(Document
 
 	cursor().clearSelection();
 
-	LyXText & text = *par.text();
+	LyXText & text = *cur[0].text();
 	setCursor(par, cur.pos());
 	
 	// hack for the chicken and egg problem
 	top_y(text.getPar(par.outerPar()).y);
 
 	update();
-	text.setCursor(cursor(), cur.par(), cur.pos());
+	//text.setCursor(cursor(), cur.par(), cur.pos());
 	cursor().updatePos();
 
 	if (length) {
-		setSelectionRange(cursor(), length);
-		cursor().setSelection();
 		if (backwards) {
+			cursor().setSelection(cursor(), -length);
 			DocumentIterator const it = cursor();
-			cursor().setCursor(cursor().anchor_, false);
+			cursor().setCursor(cursor().anchor_, true);
 			cursor().anchor_ = it;
-		}
+		} else
+			cursor().setSelection(cursor(), length);
 	}
 
 	fitCursor();
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.595
diff -u -p -u -r1.595 lyxfunc.C
--- lyxfunc.C	30 Mar 2004 19:18:11 -0000	1.595
+++ lyxfunc.C	31 Mar 2004 08:20:01 -0000
@@ -551,6 +551,7 @@ bool ensureBufferClean(BufferView * bv)
 	return buf.isClean();
 }
 
+
 void showPrintError(string const & name)
 {
 		string str = bformat(_("Could not print the document %1$s.\n"
@@ -559,6 +560,18 @@ void showPrintError(string const & name)
 		Alert::error(_("Print document failed"), str);
 }
 
+
+void getOutOf(LCursor & cur, InsetBase const & in)
+{
+	for (unsigned int i = 0; i != cur.size(); ++i) {
+		if (&cur[i].inset() == &in) {
+			cur.resize(i);
+			return;
+		}
+	}
+}
+
+
 } //namespace anon
 
 
@@ -1272,9 +1285,8 @@ void LyXFunc::dispatch(FuncRequest const
 				if (inset_code == InsetBase::NO_CODE
 				    || inset_code == it->lyxCode()) {
 					it->dispatch(cur, fr);
-					if (&cur.inset() == &*it
-					    && cur.disp_.dispatched())
-						cur.pop();
+					if (cur.disp_.dispatched())
+						getOutOf(cur, *it);
 				}
 			}
 			break;
Index: frontends/controllers/ControlSpellchecker.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlSpellchecker.C,v
retrieving revision 1.66
diff -u -p -u -r1.66 ControlSpellchecker.C
--- frontends/controllers/ControlSpellchecker.C	25 Mar 2004 09:16:27 -0000	1.66
+++ frontends/controllers/ControlSpellchecker.C	31 Mar 2004 08:20:02 -0000
@@ -151,10 +151,11 @@ namespace {
 
 bool isLetter(DocumentIterator const & cur)
 {
-	return !cur.empty()
+	return cur.inTexted()
+		&& cur.inset().allowSpellCheck()
+		&& cur.pos() != cur.lastpos()
 		&& cur.paragraph().isLetter(cur.pos())
 		&& !isDeletedText(cur.paragraph(), cur.pos());
-		//&& (!cur.nextInset() || cur.nextInset()->allowSpellCheck());
 }
 
 
@@ -162,7 +163,7 @@ WordLangTuple nextWord(DocumentIterator 
 	BufferParams & bp)
 {
 	// skip until we have real text (will jump paragraphs)
-	for (; cur.size() && !isLetter(cur); cur.forwardChar());
+	for (; cur.size() && !isLetter(cur); cur.forwardPos());
 		++progress;
 
 	// hit end
@@ -174,7 +175,7 @@ WordLangTuple nextWord(DocumentIterator 
 	string str;
 	// and find the end of the word (insets like optional hyphens
 	// and ligature break are part of a word)
-	for (; cur.size() && isLetter(cur); cur.forwardChar(), ++progress) {
+	for (; cur && isLetter(cur); cur.forwardPos(), ++progress) {
 		if (!cur.paragraph().isInset(cur.pos()))
 			str += cur.paragraph().getChar(cur.pos());
 	}
@@ -203,10 +204,10 @@ void ControlSpellchecker::check()
 	for (start = 0; it != cur; it.forwardPos())
 		++start; 	
 
-	for (total = start; it.size(); it.forwardPos())
+	for (total = start; it; it.forwardPos())
 		++total; 	
 
-	for (; cur.size() && isLetter(cur); cur.forwardPos())
+	for (; cur && isLetter(cur); cur.forwardPos())
 		++start;
 
 	while (res == SpellBase::OK || res == SpellBase::IGNORE) {
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.588
diff -u -p -u -r1.588 insettext.C
--- insets/insettext.C	28 Mar 2004 22:00:22 -0000	1.588
+++ insets/insettext.C	31 Mar 2004 08:20:04 -0000
@@ -294,7 +294,7 @@ void InsetText::edit(LCursor & cur, bool
 	cur.clearSelection();
 	finishUndo();
 	sanitizeEmptyText(cur.bv());
-	updateLocal(cur);
+//	updateLocal(cur);
 }
 
 
Index: insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.255
diff -u -p -u -r1.255 insettext.h
--- insets/insettext.h	28 Mar 2004 22:00:22 -0000	1.255
+++ insets/insettext.h	31 Mar 2004 08:20:04 -0000
@@ -148,6 +148,8 @@ public:
 	ParagraphList const & paragraphs() const;
 	///
 	bool insetAllowed(Code) const { return true; }
+	///
+	bool allowSpellCheck() const { return true; }
 	
 protected:
 	///

Reply via email to