Skip to content

Commit

Permalink
Add a new option to auto-trim single lines.
Browse files Browse the repository at this point in the history
When pasting a single line ending in newline, the user is presented with a
warning about pasting multi-line strings. This enables a new option to
automatically strip trailing newlines whenever we detect that a single line
string has been pasted. This prevents the warning and allows the user to more
conveniently edit single lines pasted into the console.
  • Loading branch information
miabrahams committed Aug 9, 2018
1 parent 0a4f947 commit 652c07e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/ConEmu/ConEmu.rc
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ BEGIN
CONTROL "First line",rPasteM2FirstLine,"Button",BS_AUTORADIOBUTTON,206,41,78,8
CONTROL "Single line",rPasteM2SingleLine,"Button",BS_AUTORADIOBUTTON,288,26,78,8
CONTROL "Do nothing",rPasteM2Nothing,"Button",BS_AUTORADIOBUTTON,288,41,78,8
GROUPBOX "Confirm critical actions",gbPasteConfirm,10,80,364,64,WS_GROUP
GROUPBOX "Confirm critical actions",gbPasteConfirm,10,80,364,79,WS_GROUP
CONTROL "Multi-line paste: avoid unexpected command execution by <Enter> keypress",cbClipConfirmEnter,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,93,355,8
CONTROL "Long text paste: avoid non-responsive console until the paste finishes",cbClipConfirmLimit,
Expand All @@ -922,6 +922,8 @@ BEGIN
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,56,163,10
CONTROL "Allow Windows to POSIX path conversion",cbPasteM2Posix,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,206,56,163,10
CONTROL "Automatically remove newline when pasting single line",cbAutoTrimSingleLine,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,141,253,10
END

IDD_SPG_ENVIRONMENT DIALOGEX 0, 0, 381, 242
Expand Down Expand Up @@ -1665,6 +1667,10 @@ END
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_CMDPROMPT, DIALOG
BEGIN
END

