mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Better statement moving
This commit is contained in:
parent
4c69cb6f62
commit
4f5a981598
1 changed files with 98 additions and 39 deletions
|
@ -2150,7 +2150,7 @@ namespace IDE.ui
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Normal,
|
Normal,
|
||||||
Method
|
Declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementKind GetStatementRange(int startCheckPos, StatementRangeFlags flags, out int startIdx, out int endIdx, out char8 endChar)
|
StatementKind GetStatementRange(int startCheckPos, StatementRangeFlags flags, out int startIdx, out int endIdx, out char8 endChar)
|
||||||
|
@ -2160,11 +2160,14 @@ namespace IDE.ui
|
||||||
endIdx = -1;
|
endIdx = -1;
|
||||||
endChar = 0;
|
endChar = 0;
|
||||||
|
|
||||||
|
if (mData.mTextLength == 0)
|
||||||
|
return .None;
|
||||||
|
|
||||||
GetLineCharAtIdx(startCheckPos, var line, var lineChar);
|
GetLineCharAtIdx(startCheckPos, var line, var lineChar);
|
||||||
GetBlockStart(line, var foundBlockStartIdx, var blockOpenSpaceCount);
|
GetBlockStart(line, var foundBlockStartIdx, var blockOpenSpaceCount);
|
||||||
|
|
||||||
if (foundBlockStartIdx < 0)
|
if (foundBlockStartIdx < 0)
|
||||||
return .None;
|
foundBlockStartIdx = 0;
|
||||||
|
|
||||||
bool expectingStatement = true;
|
bool expectingStatement = true;
|
||||||
int stmtCommentStart = -1;
|
int stmtCommentStart = -1;
|
||||||
|
@ -2176,13 +2179,15 @@ namespace IDE.ui
|
||||||
int lastCrPos = -1;
|
int lastCrPos = -1;
|
||||||
int braceCount = 0;
|
int braceCount = 0;
|
||||||
int innerBraceCount = 0;
|
int innerBraceCount = 0;
|
||||||
bool hadOuterMethodColoring = false;
|
bool hadOuterDeclaration = false;
|
||||||
int lastOpenBrace = -1;
|
int lastOpenBrace = -1;
|
||||||
int lastCloseBrace = -1;
|
int lastCloseBrace = -1;
|
||||||
|
|
||||||
int commentLineStart = -1;
|
int commentLineStart = -1;
|
||||||
int commentStart = -1;
|
int commentStart = -1;
|
||||||
bool lineIsComment = false;
|
bool lineIsComment = false;
|
||||||
|
bool lineHasComment = false;
|
||||||
|
bool prevLineHasComment = false;
|
||||||
bool lineHasNonComment = false;
|
bool lineHasNonComment = false;
|
||||||
|
|
||||||
for (int checkPos = foundBlockStartIdx; true; checkPos++)
|
for (int checkPos = foundBlockStartIdx; true; checkPos++)
|
||||||
|
@ -2200,8 +2205,9 @@ namespace IDE.ui
|
||||||
commentStart = -1;
|
commentStart = -1;
|
||||||
commentLineStart = -1;
|
commentLineStart = -1;
|
||||||
}
|
}
|
||||||
lineIsComment = false;
|
prevLineHasComment = lineHasComment;
|
||||||
lineHasNonComment = false;
|
lineHasNonComment = false;
|
||||||
|
lineHasComment = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkC.IsWhiteSpace)
|
if (checkC.IsWhiteSpace)
|
||||||
|
@ -2210,6 +2216,7 @@ namespace IDE.ui
|
||||||
let displayType = (SourceElementType)mData.mText[checkPos].mDisplayTypeId;
|
let displayType = (SourceElementType)mData.mText[checkPos].mDisplayTypeId;
|
||||||
if (displayType == .Comment)
|
if (displayType == .Comment)
|
||||||
{
|
{
|
||||||
|
lineHasComment = true;
|
||||||
if (!lineHasNonComment)
|
if (!lineHasNonComment)
|
||||||
{
|
{
|
||||||
if (commentStart == -1)
|
if (commentStart == -1)
|
||||||
|
@ -2255,31 +2262,33 @@ namespace IDE.ui
|
||||||
if (parenCount != 0)
|
if (parenCount != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (displayType == .Method)
|
if ((displayType == .Method) || (displayType == .Type) || (displayType == .RefType) || (displayType == .Interface))
|
||||||
hadOuterMethodColoring = true;
|
hadOuterDeclaration = true;
|
||||||
|
|
||||||
if ((displayType == .Normal) &&
|
if ((displayType == .Normal) &&
|
||||||
((checkC == '{') || (checkC == '}') || (checkC == ';')))
|
((checkC == '{') || (checkC == '}') || (checkC == ';')))
|
||||||
{
|
{
|
||||||
if (checkC == '{')
|
if (checkC == '{')
|
||||||
{
|
{
|
||||||
lastOpenBrace = checkPos;
|
if (braceCount == 0)
|
||||||
|
lastOpenBrace = checkPos;
|
||||||
braceCount++;
|
braceCount++;
|
||||||
}
|
}
|
||||||
if (checkC == '}')
|
if (checkC == '}')
|
||||||
{
|
{
|
||||||
lastCloseBrace = checkPos;
|
|
||||||
braceCount--;
|
braceCount--;
|
||||||
|
if (braceCount == 0)
|
||||||
|
lastCloseBrace = checkPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((checkPos >= startCheckPos) && (!expectingStatement))
|
if ((checkPos >= startCheckPos) && (!expectingStatement))
|
||||||
{
|
{
|
||||||
if (checkC == '{')
|
if (checkC == '{')
|
||||||
{
|
{
|
||||||
if (hadOuterMethodColoring)
|
if (hadOuterDeclaration)
|
||||||
statementKind = .Method;
|
statementKind = .Declaration;
|
||||||
|
|
||||||
if ((flags.HasFlag(.IncludeBlock)) || (statementKind == .Method))
|
if ((flags.HasFlag(.IncludeBlock)) || (statementKind == .Declaration))
|
||||||
{
|
{
|
||||||
innerBraceCount++;
|
innerBraceCount++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -2302,7 +2311,7 @@ namespace IDE.ui
|
||||||
}
|
}
|
||||||
|
|
||||||
expectingStatement = true;
|
expectingStatement = true;
|
||||||
hadOuterMethodColoring = false;
|
hadOuterDeclaration = false;
|
||||||
}
|
}
|
||||||
else if (expectingStatement)
|
else if (expectingStatement)
|
||||||
{
|
{
|
||||||
|
@ -2314,7 +2323,10 @@ namespace IDE.ui
|
||||||
|
|
||||||
expectingStatement = false;
|
expectingStatement = false;
|
||||||
stmtStart = checkPos;
|
stmtStart = checkPos;
|
||||||
stmtCommentStart = commentStart;
|
if (prevLineHasComment)
|
||||||
|
stmtCommentStart = commentStart;
|
||||||
|
else
|
||||||
|
stmtCommentStart = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastNonWS = checkPos;
|
lastNonWS = checkPos;
|
||||||
|
@ -2325,11 +2337,11 @@ namespace IDE.ui
|
||||||
return .None;
|
return .None;
|
||||||
|
|
||||||
// If out starting pos is within a method then select the whole thing
|
// If out starting pos is within a method then select the whole thing
|
||||||
if ((startCheckPos >= lastOpenBrace) && (startCheckPos <= lastCloseBrace) && (braceCount != 0))
|
if ((startCheckPos >= lastOpenBrace) && (startCheckPos <= lastCloseBrace) /*&& (braceCount != 0)*/)
|
||||||
{
|
{
|
||||||
let checkStmtKind = GetStatementRange(Math.Max(lastOpenBrace - 1, 0), .None, var checkStartIdx, var checkEndIdx, var checkEndChar);
|
let checkStmtKind = GetStatementRange(Math.Max(lastOpenBrace - 1, 0), .None, var checkStartIdx, var checkEndIdx, var checkEndChar);
|
||||||
//if ((checkStmtKind == .Method) && (startCheckPos >= checkStartIdx) && (startCheckPos <= checkEndIdx))
|
if ((checkStmtKind == .Declaration) && (startCheckPos >= checkStartIdx) && (startCheckPos <= checkEndIdx) /*&& (checkStartIdx > foundBlockStartIdx)*/)
|
||||||
if (checkStmtKind == .Method)
|
//if (checkStmtKind == .Method)
|
||||||
{
|
{
|
||||||
startIdx = checkStartIdx;
|
startIdx = checkStartIdx;
|
||||||
endIdx = checkEndIdx;
|
endIdx = checkEndIdx;
|
||||||
|
@ -2380,6 +2392,7 @@ namespace IDE.ui
|
||||||
|
|
||||||
var prevCursorLineAndColumn = CursorLineAndColumn;
|
var prevCursorLineAndColumn = CursorLineAndColumn;
|
||||||
var str = scope String();
|
var str = scope String();
|
||||||
|
int startSelPos = mSelection.Value.MinPos;
|
||||||
ExtractString(mSelection.Value.MinPos, mSelection.Value.Length, str);
|
ExtractString(mSelection.Value.MinPos, mSelection.Value.Length, str);
|
||||||
DeleteSelection();
|
DeleteSelection();
|
||||||
|
|
||||||
|
@ -2394,11 +2407,27 @@ namespace IDE.ui
|
||||||
GetLinePosition(Math.Max(offsetLinePos, 0), var offsetLineStart, var offsetLineEnd);
|
GetLinePosition(Math.Max(offsetLinePos, 0), var offsetLineStart, var offsetLineEnd);
|
||||||
String offsetText = scope .();
|
String offsetText = scope .();
|
||||||
ExtractString(offsetLineStart, offsetLineEnd - offsetLineStart, offsetText);
|
ExtractString(offsetLineStart, offsetLineEnd - offsetLineStart, offsetText);
|
||||||
|
bool needsBlankLine = false;
|
||||||
|
|
||||||
if (isStatementAware)
|
if (isStatementAware)
|
||||||
{
|
{
|
||||||
if (movingDown)
|
if (movingDown)
|
||||||
{
|
{
|
||||||
|
if (IsLineWhiteSpace(offsetLinePos - 1))
|
||||||
|
{
|
||||||
|
// Allow moving methods with spaces between them
|
||||||
|
GetLinePosition(Math.Max(offsetLinePos, 0), var toLineStart, var toLineEnd);
|
||||||
|
if (GetStatementRange(toLineStart, .AllowInnerMethodSelect, var stmtStartIdx, var stmtEndIdx, var stmtEndChar) == .Declaration)
|
||||||
|
{
|
||||||
|
if (startSelPos < stmtStartIdx)
|
||||||
|
{
|
||||||
|
needsBlankLine = true;
|
||||||
|
CursorLineAndColumn = .(offsetLinePos - 1, 0);
|
||||||
|
DeleteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GetLinePosition(Math.Max(offsetLinePos - 1, 0), var toLineStart, var toLineEnd);
|
GetLinePosition(Math.Max(offsetLinePos - 1, 0), var toLineStart, var toLineEnd);
|
||||||
String txt = scope .();
|
String txt = scope .();
|
||||||
ExtractString(toLineStart, toLineEnd - toLineStart, txt);
|
ExtractString(toLineStart, toLineEnd - toLineStart, txt);
|
||||||
|
@ -2413,13 +2442,12 @@ namespace IDE.ui
|
||||||
if (stmtEndChar == '{')
|
if (stmtEndChar == '{')
|
||||||
offsetLinePos++;
|
offsetLinePos++;
|
||||||
}
|
}
|
||||||
else if (GetStatementRange(toLineStart, .AllowInnerMethodSelect, var stmtStartIdx, var stmtEndIdx, var stmtEndChar) == .Method)
|
else if (GetStatementRange(toLineStart, .AllowInnerMethodSelect, var stmtStartIdx, var stmtEndIdx, var stmtEndChar) == .Declaration)
|
||||||
{
|
{
|
||||||
if (stmtStartIdx <= toLineStart)
|
if (stmtEndIdx <= toLineEnd)
|
||||||
{
|
{
|
||||||
GetLineCharAtIdx(stmtEndIdx, var endLine, var endChar);
|
GetLineCharAtIdx(stmtEndIdx, var endLine, var endChar);
|
||||||
//if (offsetLinePos)
|
offsetLinePos = endLine;
|
||||||
offsetLinePos = endLine + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2429,19 +2457,50 @@ namespace IDE.ui
|
||||||
String txt = scope .();
|
String txt = scope .();
|
||||||
ExtractString(toLineStart, toLineEnd - toLineStart, txt);
|
ExtractString(toLineStart, toLineEnd - toLineStart, txt);
|
||||||
|
|
||||||
if (GetStatementRange(toLineStart, .None, var stmtStartIdx, var stmtEndIdx, var stmtEndChar) == .None)
|
Move: do
|
||||||
{
|
{
|
||||||
if (stmtEndChar == '{')
|
if (IsLineWhiteSpace(offsetLinePos))
|
||||||
GetLinePosition(Math.Max(offsetLinePos - 1, 0), out toLineStart, out toLineEnd);
|
{
|
||||||
}
|
// Allow moving methods with spaces between them
|
||||||
|
GetLinePosition(Math.Max(offsetLinePos - 1, 0), var checkLineStart, var checkLineEnd);
|
||||||
|
if (GetStatementRange(checkLineStart, .AllowInnerMethodSelect, var stmtStartIdx, var stmtEndIdx, var stmtEndChar) == .Declaration)
|
||||||
|
{
|
||||||
|
if (startSelPos >= stmtEndIdx)
|
||||||
|
{
|
||||||
|
CursorLineAndColumn = .(offsetLinePos, 0);
|
||||||
|
DeleteLine();
|
||||||
|
offsetLinePos--;
|
||||||
|
GetLinePosition(Math.Max(offsetLinePos, 0), out toLineStart, out toLineEnd);
|
||||||
|
str.Append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (GetStatementRange(toLineStart, .AllowInnerMethodSelect, var stmtStartIdx, var stmtEndIdx, var stmtEndChar) != .None)
|
var stmtKind = GetStatementRange(toLineStart, .None, var stmtStartIdx, var stmtEndIdx, var stmtEndChar);
|
||||||
{
|
if (stmtKind == .Declaration)
|
||||||
String stmt = scope .();
|
{
|
||||||
ExtractString(stmtStartIdx, stmtEndIdx - stmtStartIdx, stmt);
|
// Don't move past method start
|
||||||
GetLineCharAtIdx(stmtStartIdx, var stmtLine, var stmtLineChar);
|
offsetLinePos++;
|
||||||
offsetLinePos = stmtLine;
|
break Move;
|
||||||
GetLinePosition(Math.Max(offsetLinePos, 0), out offsetLineStart, out offsetLineEnd);
|
}
|
||||||
|
|
||||||
|
if (stmtKind == .None)
|
||||||
|
{
|
||||||
|
if (stmtEndChar == '{')
|
||||||
|
GetLinePosition(Math.Max(offsetLinePos - 1, 0), out toLineStart, out toLineEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetStatementRange(toLineStart, .AllowInnerMethodSelect, out stmtStartIdx, out stmtEndIdx, out stmtEndChar) != .None)
|
||||||
|
{
|
||||||
|
if (startSelPos >= stmtEndIdx)
|
||||||
|
{
|
||||||
|
String stmt = scope .();
|
||||||
|
ExtractString(stmtStartIdx, stmtEndIdx - stmtStartIdx, stmt);
|
||||||
|
GetLineCharAtIdx(stmtStartIdx, var stmtLine, var stmtLineChar);
|
||||||
|
offsetLinePos = stmtLine;
|
||||||
|
GetLinePosition(Math.Max(offsetLinePos, 0), out offsetLineStart, out offsetLineEnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2458,13 +2517,13 @@ namespace IDE.ui
|
||||||
String txt = scope .();
|
String txt = scope .();
|
||||||
ExtractLine(offsetLinePos, txt);
|
ExtractLine(offsetLinePos, txt);
|
||||||
|
|
||||||
if ((isStatementAware) && (LineIsComment(offsetLinePos - 1)))
|
if ((isStatementAware) && (offsetLinePos > 0) && (LineIsComment(offsetLinePos - 1)) && (movingDown))
|
||||||
|
needsBlankLine = true;
|
||||||
|
|
||||||
|
if (needsBlankLine)
|
||||||
{
|
{
|
||||||
if (movingDown)
|
InsertAtCursor("\n");
|
||||||
{
|
wantCursorPos.mLine++;
|
||||||
InsertAtCursor("\n");
|
|
||||||
wantCursorPos.mLine++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PasteText(str, "line");
|
PasteText(str, "line");
|
||||||
|
@ -2498,7 +2557,7 @@ namespace IDE.ui
|
||||||
int checkPos = stmtEnd;
|
int checkPos = stmtEnd;
|
||||||
int selEnd = stmtEnd;
|
int selEnd = stmtEnd;
|
||||||
|
|
||||||
for ( ; checkPos < mData.mTextLength - 1; checkPos++)
|
for ( ; checkPos < mData.mTextLength; checkPos++)
|
||||||
{
|
{
|
||||||
char8 checkC = mData.mText[checkPos].mChar;
|
char8 checkC = mData.mText[checkPos].mChar;
|
||||||
selEnd = checkPos + 1;
|
selEnd = checkPos + 1;
|
||||||
|
@ -2513,7 +2572,7 @@ namespace IDE.ui
|
||||||
|
|
||||||
mSelection = .(lineStart, selEnd);
|
mSelection = .(lineStart, selEnd);
|
||||||
|
|
||||||
int toLine = lineNum + (int)dir;
|
int toLine = Math.Clamp(lineNum + (int)dir, 0, GetLineCount());
|
||||||
if (dir == .Down)
|
if (dir == .Down)
|
||||||
{
|
{
|
||||||
GetLineCharAtIdx(selEnd, var line, var lineChar);
|
GetLineCharAtIdx(selEnd, var line, var lineChar);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue