From 3f9b573aade60a4b545fb9b445090613fc5df4b9 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 1 Aug 2013 19:44:11 +0000 Subject: [PATCH] [NEW_FEATURE] (Author: Andreas Jonsson) Add new feature: Ctrl+Alt+Enter insert blank line above the current line, Ctrl+Alt+Shift+Enter insert blank line below the current line. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1094 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.rc | 2 + PowerEditor/src/NppCommands.cpp | 14 +++++ PowerEditor/src/Parameters.cpp | 3 +- .../ScitillaComponent/ScintillaEditView.cpp | 57 +++++++++++++++++++ .../src/ScitillaComponent/ScintillaEditView.h | 3 + PowerEditor/src/menuCmdID.h | 2 + 6 files changed, 80 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 3ccb39462..2d9a897bf 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -258,6 +258,8 @@ BEGIN MENUITEM "Move Down Current Line", IDM_EDIT_LINE_DOWN MENUITEM "Remove Empty Lines", IDM_EDIT_REMOVEEMPTYLINES MENUITEM "Remove Empty Lines (Containing Blank characters)", IDM_EDIT_REMOVEEMPTYLINESWITHBLANK + MENUITEM "Insert Blank Line Above Current", IDM_EDIT_BLANKLINEABOVECURRENT + MENUITEM "Insert Blank Line Below Current", IDM_EDIT_BLANKLINEBELOWCURRENT END POPUP "Comment/Uncomment" BEGIN diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index d1f42e759..9e012182a 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -315,6 +315,18 @@ void Notepad_plus::command(int id) } break; + case IDM_EDIT_BLANKLINEABOVECURRENT: + { + _pEditView->insertNewLineAboveCurrentLine(); + } + break; + + case IDM_EDIT_BLANKLINEBELOWCURRENT: + { + _pEditView->insertNewLineBelowCurrentLine(); + } + break; + case IDM_EDIT_CHAR_PANEL: { launchAnsiCharPanel(); @@ -2481,6 +2493,8 @@ void Notepad_plus::command(int id) case IDM_EDIT_RTL : case IDM_EDIT_LTR : case IDM_EDIT_BEGINENDSELECT: + case IDM_EDIT_BLANKLINEABOVECURRENT: + case IDM_EDIT_BLANKLINEBELOWCURRENT: case IDM_VIEW_FULLSCREENTOGGLE : case IDM_VIEW_ALWAYSONTOP : case IDM_VIEW_WRAP : diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 3bd57fa6f..f3a72a505 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -120,7 +120,8 @@ WinMenuKeyDefinition winKeyDefs[] = { {VK_SPACE, IDM_EDIT_FUNCCALLTIP, true, false, true, NULL}, {VK_R, IDM_EDIT_RTL, true, true, false, NULL}, {VK_L, IDM_EDIT_LTR, true, true, false, NULL}, - + {VK_RETURN, IDM_EDIT_BLANKLINEABOVECURRENT, true, true, false, NULL}, + {VK_RETURN, IDM_EDIT_BLANKLINEBELOWCURRENT, true, true, true, NULL}, {VK_F, IDM_SEARCH_FIND, true, false, false, NULL}, {VK_F, IDM_SEARCH_FINDINFILES, true, false, true, NULL}, {VK_F3, IDM_SEARCH_FINDNEXT, false, false, false, NULL}, diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index c10e45cea..2367e4aec 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -3005,3 +3005,60 @@ void ScintillaEditView::setTabSettings(Lang *lang) execute(SCI_SETUSETABS, !nppgui._tabReplacedBySpace); } } + +void ScintillaEditView::insertNewLineAboveCurrentLine() +{ + const int eol_mode = int(execute(SCI_GETEOLMODE)); + + generic_string newline; + if(eol_mode == SC_EOL_CRLF) + newline = TEXT("\r\n"); + else if(eol_mode == SC_EOL_LF) + newline = TEXT("\n"); + else + newline = TEXT("\r"); + + const int current_line = getCurrentLineNumber(); + if(current_line == 0) + { + // Special handling if caret is at first line. + insertGenericTextFrom(0, newline.c_str()); + } + else + { + const int eol_length = eol_mode == SC_EOL_CRLF ? 2 : 1; + const long position = execute(SCI_POSITIONFROMLINE, current_line) - eol_length; + insertGenericTextFrom(position, newline.c_str()); + } + execute(SCI_SETEMPTYSELECTION, execute(SCI_POSITIONFROMLINE, current_line)); +} + + +void ScintillaEditView::insertNewLineBelowCurrentLine() +{ + const int eol_mode = int(execute(SCI_GETEOLMODE)); + + generic_string newline; + if(eol_mode == SC_EOL_CRLF) + newline = TEXT("\r\n"); + else if(eol_mode == SC_EOL_LF) + newline = TEXT("\n"); + else + newline = TEXT("\r"); + + const int line_count = execute(SCI_GETLINECOUNT); + const int current_line = getCurrentLineNumber(); + if(current_line == line_count - 1) + { + // Special handling if caret is at last line. + appandGenericText(newline.c_str()); + } + else + { + const int eol_length = eol_mode == SC_EOL_CRLF ? 2 : 1; + const long position = eol_length + execute(SCI_GETLINEENDPOSITION, current_line); + insertGenericTextFrom(position, newline.c_str()); + } + execute(SCI_SETEMPTYSELECTION, execute(SCI_POSITIONFROMLINE, current_line + 1)); +} + diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 91472ed8a..b886e46a5 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -272,6 +272,9 @@ public: void getLine(int lineNumber, TCHAR * line, int lineBufferLen); void addText(int length, const char *buf); + void insertNewLineAboveCurrentLine(); + void insertNewLineBelowCurrentLine(); + void saveCurrentPos(); void restoreCurrentPos(); void saveCurrentFold(); diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 0f4cd3fb8..871a7147d 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -76,6 +76,8 @@ #define IDM_EDIT_LOWERCASE (IDM_EDIT + 17) #define IDM_EDIT_REMOVEEMPTYLINES (IDM_EDIT + 55) #define IDM_EDIT_REMOVEEMPTYLINESWITHBLANK (IDM_EDIT + 56) + #define IDM_EDIT_BLANKLINEABOVECURRENT (IDM_EDIT + 57) + #define IDM_EDIT_BLANKLINEBELOWCURRENT (IDM_EDIT + 58) // Menu macro #define IDM_MACRO_STARTRECORDINGMACRO (IDM_EDIT + 18)