mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Improved QuickFind behavior
This commit is contained in:
parent
90d1891cf1
commit
b6e2be1e99
7 changed files with 123 additions and 44 deletions
|
@ -2940,6 +2940,7 @@ namespace Beefy.widgets
|
|||
case Unknown;
|
||||
case SelectRight;
|
||||
case SelectLeft;
|
||||
case QuickFind;
|
||||
|
||||
public bool IsFromTyping => (this == FromTyping) || (this == FromTyping_Deleting);
|
||||
}
|
||||
|
|
|
@ -1068,6 +1068,16 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
extension List<T> where T : delete
|
||||
{
|
||||
public void ClearAndDeleteItems()
|
||||
{
|
||||
for (var item in this)
|
||||
delete item;
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
extension List<T> where T : String
|
||||
{
|
||||
public bool Contains(T item, StringComparison comparison)
|
||||
|
|
|
@ -697,4 +697,14 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Queue<T> where T : delete
|
||||
{
|
||||
public void ClearAndDeleteItems()
|
||||
{
|
||||
for (var item in this)
|
||||
delete item;
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5241,6 +5241,12 @@ namespace IDE
|
|||
var sourceViewPanel = GetActiveSourceViewPanel();
|
||||
if ((sourceViewPanel != null) && (sourceViewPanel.HasFocus()))
|
||||
{
|
||||
if ((sourceViewPanel?.mQuickFind?.mIsShowingMatches == true) && (sourceViewPanel.mQuickFind.mFindEditWidget.mHasFocus))
|
||||
{
|
||||
sourceViewPanel.SetFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
var sourceEditWidgetContent = (SourceEditWidgetContent)sourceViewPanel.mEditWidget.mEditWidgetContent;
|
||||
if (sourceEditWidgetContent.IsAtCurrentHistory())
|
||||
{
|
||||
|
|
|
@ -128,7 +128,6 @@ namespace IDE.ui
|
|||
if (content.mData.mText[i].mChar == '\n')
|
||||
{
|
||||
isMultiline = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,6 +153,8 @@ namespace IDE.ui
|
|||
mFindEditWidget.SetText(text);
|
||||
mFindEditWidget.Content.SelectAll();
|
||||
}
|
||||
|
||||
content.mSelection = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,8 +275,10 @@ namespace IDE.ui
|
|||
return foundFlags;
|
||||
}
|
||||
|
||||
public void FindAll()
|
||||
public void FindAll(bool doSelect = true)
|
||||
{
|
||||
Debug.WriteLine($"FindAll({doSelect})");
|
||||
|
||||
mIsShowingMatches = true;
|
||||
mFoundMatches = false;
|
||||
|
||||
|
@ -285,6 +288,16 @@ namespace IDE.ui
|
|||
//mSearchDidWrap = false;
|
||||
|
||||
ClearFlags(true, true);
|
||||
if (mSelectionStart != null)
|
||||
{
|
||||
var data = mEditWidget.Content.mData;
|
||||
for (int i in mSelectionStart.mIndex..<mSelectionEnd.mIndex)
|
||||
{
|
||||
data.mText[i].mDisplayFlags |= (uint8)SourceElementFlags.Find_CurrentSelection;
|
||||
}
|
||||
}
|
||||
|
||||
if (doSelect)
|
||||
FindNext(1, true, ErrorReportType.None);
|
||||
int32 curFindIdx = mCurFindIdx;
|
||||
while (FindNext(1, false, ErrorReportType.None))
|
||||
|
@ -292,6 +305,8 @@ namespace IDE.ui
|
|||
}
|
||||
mCurFindIdx = curFindIdx;
|
||||
mCurFindCount = 0;
|
||||
|
||||
Debug.WriteLine($"FindAll CurFindIdx{mCurFindIdx} CurFindStart:{mCurFindStart}");
|
||||
}
|
||||
|
||||
public void ShowCurrentSelection()
|
||||
|
@ -305,13 +320,16 @@ namespace IDE.ui
|
|||
if (findText.Length == 0)
|
||||
return;
|
||||
var editWidgetContent = mEditWidget.Content;
|
||||
editWidgetContent.MoveCursorToIdx(mCurFindIdx + (int32)findText.Length, true);
|
||||
editWidgetContent.MoveCursorToIdx(mCurFindIdx + (int32)findText.Length, true, .QuickFind);
|
||||
|
||||
for (int32 idx = mCurFindIdx; idx < mCurFindIdx + findText.Length; idx++)
|
||||
|
||||
editWidgetContent.mSelection = EditSelection(mCurFindIdx, mCurFindIdx + (int32)findText.Length);
|
||||
|
||||
/*for (int32 idx = mCurFindIdx; idx < mCurFindIdx + findText.Length; idx++)
|
||||
{
|
||||
uint8 flags = (uint8)SourceElementFlags.Find_CurrentSelection;
|
||||
mEditWidget.Content.mData.mText[idx].mDisplayFlags = (uint8)(mEditWidget.Content.mData.mText[idx].mDisplayFlags | flags);
|
||||
}
|
||||
}*/
|
||||
|
||||
if ((mSelectionStart == null) || (mParent == null))
|
||||
{
|
||||
|
@ -328,6 +346,17 @@ namespace IDE.ui
|
|||
}
|
||||
}
|
||||
|
||||
public void SetFindIdx(int idx, bool resetFind)
|
||||
{
|
||||
mCurFindIdx = (.)idx;
|
||||
mLastActiveCursorPos = mCurFindIdx;
|
||||
if (resetFind)
|
||||
{
|
||||
mCurFindCount = 0;
|
||||
mCurFindStart = mCurFindIdx;
|
||||
}
|
||||
}
|
||||
|
||||
public void FindNext(int32 dir, bool showMessage)
|
||||
{
|
||||
var editWidgetContent = mEditWidget.Content;
|
||||
|
@ -351,7 +380,6 @@ namespace IDE.ui
|
|||
|
||||
if (FindNext(dir, true, showMessage ? ErrorReportType.MessageBox : ErrorReportType.Sound))
|
||||
{
|
||||
ClearFlags(false, true);
|
||||
ShowCurrentSelection();
|
||||
}
|
||||
}
|
||||
|
@ -388,16 +416,21 @@ namespace IDE.ui
|
|||
String findTextUpper = scope String(findText);
|
||||
findTextUpper.ToUpper();
|
||||
|
||||
if ((mCurFindIdx == -1) && (mSelectionStart != null))
|
||||
{
|
||||
mCurFindIdx = mSelectionStart.mIndex - 1;
|
||||
}
|
||||
|
||||
int32 selStart = (mSelectionStart != null) ? mSelectionStart.mIndex : 0;
|
||||
int32 selEnd = (mSelectionEnd != null) ? mSelectionEnd.mIndex : editContent.mData.mTextLength;
|
||||
|
||||
mCurFindStart = Math.Max(mCurFindStart, selStart);
|
||||
|
||||
|
||||
/*mCurFindStart = Math.Clamp(mCurFindStart, selStart, selEnd - (.)findText.Length);*/
|
||||
if (mCurFindIdx != -1)
|
||||
mCurFindIdx = Math.Clamp(mCurFindIdx, selStart, selEnd - (.)findText.Length);
|
||||
|
||||
if ((mCurFindIdx == -1) && (mSelectionStart != null) && (dir > 0))
|
||||
{
|
||||
mCurFindIdx = mSelectionStart.mIndex - 1;
|
||||
}
|
||||
|
||||
int32 nextIdx = -1;
|
||||
int32 searchStartIdx;
|
||||
|
||||
|
@ -565,10 +598,18 @@ namespace IDE.ui
|
|||
|
||||
SourceElementFlags findFlags = replaceAll ? .Find_Matches : .Find_CurrentSelection;
|
||||
|
||||
if (!replaceAll)
|
||||
{
|
||||
if (!ewc.HasSelection())
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
int32 selEnd = -1;
|
||||
int32 selStart = -1;
|
||||
if (replaceAll)
|
||||
{
|
||||
var text = mEditWidget.Content.mData.mText;
|
||||
for (int32 i = searchStart; i < mEditWidget.Content.mData.mTextLength; i++)
|
||||
{
|
||||
|
@ -599,6 +640,9 @@ namespace IDE.ui
|
|||
selection.mStartPos = selStart;
|
||||
selection.mEndPos = selEnd + 1;
|
||||
ewc.mSelection = selection;
|
||||
}
|
||||
else
|
||||
selStart = (.)ewc.mSelection.Value.MinPos;
|
||||
EditWidgetContent.InsertFlags insertFlags = .NoMoveCursor | .NoRestoreSelectionOnUndo | .IsGroupPart;
|
||||
if (searchCount == 0)
|
||||
insertFlags |= .IsGroupStart;
|
||||
|
@ -611,6 +655,9 @@ namespace IDE.ui
|
|||
searchCount++;
|
||||
DataUpdated();
|
||||
|
||||
if (!replaceAll)
|
||||
break;
|
||||
|
||||
/*if (flags == (byte)SourceElementFlags.Find_CurrentSelection)
|
||||
{
|
||||
mLastTextVersion = mEditWidget.Content.mCurTextVersionId;
|
||||
|
@ -638,7 +685,7 @@ namespace IDE.ui
|
|||
if (mLastTextVersion != mEditWidget.Content.mData.mCurTextVersionId)
|
||||
{
|
||||
if (mIsShowingMatches)
|
||||
FindAll();
|
||||
FindAll(false);
|
||||
DataUpdated();
|
||||
}
|
||||
|
||||
|
|
|
@ -716,7 +716,7 @@ namespace IDE.ui
|
|||
|
||||
if ((flags & (uint8)SourceElementFlags.Find_CurrentSelection) != 0)
|
||||
{
|
||||
using (g.PushColor(0x80FFE0B0))
|
||||
using (g.PushColor(0x504C575C))
|
||||
g.FillRect(x, y, width, mFont.GetLineSpacing());
|
||||
|
||||
DrawSectionFlagsOver(g, x, y, width, (uint8)(flags & ~(uint8)(SourceElementFlags.Find_CurrentSelection | .Find_Matches)));
|
||||
|
@ -4840,6 +4840,11 @@ namespace IDE.ui
|
|||
|
||||
public override void PhysCursorMoved(CursorMoveKind moveKind)
|
||||
{
|
||||
if (moveKind != .QuickFind)
|
||||
{
|
||||
mSourceViewPanel?.mQuickFind?.SetFindIdx(CursorTextPos, !moveKind.IsFromTyping);
|
||||
}
|
||||
|
||||
if (mVirtualCursorPos != null)
|
||||
{
|
||||
CheckCollapseOpen(mVirtualCursorPos.Value.mLine, moveKind);
|
||||
|
|
|
@ -1698,7 +1698,7 @@ namespace IDE.ui
|
|||
{
|
||||
if ((mHoverResolveTask != null) && (mHoverResolveTask.mCursorPos == resolveParams.mOverrideCursorPos))
|
||||
{
|
||||
mHoverResolveTask.mResult = new String(autocompleteInfo);
|
||||
mHoverResolveTask.mResult = new String(autocompleteInfo ?? "");
|
||||
}
|
||||
|
||||
resolveParams.mResultString = new String(autocompleteInfo);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue