Skip to content

Commit

Permalink
fix multiline textbox Enter key bug
Browse files Browse the repository at this point in the history
now hitting Enter in a multiline textbox adds a newline
  • Loading branch information
molsonkiko committed Feb 9, 2024
1 parent 548e21f commit 9e2ef71
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Closing HTML/XML tags works inconsistently in Notepad++ v7.3.3.
- Avoid plugin crash when too-large int values are entered in the selection-remembering form.
- Holding down `Enter` in a multiline textbox does not add multiple new lines; it only adds one newline on keyup.

## [0.0.3] - (UNRELEASED) YYYY-MM-DD

### Fixed

1. Greatly reduced unnecessary calls to `NPPM_GETCURRENTLANGTYPE` in `DoInsertHtmlCloseTag` by caching the lexer language whenever the lexer language changes or a buffer is opened.
2. Bug where hitting `Enter` in a multiline textbox would not add a new line.

## [0.0.2] - 2024-02-06

Expand Down
25 changes: 25 additions & 0 deletions NppCSharpPluginPack/Forms/NppFormHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static void GenericKeyUpHandler(Form form, object sender, KeyEventArgs e,
// Enter has the same effect as clicking a selected button
btn.PerformClick();
}
else
PressEnterInTextBoxHandler(sender, isModal);
}
// Escape ->
// * if this.IsModal (meaning this is a pop-up dialog), close this.
Expand Down Expand Up @@ -92,6 +94,29 @@ public static void GenericTabNavigationHandler(Form form, object sender, KeyEven
e.Handled = true;
}

/// <summary>
/// NPPM_MODELESSDIALOG consumes the KeyDown and KeyPress events for the Enter key,<br></br>
/// so our KeyUp handler needs to simulate pressing enter to add a new line in a multiline text box.<br></br>
/// Note that this does not fully repair the functionality of the Enter key in a multiline text box,
/// because only one newline can be created for a single keypress of Enter, no matter how long the key is held down.
/// </summary>
/// <param name="sender">the text box that sent the message</param>
/// <param name="isModal">if true, this blocks the parent application until closed. THIS IS ONLY TRUE OF POP-UP DIALOGS</param>
public static void PressEnterInTextBoxHandler(object sender, bool isModal)
{

if (!isModal && sender is TextBox tb && tb.Multiline)
{
int selstart = tb.SelectionStart;
tb.SelectedText = "";
string text = tb.Text;
tb.Text = text.Substring(0, selstart) + "\r\n" + text.Substring(selstart);
tb.SelectionStart = selstart + 2; // after the inserted newline
tb.SelectionLength = 0;
tb.ScrollToCaret();
}
}

/// <summary>
/// CALL THIS IN YOUR Dispose(bool disposing) METHOD, INSIDE OF THE ".Designer.cs" FILE<br></br>
/// When this form is initialized, *if it is a modeless dialog* (i.e., !isModal; the form does not block the parent application until closed)<br></br>
Expand Down
4 changes: 2 additions & 2 deletions NppCSharpPluginPack/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.0.2.1")]
[assembly: AssemblyFileVersion("0.0.2.1")]
[assembly: AssemblyVersion("0.0.2.2")]
[assembly: AssemblyFileVersion("0.0.2.2")]

0 comments on commit 9e2ef71

Please sign in to comment.