Bug 137131 - Autocompletion error with LaTeX linebreaks "\\[length]"
Summary: Autocompletion error with LaTeX linebreaks "\\[length]"
Status: RESOLVED FIXED
Alias: None
Product: kile
Classification: Applications
Component: general (show other bugs)
Version: 1.9.2
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Jeroen Wijnhout
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-10 00:26 UTC by Kurt Bennater
Modified: 2006-11-17 12:47 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt Bennater 2006-11-10 00:26:00 UTC
Version:           1.9.2 (using KDE KDE 3.5.5)
Installed from:    SuSE RPMs
OS:                Linux

Hitting Return after a line break command of the form "blabla\\[1cm]" leads to unwanted autocompletion; the editor substitutes a closing "\]" for a formula in displaystyle.
Comment 1 Thomas Braun 2006-11-17 12:47:52 UTC
SVN commit 605593 by tbraun:

BUG: 137131
BUG: 134793


Fix bug where environments were completed which should not have been completed.
Remove selected text in any case if the user insert "


 M  +22 -15    kileedit.cpp  


--- trunk/extragear/office/kile/kile/kileedit.cpp #605592:605593
@@ -2292,7 +2292,9 @@
 	uint row,col;
 	view->cursorPositionReal(&row,&col);
 	Kate::Document *doc = view->getDoc();
-	
+	if(doc)
+		doc->removeSelectedText();
+
 	// simply insert, if we are inside a verb command
 	if ( insideVerb(view) || insideVerbatim(view) )
 	{
@@ -2451,35 +2453,40 @@
 
 bool EditorExtension::shouldCompleteEnv(const QString &env, Kate::View *view)
 {
-	kdDebug() << "===EditorExtension::shouldCompleteEnv(...)===" << endl;
- 	QString envname = env;
-	envname.replace("*","\\*");
+	kdDebug() << "===EditorExtension::shouldCompleteEnv( " << env << " )===" << endl;
 	QRegExp reTestBegin,reTestEnd;
-	if ( envname == "\\[" )
+	if ( env == "\\[" )
 	{
-		reTestBegin.setPattern("\\\\\\[");
-		reTestEnd.setPattern("\\\\\\]");
+		kdDebug() << "display style" << endl;
+		reTestBegin.setPattern("(?:[^\\\\]|^)\\\\\\["); 
+		// the first part is a non-capturing bracket (?:...) and we check if we don't have a backslash in front,
+		//  or that we are at the begin of the line
+		reTestEnd.setPattern("(?:[^\\\\]|^)\\\\\\]");
 	}
 	else
 	{
-		reTestBegin.setPattern("\\\\begin\\s*\\{" + envname + "\\}");
-		reTestEnd.setPattern("\\\\end\\s*\\{" + envname + "\\}");
+		reTestBegin.setPattern("(?:[^\\\\]|^)\\\\begin\\s*\\{" + QRegExp::escape(env) + "\\}");
+		reTestEnd.setPattern("(?:[^\\\\]|^)\\\\end\\s*\\{" + QRegExp::escape(env) + "\\}");
 	}
-	
+
 	int num = view->getDoc()->numLines();
 	int numBeginsFound = 0;
 	int numEndsFound = 0;
 	uint realLine, realColumn;
-	view->cursorPositionReal(&realLine, &realColumn);
+	view->cursorPositionReal(&realLine, &realColumn);	
 	for ( int i = realLine; i < num; ++i)
 	{
 		numBeginsFound += view->getDoc()->textLine(i).contains(reTestBegin);
 		numEndsFound += view->getDoc()->textLine(i).contains(reTestEnd);
-		if ( (numBeginsFound == 1) && (numEndsFound == 1) ) return false;        
-		else if ( (numEndsFound == 0) && (numBeginsFound > 1) ) return true;
-		else if ( (numBeginsFound > 2) || (numEndsFound > 1) ) return true; //terminate the search
+		kdDebug() << "line is " << i <<  " numBeginsFound = " << numBeginsFound <<  " , " << "numEndsFound = " << numEndsFound << endl;
+		if ( numEndsFound >= numBeginsFound )
+			return false;
+		else if ( numEndsFound == 0 && numBeginsFound > 1 )
+			return true;
+		else if ( numBeginsFound > 2 || numEndsFound > 1 )
+			return true; // terminate the search
 	}
-    
+
 	return true;
 }