Bug 134793 - problem with automaticly complete of \begin{env}
Summary: problem with automaticly complete of \begin{env}
Status: RESOLVED FIXED
Alias: None
Product: kile
Classification: Applications
Component: general (show other bugs)
Version: 1.8.1
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Jeroen Wijnhout
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-28 18:18 UTC by Ralf Butenuth
Modified: 2006-11-21 20:13 UTC (History)
1 user (show)

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 Ralf Butenuth 2006-09-28 18:18:28 UTC
Version:           1.8.1 (using KDE 3.5.2, Kubuntu Package 4:3.5.2-0ubuntu18.1 dapper)
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.15-27-686

Kile produces a wrong auto-completition if I have two \begin{env} -Statements in one line!

Example:
If i have the following code:
 
Let \begin{env} foo \end{env} and \begin{env} bar \end{env} 

and hit enter at the end of the line, it makes an third \end{env} appear below the second \begin{env}. Quit annoying.

Thanks, Ralf
Comment 1 Thomas Braun 2006-10-05 20:25:26 UTC
Hello,

please try the newest version 1.9.2, 1.8 is pretty old.
If you also have the problem with the newest version, I can have a look.

Thanks
Thomas Braun
Comment 2 Ralf Butenuth 2006-10-05 22:09:09 UTC
Thanks. Bug still exists in Kile 1.9.2 with KDE 3.5.2 on my machine. 
Comment 3 R (Chandra) Chandrasekhar 2006-10-11 09:32:55 UTC
I can confirm that with Kile 1.8.1 KDE 3.5.4 in Kubuntu Dapper, \begin{env} does not autocomplete with \end{env} even if that box is checked in Kile settings.

I will wait for Edgy to see if it persists in the new kile.
Comment 4 Thomas Braun 2006-11-17 12:47:53 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;
 }
 
Comment 5 Ralf Butenuth 2006-11-21 20:13:37 UTC
Thanks a lot Thomas for fixing that bug.
It now workes perfectly from Kile 1.9.3 on.