From 9772364a6d18fa45c4e68ae2637d745c401656d5 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Sun, 4 Apr 2021 10:37:33 +0200 Subject: [PATCH] fix readonly editwidget deletions --- BeefLibs/Beefy2D/src/widgets/EditWidget.bf | 69 +++++++++++----------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf index ae10afee..70704f0d 100644 --- a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf +++ b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf @@ -1700,29 +1700,29 @@ namespace Beefy.widgets if (keyChar == '\x7F') // Ctrl+Backspace { - int line; - int lineChar; - GetCursorLineChar(out line, out lineChar); + if (!CheckReadOnly()) + { + int line; + int lineChar; + GetCursorLineChar(out line, out lineChar); - int startIdx = CursorTextPos; - SelectLeft(line, lineChar, true, false); - mSelection = EditSelection(CursorTextPos, startIdx); - - var action = new DeleteSelectionAction(this); - action.mMoveCursor = true; - mData.mUndoManager.Add(action); - action.mCursorTextPos = (.)startIdx; - PhysDeleteSelection(true); + int startIdx = CursorTextPos; + SelectLeft(line, lineChar, true, false); + mSelection = EditSelection(CursorTextPos, startIdx); + + var action = new DeleteSelectionAction(this); + action.mMoveCursor = true; + mData.mUndoManager.Add(action); + action.mCursorTextPos = (.)startIdx; + PhysDeleteSelection(true); + } return; } char32 useChar = keyChar; - mCursorBlinkTicks = 0; - - if (useChar == '\x7F') // Ctrl+Backspace - useChar = '\b'; + mCursorBlinkTicks = 0; if (useChar == '\b') { @@ -2511,32 +2511,35 @@ namespace Beefy.widgets case KeyCode.Delete: if (mWidgetWindow.IsKeyDown(.Control)) { - if (mWidgetWindow.IsKeyDown(.Shift)) + if (!CheckReadOnly()) { + if (mWidgetWindow.IsKeyDown(.Shift)) + { + int startIdx = CursorTextPos; + CursorToLineEnd(); + mSelection = EditSelection(CursorTextPos, startIdx); + var action = new DeleteSelectionAction(this); + action.mMoveCursor = true; + mData.mUndoManager.Add(action); + action.mCursorTextPos = (.)startIdx; + PhysDeleteSelection(true); + break; + } + + int line; + int lineChar2; + GetCursorLineChar(out line, out lineChar2); + int startIdx = CursorTextPos; - CursorToLineEnd(); + SelectRight(line, lineChar, true, false); mSelection = EditSelection(CursorTextPos, startIdx); + var action = new DeleteSelectionAction(this); action.mMoveCursor = true; mData.mUndoManager.Add(action); action.mCursorTextPos = (.)startIdx; PhysDeleteSelection(true); - break; } - - int line; - int lineChar2; - GetCursorLineChar(out line, out lineChar2); - - int startIdx = CursorTextPos; - SelectRight(line, lineChar, true, false); - mSelection = EditSelection(CursorTextPos, startIdx); - - var action = new DeleteSelectionAction(this); - action.mMoveCursor = true; - mData.mUndoManager.Add(action); - action.mCursorTextPos = (.)startIdx; - PhysDeleteSelection(true); break; }