mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36:00 +02:00
Ctrl+Alt+Up/Down support, QuickFind Ctrl+D fixes
This commit is contained in:
parent
2ce4ec2e3f
commit
adb7a2bdef
8 changed files with 259 additions and 110 deletions
|
@ -68,6 +68,7 @@ namespace Beefy.theme.dark
|
|||
public Range? mLineRange;
|
||||
|
||||
protected static uint32[] sDefaultColors = new uint32[] ( Color.White ) ~ delete _;
|
||||
public static bool sDebugMultiCursor;
|
||||
|
||||
public float LineHeight => Math.Max(Math.Round(mFont.GetLineSpacing() * mLineHeightScale), 1);
|
||||
|
||||
|
@ -573,7 +574,7 @@ namespace Beefy.theme.dark
|
|||
|
||||
bool drewCursor = false;
|
||||
|
||||
void DrawCursor(float x, float y)
|
||||
void DrawCursor(float x, float y, bool isSecondary = false)
|
||||
{
|
||||
if (mHiliteCurrentLine && selStartIdx == selEndIdx)
|
||||
{
|
||||
|
@ -618,8 +619,18 @@ namespace Beefy.theme.dark
|
|||
}
|
||||
else
|
||||
{
|
||||
float cursorY = y + textYOffset;
|
||||
float cursorHeight = fontLineSpacing;
|
||||
float cursorWidth = Math.Max(1.0f, GS!(1));
|
||||
|
||||
if ((sDebugMultiCursor) && (mTextCursors.Count > 1))
|
||||
{
|
||||
if (isSecondary)
|
||||
cursorColor.A = (.)(cursorColor.A * 0.5f);
|
||||
}
|
||||
|
||||
using (g.PushColor(Color.Mult(cursorColor, Color.Get(brightness))))
|
||||
g.FillRect(x, y + textYOffset, Math.Max(1.0f, GS!(1)), fontLineSpacing);
|
||||
g.FillRect(x, cursorY, cursorWidth, cursorHeight);
|
||||
}
|
||||
drewCursor = true;
|
||||
}
|
||||
|
@ -859,8 +870,7 @@ namespace Beefy.theme.dark
|
|||
y = mLineCoords[eStartLine];
|
||||
}
|
||||
|
||||
using (g.PushColor(0xFF80FFB3))
|
||||
DrawCursor(x, y);
|
||||
DrawCursor(x, y, true);
|
||||
}
|
||||
SetTextCursor(prevTextCursor);
|
||||
}
|
||||
|
|
|
@ -2801,9 +2801,11 @@ namespace Beefy.widgets
|
|||
}
|
||||
}
|
||||
|
||||
public override void KeyDown(KeyCode keyCode, bool isRepeat)
|
||||
public virtual void HandleKey(KeyCode keyCode, KeyFlags keyFlags, bool isRepeat)
|
||||
{
|
||||
base.KeyDown(keyCode, isRepeat);
|
||||
bool shiftDown = keyFlags.HasFlag(.Shift);
|
||||
bool ctrlDown = keyFlags.HasFlag(.Ctrl);
|
||||
bool altDown = keyFlags.HasFlag(.Alt);
|
||||
|
||||
if (keyCode == KeyCode.Escape)
|
||||
{
|
||||
|
@ -2871,7 +2873,7 @@ namespace Beefy.widgets
|
|||
{
|
||||
bool doVirtualMove = true;
|
||||
|
||||
if ((mWidgetWindow.IsKeyDown(KeyCode.Shift)) || (mWidgetWindow.IsKeyDown(KeyCode.Control)))
|
||||
if ((shiftDown) || (ctrlDown))
|
||||
doVirtualMove = false;
|
||||
else
|
||||
{
|
||||
|
@ -2907,7 +2909,7 @@ namespace Beefy.widgets
|
|||
|
||||
|
||||
wasMoveKey = true;
|
||||
SelectLeft(lineIdx, lineChar, mWidgetWindow.IsKeyDown(KeyCode.Control), mWidgetWindow.IsKeyDown(KeyCode.Alt));
|
||||
SelectLeft(lineIdx, lineChar, ctrlDown, altDown);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2919,7 +2921,7 @@ namespace Beefy.widgets
|
|||
{
|
||||
bool doVirtualMove = true;
|
||||
|
||||
if ((mWidgetWindow.IsKeyDown(KeyCode.Shift)) || (mWidgetWindow.IsKeyDown(KeyCode.Control)))
|
||||
if ((shiftDown) || (ctrlDown))
|
||||
doVirtualMove = false;
|
||||
else
|
||||
{
|
||||
|
@ -2947,7 +2949,7 @@ namespace Beefy.widgets
|
|||
}
|
||||
|
||||
wasMoveKey = true;
|
||||
SelectRight(lineIdx, lineChar, mWidgetWindow.IsKeyDown(KeyCode.Control), mWidgetWindow.IsKeyDown(KeyCode.Alt));
|
||||
SelectRight(lineIdx, lineChar, ctrlDown, altDown);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2956,7 +2958,8 @@ namespace Beefy.widgets
|
|||
case KeyCode.Down:
|
||||
{
|
||||
int32 aDir = (keyCode == KeyCode.Up) ? -1 : 1;
|
||||
if ((HasSelection()) && (!mWidgetWindow.IsKeyDown(KeyCode.Shift)))
|
||||
|
||||
if ((HasSelection()) && (!shiftDown))
|
||||
{
|
||||
if (mAllowVirtualCursor)
|
||||
{
|
||||
|
@ -2972,7 +2975,7 @@ namespace Beefy.widgets
|
|||
|
||||
GetCursorLineChar(out lineIdx, out lineChar);
|
||||
|
||||
if (mWidgetWindow.IsKeyDown(KeyCode.Control))
|
||||
if (ctrlDown)
|
||||
{
|
||||
mEditWidget.VertScrollTo(mEditWidget.mVertPos.mDest + aDir * mEditWidget.mScrollContentContainer.mHeight * 0.25f);
|
||||
EnsureCursorVisible(false);
|
||||
|
@ -3028,7 +3031,7 @@ namespace Beefy.widgets
|
|||
case KeyCode.Home:
|
||||
PrepareForCursorMove(-1);
|
||||
wasMoveKey = true;
|
||||
if (mWidgetWindow.IsKeyDown(KeyCode.Control))
|
||||
if (ctrlDown)
|
||||
CursorToStart();
|
||||
else
|
||||
CursorToLineStart(true);
|
||||
|
@ -3037,7 +3040,7 @@ namespace Beefy.widgets
|
|||
case KeyCode.End:
|
||||
PrepareForCursorMove(1);
|
||||
wasMoveKey = true;
|
||||
if (mWidgetWindow.IsKeyDown(KeyCode.Control))
|
||||
if (ctrlDown)
|
||||
{
|
||||
CursorToEnd();
|
||||
}
|
||||
|
@ -3185,7 +3188,7 @@ namespace Beefy.widgets
|
|||
|
||||
if (wasMoveKey)
|
||||
{
|
||||
if (mWidgetWindow.IsKeyDown(KeyCode.Shift))
|
||||
if (shiftDown)
|
||||
{
|
||||
if (!HasSelection())
|
||||
{
|
||||
|
@ -3200,6 +3203,12 @@ namespace Beefy.widgets
|
|||
EnsureCursorVisible();
|
||||
}
|
||||
}
|
||||
|
||||
public override void KeyDown(KeyCode keyCode, bool isRepeat)
|
||||
{
|
||||
base.KeyDown(keyCode, isRepeat);
|
||||
HandleKey(keyCode, mWidgetWindow.GetKeyFlags(true), isRepeat);
|
||||
}
|
||||
|
||||
public float GetCursorScreenRelY()
|
||||
{
|
||||
|
@ -4350,7 +4359,7 @@ namespace Beefy.widgets
|
|||
return !((lhsSelection.mEndPos <= rhsSelection.mStartPos) || (rhsSelection.mEndPos <= lhsSelection.mStartPos));
|
||||
}
|
||||
|
||||
public void AddSelectionToNextFindMatch(bool createCursor = true, bool exhaustiveSearch = false)
|
||||
public virtual void AddSelectionToNextFindMatch(bool createCursor = true, bool exhaustiveSearch = false)
|
||||
{
|
||||
SetPrimaryTextCursor();
|
||||
|
||||
|
@ -4432,6 +4441,38 @@ namespace Beefy.widgets
|
|||
{
|
||||
AddSelectionToNextFindMatch(createCursor: false);
|
||||
}
|
||||
|
||||
public void AddMultiCursor(int32 dir)
|
||||
{
|
||||
var refTextCursor = mCurrentTextCursor;
|
||||
var refTextPos = CursorTextPos;
|
||||
|
||||
for (var cursor in mTextCursors)
|
||||
{
|
||||
SetTextCursor(cursor);
|
||||
var textPos = CursorTextPos;
|
||||
|
||||
if (Math.Sign(textPos <=> refTextPos) == dir)
|
||||
{
|
||||
refTextCursor = cursor;
|
||||
refTextPos = textPos;
|
||||
}
|
||||
}
|
||||
|
||||
var newCursor = new TextCursor(-1, refTextCursor);
|
||||
mTextCursors.Add(newCursor);
|
||||
|
||||
SetTextCursor(mTextCursors.Back);
|
||||
var startCursorPos = CursorLineAndColumn;
|
||||
HandleKey((dir < 0) ? .Up : .Down, .None, false);
|
||||
bool moved = startCursorPos != CursorLineAndColumn;
|
||||
SetPrimaryTextCursor();
|
||||
if (!moved)
|
||||
{
|
||||
mTextCursors.Remove(newCursor);
|
||||
delete newCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class EditWidget : ScrollableWidget
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue