Jelajahi Sumber

Fixed some indenting issues, added indenting test

Brian Fiete 5 tahun lalu
induk
melakukan
e5de09488e

+ 13 - 1
BeefLibs/Beefy2D/src/widgets/EditWidget.bf

@@ -1548,7 +1548,19 @@ namespace Beefy.widgets
             int lineChar;
             GetLineCharAtIdx(textPos, out line, out lineChar);
 
-            bool wasLineEnd = mData.mText[textPos].mChar == '\n';
+            bool wasLineEnd = false;
+			for (int i = textPos; i < mData.mTextLength; i++)
+			{
+				char8 c = mData.mText[i].mChar;
+				if (c == '\n')
+				{
+					wasLineEnd = true;
+					break;
+				}
+				else if (!c.IsWhiteSpace)
+					break;
+			}
+
             String lineText = scope String();
             GetLineText(line, lineText);
 

+ 9 - 0
IDE/Tests/IndentTest/BeefProj.toml

@@ -0,0 +1,9 @@
+FileVersion = 1
+
+[Project]
+Name = "IDETest"
+TargetType = "BeefWindowsApplication"
+StartupObject = "IDETest.Program"
+
+[Configs.Debug.Win64]
+BeefLibType = "DynamicDebug"

+ 12 - 0
IDE/Tests/IndentTest/BeefSpace.toml

@@ -0,0 +1,12 @@
+FileVersion = 1
+Projects = {IDETest = {Path = "."}}
+Unlocked = ["corlib"]
+
+[Workspace]
+StartupProject = "IDETest"
+
+[Configs.Debug.Win64]
+IntermediateType = "ObjectAndIRCode"
+
+[Configs.Debug.Win32]
+IntermediateType = "ObjectAndIRCode"

+ 46 - 0
IDE/Tests/IndentTest/scripts/Indent01.txt

@@ -0,0 +1,46 @@
+ShowFile("src/Indent01.bf")
+
+GotoText("//Test01")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 17)
+
+GotoText("//Test02")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 21)
+
+GotoText("//Test03")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 21)
+
+GotoText("//Test04")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 25)
+
+GotoText("//Test05")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 25)
+
+GotoText("//Test06")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 21)
+
+GotoText("//Test07")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 25)
+
+GotoText("//Test08")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 21)
+
+GotoText("//Test09")
+AdjustCursor(0, -1)
+CursorToLineEnd()
+AssertIsAtColumn("Indent01.bf", 17)

+ 100 - 0
IDE/Tests/IndentTest/src/Indent01.bf

@@ -0,0 +1,100 @@
+namespace IDETest
+{
+	class Indent01
+	{
+		static void Test01()
+		{
+			if (true)
+
+			//Test01
+		}
+
+		static void Test02()
+		{
+			if (true)
+				if (true)
+
+			//Test02
+		}
+
+		static void Test03()
+		{
+			if (true)
+				if (true)
+					;
+			    else
+
+			//Test03
+		}
+
+		static void Test04()
+		{
+			if (true)
+				if (true)
+					for ()
+
+			//Test04
+		}
+
+		static void Test05()
+		{
+			if (true)
+				if (true)
+					;
+			    else
+					for ()
+
+			//Test05
+		}
+
+		static void Test06()
+		{
+			if (true)
+				if (true)
+					;
+			    else if (true)
+
+			//Test06
+		}
+
+		static void Test07()
+		{
+			if (true)
+				if (true)
+					;
+			    else if (true)
+					for (int i < 10)
+
+			//Test07
+		}
+
+		static void Test08()
+		{
+			if (true)
+				if (true)
+					;
+			    else if (true)
+					for (int i < 10)
+						;
+			    else
+
+			//Test08
+		}
+
+		static void Test09()
+		{
+			if (true)
+				if (true)
+					;
+			    else if (true)
+					for (int i < 10)
+						;
+			    else
+					;
+
+			for (int i < 20)
+
+			//Test09
+		}
+	}
+}

+ 25 - 13
IDE/src/ui/SourceEditWidgetContent.bf

@@ -828,6 +828,7 @@ namespace IDE.ui
 			int ifDepth = 0;
 			bool isDoingCtl = false;
 			bool justFinishedCtlCond = false;
+			bool justFinishedCtl = false;
 			int ctlDepth = 0; // for, while, using
 
 			int extraTab = 1;
@@ -906,20 +907,25 @@ namespace IDE.ui
 				{
 					if (blockDepth == 0)
 					{
+						if (((justFinishedIf) || (justFinishedCtl)) && (keywordStr != "else"))
+						{
+							// This catches the case of:
+							// if (a) Thing();
+							// if (b) ...
+							ifDepth = 0;
+							justFinishedIf = false;
+							ifCtlDepthStack.Clear();
+							ctlDepth = 0;
+
+							isDoingCtl = false;
+						}
+
+						justFinishedCtl = false;
+						justFinishedIf = false;
+						
 						switch (keywordStr)
 						{
 						case "if":
-							if (justFinishedIf)
-							{
-								// This catches the case of:
-								// if (a) Thing();
-								// if (b) ...
-								ifDepth = 0;
-								justFinishedIf = false;
-								ifCtlDepthStack.Clear();
-								ctlDepth = 0;
-							}
-							
 							if (isDoingCtl)
 							{
 								ctlDepth++;
@@ -947,7 +953,11 @@ namespace IDE.ui
 								caseStartPos = checkIdx - 4;
 								inCaseExpr = true;
 							}
+						case "switch":
+							ifDepth = 0;
 						}
+
+						doingElse = keywordStr == "else";
 					}
 
 					keywordStr.Clear();
@@ -1052,6 +1062,9 @@ namespace IDE.ui
 						startedWithType = false;
 						checkedStartedWithType = false;
 
+						if (isDoingCtl)
+							justFinishedCtl = true;
+
 						if (ifDepth == 0)
 						{
 							isDoingCtl = false;
@@ -1075,7 +1088,6 @@ namespace IDE.ui
 							doingElse = false;
 						}
 
-
 						if (justFinishedIf)
 						{
 							// We had a non-else statement
@@ -1092,7 +1104,6 @@ namespace IDE.ui
 						if (ifDepth > 0)
 							justFinishedIf = true;
 
-						//NEW
 						inCaseExpr = false;
 						inCaseExprNext = false;
 						inCaseExprNextLine = false;
@@ -1147,6 +1158,7 @@ namespace IDE.ui
 				
 			}
 
+
 			if ((ctlDepth > 0) && ((!justFinishedIf) || (insertingElseStmt)))
 				extraTab += ctlDepth;
 

+ 8 - 0
bin/test_ide.bat

@@ -31,6 +31,14 @@ PUSHD %~dp0..\
 @CALL :TEST
 @IF !ERRORLEVEL! NEQ 0 GOTO HADERROR
 
+@SET TESTPATH=IDE\Tests\BugW002
+@CALL :TEST
+@IF !ERRORLEVEL! NEQ 0 GOTO HADERROR
+
+@SET TESTPATH=IDE\Tests\IndentTest
+@CALL :TEST
+@IF !ERRORLEVEL! NEQ 0 GOTO HADERROR
+
 @GOTO :EMPTYTEST
 
 :TEST