IDD_SPG_PASTE, DIALOG
BEGIN
END
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,7 @@ void Settings::LoadSettings(bool& rbNeedCreateVanilla, const SettingsStorage* ap
reg->Load(L"CTS.ColorIndex", isCTSColorIndex); if (CONFORECOLOR(isCTSColorIndex) == CONBACKCOLOR(isCTSColorIndex)) isCTSColorIndex = DefaultSelectionConsoleColor;

reg->Load(L"ClipboardConfirmEnter", isPasteConfirmEnter);
reg->Load(L"AutoTrimSingleLine", isAutoTrimSingleLine);
reg->Load(L"ClipboardConfirmLonger", nPasteConfirmLonger);

reg->Load(L"FarGotoEditorOpt", isFarGotoEditor);
Expand Down Expand Up @@ -3794,6 +3795,7 @@ BOOL Settings::SaveSettings(BOOL abSilent /*= FALSE*/, const SettingsStorage* ap
reg->Save(L"CTS.ColorIndex", isCTSColorIndex);

reg->Save(L"ClipboardConfirmEnter", isPasteConfirmEnter);
reg->Save(L"AutoTrimSingleLine", isAutoTrimSingleLine);
reg->Save(L"ClipboardConfirmLonger", nPasteConfirmLonger);

reg->Save(L"FarGotoEditorOpt", isFarGotoEditor);
Expand Down
2 changes: 2 additions & 0 deletions src/ConEmu/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ struct Settings
BYTE isCTSColorIndex;
//reg->Load(L"ClipboardConfirmEnter", isPasteConfirmEnter);
bool isPasteConfirmEnter;
//reg->Load(L"AutoTrimSingleLine", isAutoTrimSingleLine);
bool isAutoTrimSingleLine;
//reg->Load(L"ClipboardConfirmLonger", nPasteConfirmLonger);
UINT nPasteConfirmLonger;
//reg->Load(L"FarGotoEditorOpt", isFarGotoEditor);
Expand Down
13 changes: 13 additions & 0 deletions src/ConEmu/RealConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12477,6 +12477,19 @@ void CRealConsole::Paste(CEPasteMode PasteMode /*= pm_Standard*/, LPCWSTR asText

// Смотрим первую строку / наличие второй
wchar_t* pszRN = wcspbrk(pszBuf, L"\r\n");

// If user has enabled AutoTrimSingleLine, check if we are pasting a single line string.
// If so, set PasteMode to pm_OneLine to remove trailing newlines.
if (pszRN && gpSet->isAutoTrimSingleLine) {
wchar_t* pszNext = pszRN;
while ((*pszNext == L'\r') || (*pszNext == L'\n')) {
pszNext++;
}
if (!wcspbrk(pszNext, L"\r\n")) {
PasteMode = pm_OneLine;
}
}

if (PasteMode == pm_OneLine)
{
LPCWSTR pszEnd = pszBuf + nBufLen;
Expand Down
3 changes: 3 additions & 0 deletions src/ConEmu/SetDlgButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,9 @@ bool CSetDlgButtons::ProcessButtonClick(HWND hDlg, WORD CB, BYTE uCheck)
case cbClipConfirmEnter:
CSetPgPaste::OnBtn_ClipConfirmEnter(hDlg, CB, uCheck);
break;
case cbAutoTrimSingleLine:
CSetPgPaste::OnBtn_AutoTrimSingleLine(hDlg, CB, uCheck);
break;
case cbClipConfirmLimit:
CSetPgPaste::OnBtn_ClipConfirmLimit(hDlg, CB, uCheck);
break;
Expand Down
12 changes: 12 additions & 0 deletions src/ConEmu/SetPgPaste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ LRESULT CSetPgPaste::OnInitDialog(HWND hDlg, bool abInitial)
checkDlgButton(hDlg, cbPasteM2Posix, (gpSet->AppStd.isPosixFirstLine != pxm_Intact) ? BST_CHECKED : BST_UNCHECKED);

checkDlgButton(hDlg, cbClipConfirmEnter, gpSet->isPasteConfirmEnter);
checkDlgButton(hDlg, cbAutoTrimSingleLine, gpSet->isAutoTrimSingleLine);

checkDlgButton(hDlg, cbClipConfirmLimit, (gpSet->nPasteConfirmLonger!=0));
SetDlgItemInt(hDlg, tClipConfirmLimit, gpSet->nPasteConfirmLonger, FALSE);
Expand Down Expand Up @@ -153,6 +154,17 @@ void CSetPgPaste::OnBtn_ClipConfirmEnter(HWND hDlg, WORD CB, BYTE uCheck)

} // cbClipConfirmEnter


// cbAutoTrimSingleLine
void CSetPgPaste::OnBtn_AutoTrimSingleLine(HWND hDlg, WORD CB, BYTE uCheck)
{
_ASSERTE(CB == cbAutoTrimSingleLine);

gpSet->isAutoTrimSingleLine = (uCheck != BST_UNCHECKED);

} // cbAutoTrimSingleLine


// cbClipConfirmLimit
void CSetPgPaste::OnBtn_ClipConfirmLimit(HWND hDlg, WORD CB, BYTE uCheck)
{
Expand Down
1 change: 1 addition & 0 deletions src/ConEmu/SetPgPaste.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CSetPgPaste
static void OnBtn_ClipCtrlV(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_ClipPosixCvt(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_ClipConfirmEnter(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_AutoTrimSingleLine(HWND hDlg, WORD CB, BYTE uCheck);
static void OnBtn_ClipConfirmLimit(HWND hDlg, WORD CB, BYTE uCheck);

protected:
Expand Down
3 changes: 2 additions & 1 deletion src/ConEmu/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@
#define cbRestoreInactive 3099
#define cbInactiveCursorSubstHidden 3100
#define vkCheckUpdates 3101
#define cbAutoTrimSingleLine 3102
#define IDC_STATIC -1

// Next default values for new objects
Expand All @@ -1346,7 +1347,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 246
#define _APS_NEXT_COMMAND_VALUE 40010
#define _APS_NEXT_CONTROL_VALUE 3102
#define _APS_NEXT_CONTROL_VALUE 3103
#define _APS_NEXT_SYMED_VALUE 130
#endif
#endif

0 comments on commit 652c07e

Please sign in to comment.