1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-13 22:04:09 +02:00

Improved handling of char pairs

This commit is contained in:
Brian Fiete 2020-11-30 09:47:14 -08:00
parent e93c44703b
commit 77946cafdf

View file

@ -2707,7 +2707,7 @@ namespace IDE.ui
mAutoComplete.CloseListWindow();*/ mAutoComplete.CloseListWindow();*/
} }
bool IsCurrentPairClosing(int cursorIdx) bool IsCurrentPairClosing(int cursorIdx, bool removeOnFind = false)
{ {
mData.mTextIdData.Prepare(); mData.mTextIdData.Prepare();
int32 closeId = mData.mTextIdData.GetIdAtIndex(cursorIdx); int32 closeId = mData.mTextIdData.GetIdAtIndex(cursorIdx);
@ -2718,9 +2718,13 @@ namespace IDE.ui
{ {
int openCursorIdx = mData.mTextIdData.GetIndexFromId(openId); int openCursorIdx = mData.mTextIdData.GetIndexFromId(openId);
if (openCursorIdx != -1) if (openCursorIdx != -1)
{
if (removeOnFind)
mCurParenPairIdSet.Remove(openId);
return true; return true;
} }
} }
}
return false; return false;
} }
@ -3124,7 +3128,7 @@ namespace IDE.ui
{ {
if ((mData.mText[checkPos].mDisplayTypeId == (int32)wantElementType) && if ((mData.mText[checkPos].mDisplayTypeId == (int32)wantElementType) &&
((keyChar == '"') || (keyChar == '\'') || (keyChar == ')') || (keyChar == ']') || (keyChar == '>') || (keyChar == '}')) && ((keyChar == '"') || (keyChar == '\'') || (keyChar == ')') || (keyChar == ']') || (keyChar == '>') || (keyChar == '}')) &&
(IsCurrentPairClosing(cursorTextPos))) (IsCurrentPairClosing(cursorTextPos, true)))
{ {
mJustInsertedCharPair = false; mJustInsertedCharPair = false;
CursorTextPos++; CursorTextPos++;
@ -4177,7 +4181,26 @@ namespace IDE.ui
if (moveKind != .FromTyping) if (moveKind != .FromTyping)
{ {
mCurParenPairIdSet.Clear(); int cursorIdx = CursorTextPos;
mData.mTextIdData.Prepare();
List<int32> removeList = scope .();
for (var openId in mCurParenPairIdSet)
{
int openIdx = mData.mTextIdData.GetIndexFromId(openId);
int closeIdx = mData.mTextIdData.GetIndexFromId(openId + 1);
bool wantRemove = false;
if ((openIdx == -1) || (closeIdx == -1))
wantRemove = true;
if ((cursorIdx <= openIdx) || (cursorIdx > closeIdx))
wantRemove = true;
if (wantRemove)
removeList.Add(openId);
}
for (var openId in removeList)
mCurParenPairIdSet.Remove(openId);
} }
base.PhysCursorMoved(moveKind); base.PhysCursorMoved(moveKind);