Skip to content

Commit

Permalink
Make multi-paste correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Nov 9, 2023
1 parent a7ab731 commit 8fb8515
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
4 changes: 2 additions & 2 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ void Notepad_plus::command(int id)
GlobalUnlock(hglbLenCopy);

// Place the handle on the clipboard.
UINT f = RegisterClipboardFormat(CF_NPPTEXTLEN);
SetClipboardData(f, hglbLenCopy);
UINT cf_nppTextLen = RegisterClipboardFormat(CF_NPPTEXTLEN);
SetClipboardData(cf_nppTextLen, hglbLenCopy);

CloseClipboard();

Expand Down
62 changes: 62 additions & 0 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
::SendMessage(_hParent, WM_NOTIFY, LINKTRIGGERED, reinterpret_cast<LPARAM>(&notification));

}
else if (wParam == 'V')
{
if (_isMultiPasteActive)
{
Buffer* buf = getCurrentBuffer();
buf->setUserReadOnly(false);

_isMultiPasteActive = false;
}
}
break;
}

Expand Down Expand Up @@ -570,6 +580,58 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
}
}
break;

case 'V':
{
SHORT ctrl = GetKeyState(VK_CONTROL);
SHORT alt = GetKeyState(VK_MENU);
SHORT shift = GetKeyState(VK_SHIFT);
if ((ctrl & 0x8000) && !(alt & 0x8000) && !(shift & 0x8000))
{
// "MSDEVColumnSelect" is column format from Scintilla
CLIPFORMAT cfColumnSelect = static_cast<CLIPFORMAT>(::RegisterClipboardFormat(TEXT("MSDEVColumnSelect")));
if (IsClipboardFormatAvailable(cfColumnSelect) && OpenClipboard(NULL))
{
HANDLE clipboardData = ::GetClipboardData(CF_UNICODETEXT);
::GlobalSize(clipboardData);
LPVOID clipboardDataPtr = ::GlobalLock(clipboardData);
if (clipboardDataPtr)
{
wstring clipboardStr = (const TCHAR*)clipboardDataPtr;
::GlobalUnlock(clipboardData);
::CloseClipboard();

vector<wstring> stringArray;
stringSplit(clipboardStr, getEOLString(), stringArray);
stringArray.erase(stringArray.cend() - 1); // remove the last empty string

size_t numSelections = execute(SCI_GETSELECTIONS);
if (numSelections > 1 && numSelections == stringArray.size())
{
execute(SCI_BEGINUNDOACTION);
for (int i = 0; i < numSelections; ++i)
{
LRESULT posStart = execute(SCI_GETSELECTIONNSTART, i);
LRESULT posEnd = execute(SCI_GETSELECTIONNEND, i);
replaceTarget(stringArray[i].c_str(), posStart, posEnd);
posStart += stringArray[i].length();
execute(SCI_SETSELECTIONNSTART, i, posStart);
execute(SCI_SETSELECTIONNEND, i, posStart);
}
execute(SCI_ENDUNDOACTION);

// Hack for prevent
//Buffer* buf = getCurrentBuffer();
//buf->setUserReadOnly(true);

_isMultiPasteActive = true;
return TRUE;
}
}
}
}
}
break;
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScintillaComponent/ScintillaEditView.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,8 @@ friend class Finder;
BufferStyleMap _hotspotStyles;

intptr_t _beginSelectPosition = -1;

static std::string _defaultCharList;
bool _isMultiPasteActive = false;

//Lexers and Styling
void restyleBuffer();
Expand Down

0 comments on commit 8fb8515

Please sign in to comment.