mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36:00 +02:00
Added line copying to copy/cut/paste
This commit is contained in:
parent
9242cb0dc5
commit
d807049b9f
5 changed files with 124 additions and 65 deletions
|
@ -777,25 +777,41 @@ namespace Beefy
|
|||
|
||||
public virtual bool GetClipboardText(String outStr)
|
||||
{
|
||||
int32 aSize;
|
||||
void* clipboardData = GetClipboardData("text", out aSize);
|
||||
if (clipboardData == null)
|
||||
return false;
|
||||
return GetClipboardTextData("text", outStr);
|
||||
}
|
||||
|
||||
outStr.Append((char8*)clipboardData);
|
||||
public virtual bool GetClipboardText(String outStr, String extra)
|
||||
{
|
||||
GetClipboardTextData("bf_text", extra);
|
||||
return GetClipboardTextData("text", outStr);
|
||||
}
|
||||
|
||||
public bool GetClipboardTextData(String format, String outStr)
|
||||
{
|
||||
int32 aSize;
|
||||
void* clipboardData = GetClipboardData(format, out aSize);
|
||||
if (clipboardData == null)
|
||||
return false;
|
||||
|
||||
outStr.Append((char8*)clipboardData);
|
||||
ReleaseClipboardData(clipboardData);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetClipboardData(String format, void* ptr, int32 size, bool resetClipboard)
|
||||
{
|
||||
BFApp_SetClipboardData(format, ptr, size, resetClipboard ? 1 : 0);
|
||||
}
|
||||
|
||||
public void SetClipboardText(String text, String extra)
|
||||
{
|
||||
SetClipboardData("text", text.CStr(), (int32)text.Length + 1, true);
|
||||
SetClipboardData("bf_text", extra.CStr(), (int32)extra.Length + 1, false);
|
||||
}
|
||||
|
||||
public virtual void SetClipboardText(String text)
|
||||
{
|
||||
//IntPtr aPtr = Marshal.StringToCoTaskMemUni(text);
|
||||
SetClipboardData("text", text.CStr(), (int32)text.Length + 1, true);
|
||||
SetClipboardText(text, "");
|
||||
}
|
||||
|
||||
#if STUDIO_CLIENT
|
||||
|
|
|
@ -2001,35 +2001,93 @@ namespace Beefy.widgets
|
|||
InsertAtCursor(text);
|
||||
}
|
||||
|
||||
public void CutText()
|
||||
void CopyText(bool cut)
|
||||
{
|
||||
if (!CheckReadOnly())
|
||||
{
|
||||
bool selectedLine = false;
|
||||
String extra = scope .();
|
||||
if (!HasSelection())
|
||||
{
|
||||
selectedLine = true;
|
||||
GetLinePosition(CursorLineAndColumn.mLine, var lineStart, var lineEnd);
|
||||
mSelection = .(lineStart, lineEnd);
|
||||
extra.Append("line");
|
||||
}
|
||||
|
||||
String selText = scope String();
|
||||
GetSelectionText(selText);
|
||||
if (!selText.IsEmpty)
|
||||
{
|
||||
BFApp.sApp.SetClipboardText(selText);
|
||||
DeleteSelection();
|
||||
BFApp.sApp.SetClipboardText(selText, extra);
|
||||
if (cut)
|
||||
{
|
||||
if (selectedLine)
|
||||
{
|
||||
// Remove \n
|
||||
if (mSelection.Value.mEndPos < mData.mTextLength)
|
||||
mSelection.ValueRef.mEndPos++;
|
||||
}
|
||||
DeleteSelection();
|
||||
}
|
||||
|
||||
if (selectedLine)
|
||||
mSelection = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void CutText()
|
||||
{
|
||||
CopyText(true);
|
||||
}
|
||||
|
||||
public void CopyText()
|
||||
{
|
||||
String selText = scope String();
|
||||
GetSelectionText(selText);
|
||||
if (!selText.IsEmpty)
|
||||
BFApp.sApp.SetClipboardText(selText);
|
||||
CopyText(false);
|
||||
}
|
||||
|
||||
public void PasteText(String text, String extra)
|
||||
{
|
||||
if (extra == "line")
|
||||
{
|
||||
UndoBatchStart undoBatchStart = new UndoBatchStart("paste");
|
||||
mData.mUndoManager.Add(undoBatchStart);
|
||||
var origPosition = CursorLineAndColumn;
|
||||
CursorLineAndColumn = .(origPosition.mLine, 0);
|
||||
var lineStartPosition = CursorLineAndColumn;
|
||||
InsertAtCursor("\n");
|
||||
CursorLineAndColumn = lineStartPosition;
|
||||
CursorToLineStart(false);
|
||||
|
||||
// Adjust to requested column
|
||||
if (CursorLineAndColumn.mColumn != 0)
|
||||
{
|
||||
for (let c in text.RawChars)
|
||||
{
|
||||
if (!c.IsWhiteSpace)
|
||||
{
|
||||
text.Remove(0, @c.Index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PasteText(text);
|
||||
CursorLineAndColumn = origPosition;
|
||||
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
|
||||
}
|
||||
else
|
||||
PasteText(text);
|
||||
}
|
||||
|
||||
public void PasteText()
|
||||
{
|
||||
String aText = scope String();
|
||||
BFApp.sApp.GetClipboardText(aText);
|
||||
String extra = scope .();
|
||||
BFApp.sApp.GetClipboardText(aText, extra);
|
||||
aText.Replace("\r", "");
|
||||
if ((aText != null) && (!CheckReadOnly()))
|
||||
PasteText(aText);
|
||||
{
|
||||
PasteText(aText, extra);
|
||||
}
|
||||
}
|
||||
|
||||
protected void SelectLeft(int lineIdx, int lineChar, bool isChunkMove, bool isWordMove)
|
||||
|
@ -3593,7 +3651,7 @@ namespace Beefy.widgets
|
|||
|
||||
public void FinishScroll()
|
||||
{
|
||||
mVertPos.mPct = 1.0f;
|
||||
mVertPos.mPct = 1.0f;
|
||||
UpdateContentPosition();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue