From b6e2be1e995e75db34b428a2bf23545c7c37c3be Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 1 Mar 2022 06:11:28 -0800 Subject: [PATCH] Improved QuickFind behavior --- BeefLibs/Beefy2D/src/widgets/EditWidget.bf | 1 + BeefLibs/corlib/src/Collections/List.bf | 10 ++ BeefLibs/corlib/src/Collections/Queue.bf | 10 ++ IDE/src/IDEApp.bf | 6 + IDE/src/ui/QuickFind.bf | 131 ++++++++++++++------- IDE/src/ui/SourceEditWidgetContent.bf | 7 +- IDE/src/ui/SourceViewPanel.bf | 2 +- 7 files changed, 123 insertions(+), 44 deletions(-) diff --git a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf index 35f8f8ea..de2618f5 100644 --- a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf +++ b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf @@ -2940,6 +2940,7 @@ namespace Beefy.widgets case Unknown; case SelectRight; case SelectLeft; + case QuickFind; public bool IsFromTyping => (this == FromTyping) || (this == FromTyping_Deleting); } diff --git a/BeefLibs/corlib/src/Collections/List.bf b/BeefLibs/corlib/src/Collections/List.bf index 16496e2f..ac36e595 100644 --- a/BeefLibs/corlib/src/Collections/List.bf +++ b/BeefLibs/corlib/src/Collections/List.bf @@ -1068,6 +1068,16 @@ namespace System.Collections } } + extension List where T : delete + { + public void ClearAndDeleteItems() + { + for (var item in this) + delete item; + Clear(); + } + } + extension List where T : String { public bool Contains(T item, StringComparison comparison) diff --git a/BeefLibs/corlib/src/Collections/Queue.bf b/BeefLibs/corlib/src/Collections/Queue.bf index f92b9a63..9cd72a57 100644 --- a/BeefLibs/corlib/src/Collections/Queue.bf +++ b/BeefLibs/corlib/src/Collections/Queue.bf @@ -697,4 +697,14 @@ namespace System.Collections } } } + + extension Queue where T : delete + { + public void ClearAndDeleteItems() + { + for (var item in this) + delete item; + Clear(); + } + } } diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index 7ed18857..2356b543 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -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()) { diff --git a/IDE/src/ui/QuickFind.bf b/IDE/src/ui/QuickFind.bf index 80f4f7f3..9a6fa6e8 100644 --- a/IDE/src/ui/QuickFind.bf +++ b/IDE/src/ui/QuickFind.bf @@ -128,7 +128,6 @@ namespace IDE.ui if (content.mData.mText[i].mChar == '\n') { isMultiline = true; - break; } } @@ -154,7 +153,9 @@ namespace IDE.ui mFindEditWidget.SetText(text); mFindEditWidget.Content.SelectAll(); } - } + + content.mSelection = null; + } } public ~this() @@ -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,13 +288,25 @@ namespace IDE.ui //mSearchDidWrap = false; ClearFlags(true, true); - FindNext(1, true, ErrorReportType.None); + if (mSelectionStart != null) + { + var data = mEditWidget.Content.mData; + for (int i in mSelectionStart.mIndex.. 0)) + { + mCurFindIdx = mSelectionStart.mIndex - 1; + } + int32 nextIdx = -1; int32 searchStartIdx; @@ -565,40 +598,51 @@ 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; - var text = mEditWidget.Content.mData.mText; - for (int32 i = searchStart; i < mEditWidget.Content.mData.mTextLength; i++) - { - if ((text[i].mDisplayFlags & (uint8)findFlags) != 0) - { - if (selStart == -1) - selStart = i; - selEnd = i; - } - else if (selEnd != -1) - break; - } + int32 selEnd = -1; + int32 selStart = -1; + if (replaceAll) + { + var text = mEditWidget.Content.mData.mText; + for (int32 i = searchStart; i < mEditWidget.Content.mData.mTextLength; i++) + { + if ((text[i].mDisplayFlags & (uint8)findFlags) != 0) + { + if (selStart == -1) + selStart = i; + selEnd = i; + } + else if (selEnd != -1) + break; + } - if (selStart == -1) - break; + if (selStart == -1) + break; - int32 selLen = selEnd - selStart + 1; - Debug.Assert(selLen % findText.Length == 0); - selEnd = selStart + (int32)findText.Length - 1; + int32 selLen = selEnd - selStart + 1; + Debug.Assert(selLen % findText.Length == 0); + selEnd = selStart + (int32)findText.Length - 1; - if (searchCount == 0) - { - undoBatchStart = new UndoBatchStart("replace"); - ewc.mData.mUndoManager.Add(undoBatchStart); - } + if (searchCount == 0) + { + undoBatchStart = new UndoBatchStart("replace"); + ewc.mData.mUndoManager.Add(undoBatchStart); + } - EditSelection selection = EditSelection(); - selection.mStartPos = selStart; - selection.mEndPos = selEnd + 1; - ewc.mSelection = selection; + EditSelection selection = EditSelection(); + 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(); } diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index 78ee73fa..a6148989 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -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); diff --git a/IDE/src/ui/SourceViewPanel.bf b/IDE/src/ui/SourceViewPanel.bf index e2c1782c..a2ae1773 100644 --- a/IDE/src/ui/SourceViewPanel.bf +++ b/IDE/src/ui/SourceViewPanel.bf @@ -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);